mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-22 23:58:02 -05:00
Add fabric model predicate provider registry (#601)
* Add fabric model predicate provider registry Signed-off-by: liach <liach@users.noreply.github.com> * Fix jd with new mappings Signed-off-by: liach <liach@users.noreply.github.com> * Bump module version Signed-off-by: liach <liach@users.noreply.github.com> * Remove redundant line * Move inner class accessor to outer class Co-authored-by: liach <liach@users.noreply.github.com>
This commit is contained in:
parent
d83d36ad00
commit
eae12eb815
6 changed files with 135 additions and 5 deletions
|
@ -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.
|
||||||
|
*
|
||||||
|
* <p>A registered model predicate providers for an item can be retrieved through
|
||||||
|
* {@link net.minecraft.client.item.ModelPredicateProviderRegistry#get(Item, Identifier)}.</p>
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,10 @@
|
||||||
"MaterialBuilderAccessor",
|
"MaterialBuilderAccessor",
|
||||||
"MixinBlock"
|
"MixinBlock"
|
||||||
],
|
],
|
||||||
|
"client": [
|
||||||
|
"ModelPredicateProviderRegistryAccessor",
|
||||||
|
"ModelPredicateProviderRegistrySpecificAccessor"
|
||||||
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,10 @@ import java.util.Random;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.client.render.VertexConsumer;
|
||||||
import net.minecraft.client.render.block.BlockModelRenderer;
|
import net.minecraft.client.render.block.BlockModelRenderer;
|
||||||
import net.minecraft.client.render.model.BakedModel;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.BlockRenderView;
|
import net.minecraft.world.BlockRenderView;
|
||||||
|
@ -62,7 +64,7 @@ public interface FabricBakedModel {
|
||||||
* <p>Also called to render block models outside of chunk rebuild or block entity rendering.
|
* <p>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.
|
* 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
|
* 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
|
* that occur outside of chunk rebuilds to allow for features added by mods, unless
|
||||||
* {@link #isVanillaAdapter()} returns true.
|
* {@link #isVanillaAdapter()} returns true.
|
||||||
*
|
*
|
||||||
|
@ -111,14 +113,14 @@ public interface FabricBakedModel {
|
||||||
* method thread-safe.
|
* method thread-safe.
|
||||||
*
|
*
|
||||||
* <p>Implementing this method does NOT mitigate the need to implement a functional
|
* <p>Implementing this method does NOT mitigate the need to implement a functional
|
||||||
* {@link BakedModel#getItemPropertyOverrides()} method, because this method will be called
|
* {@link BakedModel#getOverrides()} method, because this method will be called
|
||||||
* on the <em>result</em> of {@link BakedModel#getItemPropertyOverrides}. However, that
|
* on the <em>result</em> of {@link BakedModel#getOverrides}. However, that
|
||||||
* method can simply return the base model because the output from this method will
|
* method can simply return the base model because the output from this method will
|
||||||
* be used for rendering.
|
* be used for rendering.
|
||||||
*
|
*
|
||||||
* <p>Renderer implementations should also use this method to obtain the quads used
|
* <p>Renderer implementations should also use this method to obtain the quads used
|
||||||
* for item enchantment glint rendering. This means models can put geometric variation
|
* 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.
|
* as vanilla baked models.
|
||||||
*/
|
*/
|
||||||
void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context);
|
void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context);
|
||||||
|
|
|
@ -24,7 +24,7 @@ import net.minecraft.util.Identifier;
|
||||||
* Implement this interface on a Sprite to declare additional dependencies
|
* Implement this interface on a Sprite to declare additional dependencies
|
||||||
* that should be processed prior to this sprite.
|
* that should be processed prior to this sprite.
|
||||||
*
|
*
|
||||||
* <p>Best used in conjunction with {@link CustomSpriteLoader}.
|
* <p>Best used in conjunction with {@link net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback}.
|
||||||
*/
|
*/
|
||||||
public interface DependentSprite {
|
public interface DependentSprite {
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue