From eae12eb8159bf8e492d82a5e752fe96967026d4e Mon Sep 17 00:00:00 2001 From: liach <7806504+liach@users.noreply.github.com> Date: Thu, 7 May 2020 16:10:07 -0500 Subject: [PATCH] Add fabric model predicate provider registry (#601) * Add fabric model predicate provider registry Signed-off-by: liach * Fix jd with new mappings Signed-off-by: liach * Bump module version Signed-off-by: liach * Remove redundant line * Move inner class accessor to outer class Co-authored-by: liach --- .../FabricModelPredicateProviderRegistry.java | 58 +++++++++++++++++++ ...odelPredicateProviderRegistryAccessor.java | 32 ++++++++++ ...icateProviderRegistrySpecificAccessor.java | 34 +++++++++++ .../fabric-object-builder-v1.mixins.json | 4 ++ .../renderer/v1/model/FabricBakedModel.java | 10 ++-- .../api/client/texture/DependentSprite.java | 2 +- 6 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/client/model/FabricModelPredicateProviderRegistry.java create mode 100644 fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/ModelPredicateProviderRegistryAccessor.java create mode 100644 fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/ModelPredicateProviderRegistrySpecificAccessor.java diff --git a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/client/model/FabricModelPredicateProviderRegistry.java b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/client/model/FabricModelPredicateProviderRegistry.java new file mode 100644 index 000000000..95a0ed276 --- /dev/null +++ b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/client/model/FabricModelPredicateProviderRegistry.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.api.object.builder.v1.client.model; + +import net.minecraft.client.item.ModelPredicateProvider; +import net.minecraft.item.Item; +import net.minecraft.util.Identifier; + +import net.fabricmc.fabric.mixin.object.builder.ModelPredicateProviderRegistryAccessor; +import net.fabricmc.fabric.mixin.object.builder.ModelPredicateProviderRegistrySpecificAccessor; + +/** + * Allows registering model predicate providers for item models. + * + *

A registered model predicate providers for an item can be retrieved through + * {@link net.minecraft.client.item.ModelPredicateProviderRegistry#get(Item, Identifier)}.

+ * + * @see net.minecraft.client.item.ModelPredicateProviderRegistry + * @deprecated Experimental feature, may be removed or changed without further notice. + * Vanilla snapshot feature, subject to vanilla change. + */ +@Deprecated +public final class FabricModelPredicateProviderRegistry { + /** + * Registers a model predicate provider that is applicable for any item. + * + * @param id the identifier of the provider + * @param provider the provider + */ + public static void register(Identifier id, ModelPredicateProvider provider) { + ModelPredicateProviderRegistryAccessor.callRegister(id, provider); + } + + /** + * Registers a model predicate provider to a specific item. + * + * @param item the item the provider is associated to + * @param id the identifier of the provider + * @param provider the provider + */ + public static void register(Item item, Identifier id, ModelPredicateProvider provider) { + ModelPredicateProviderRegistrySpecificAccessor.callRegister(item, id, provider); + } +} diff --git a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/ModelPredicateProviderRegistryAccessor.java b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/ModelPredicateProviderRegistryAccessor.java new file mode 100644 index 000000000..d33a122eb --- /dev/null +++ b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/ModelPredicateProviderRegistryAccessor.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.object.builder; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import net.minecraft.client.item.ModelPredicateProvider; +import net.minecraft.client.item.ModelPredicateProviderRegistry; +import net.minecraft.util.Identifier; + +@Mixin(ModelPredicateProviderRegistry.class) +public interface ModelPredicateProviderRegistryAccessor { + @Invoker + static ModelPredicateProvider callRegister(Identifier id, ModelPredicateProvider provider) { + throw new AssertionError("mixin dummy"); + } +} diff --git a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/ModelPredicateProviderRegistrySpecificAccessor.java b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/ModelPredicateProviderRegistrySpecificAccessor.java new file mode 100644 index 000000000..c5fad82e8 --- /dev/null +++ b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/ModelPredicateProviderRegistrySpecificAccessor.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.object.builder; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import net.minecraft.client.item.ModelPredicateProvider; +import net.minecraft.client.item.ModelPredicateProviderRegistry; +import net.minecraft.item.Item; +import net.minecraft.util.Identifier; + +// mixin doesn't care about descriptor, must put two "register" accessors in different places +@Mixin(ModelPredicateProviderRegistry.class) +public interface ModelPredicateProviderRegistrySpecificAccessor { + @Invoker + static void callRegister(Item item, Identifier id, ModelPredicateProvider provider) { + throw new AssertionError("mixin dummy"); + } +} diff --git a/fabric-object-builder-api-v1/src/main/resources/fabric-object-builder-v1.mixins.json b/fabric-object-builder-api-v1/src/main/resources/fabric-object-builder-v1.mixins.json index d7354dd9c..0378b7bdc 100644 --- a/fabric-object-builder-api-v1/src/main/resources/fabric-object-builder-v1.mixins.json +++ b/fabric-object-builder-api-v1/src/main/resources/fabric-object-builder-v1.mixins.json @@ -11,6 +11,10 @@ "MaterialBuilderAccessor", "MixinBlock" ], + "client": [ + "ModelPredicateProviderRegistryAccessor", + "ModelPredicateProviderRegistrySpecificAccessor" + ], "injectors": { "defaultRequire": 1 } diff --git a/fabric-renderer-api-v1/src/main/java/net/fabricmc/fabric/api/renderer/v1/model/FabricBakedModel.java b/fabric-renderer-api-v1/src/main/java/net/fabricmc/fabric/api/renderer/v1/model/FabricBakedModel.java index fee0bbf03..b6b00a692 100644 --- a/fabric-renderer-api-v1/src/main/java/net/fabricmc/fabric/api/renderer/v1/model/FabricBakedModel.java +++ b/fabric-renderer-api-v1/src/main/java/net/fabricmc/fabric/api/renderer/v1/model/FabricBakedModel.java @@ -20,8 +20,10 @@ import java.util.Random; import java.util.function.Supplier; import net.minecraft.block.BlockState; +import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.block.BlockModelRenderer; import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockRenderView; @@ -62,7 +64,7 @@ public interface FabricBakedModel { *

Also called to render block models outside of chunk rebuild or block entity rendering. * Typically this happens when the block is being rendered as an entity, not as a block placed in the world. * Currently this happens for falling blocks and blocks being pushed by a piston, but renderers - * should invoke this for all calls to {@link BlockModelRenderer#tesselate(ExtendedBlockView, BakedModel, BlockState, BlockPos, net.minecraft.client.render.BufferBuilder, boolean, Random, long)} + * should invoke this for all calls to {@link BlockModelRenderer#render(BlockRenderView, BakedModel, BlockState, BlockPos, MatrixStack, VertexConsumer, boolean, Random, long, int)} * that occur outside of chunk rebuilds to allow for features added by mods, unless * {@link #isVanillaAdapter()} returns true. * @@ -111,14 +113,14 @@ public interface FabricBakedModel { * method thread-safe. * *

Implementing this method does NOT mitigate the need to implement a functional - * {@link BakedModel#getItemPropertyOverrides()} method, because this method will be called - * on the result of {@link BakedModel#getItemPropertyOverrides}. However, that + * {@link BakedModel#getOverrides()} method, because this method will be called + * on the result of {@link BakedModel#getOverrides}. However, that * method can simply return the base model because the output from this method will * be used for rendering. * *

Renderer implementations should also use this method to obtain the quads used * for item enchantment glint rendering. This means models can put geometric variation - * logic here, instead of returning every possible shape from {@link BakedModel#getItemPropertyOverrides} + * logic here, instead of returning every possible shape from {@link BakedModel#getOverrides} * as vanilla baked models. */ void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context); diff --git a/fabric-textures-v0/src/main/java/net/fabricmc/fabric/api/client/texture/DependentSprite.java b/fabric-textures-v0/src/main/java/net/fabricmc/fabric/api/client/texture/DependentSprite.java index 3f1b7a7ab..6ad130c4e 100644 --- a/fabric-textures-v0/src/main/java/net/fabricmc/fabric/api/client/texture/DependentSprite.java +++ b/fabric-textures-v0/src/main/java/net/fabricmc/fabric/api/client/texture/DependentSprite.java @@ -24,7 +24,7 @@ import net.minecraft.util.Identifier; * Implement this interface on a Sprite to declare additional dependencies * that should be processed prior to this sprite. * - *

Best used in conjunction with {@link CustomSpriteLoader}. + *

Best used in conjunction with {@link net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback}. */ public interface DependentSprite { /**