mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-14 19:25:23 -05:00
parent
f1e4495b13
commit
0b401b6a39
3 changed files with 16 additions and 6 deletions
|
@ -16,7 +16,7 @@
|
|||
|
||||
package net.fabricmc.fabric.api.client.rendering.v1;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
|
@ -75,7 +75,13 @@ public interface BuiltinItemRendererRegistry {
|
|||
* @throws IllegalArgumentException if the item already has a registered renderer
|
||||
* @throws NullPointerException if either the item or the renderer is null
|
||||
*/
|
||||
void register(@NotNull ItemConvertible item, @NotNull DynamicItemRenderer renderer);
|
||||
void register(ItemConvertible item, DynamicItemRenderer renderer);
|
||||
|
||||
/**
|
||||
* Returns the renderer for the item, or {@code null} if the item has no renderer.
|
||||
*/
|
||||
@Nullable
|
||||
DynamicItemRenderer get(ItemConvertible item);
|
||||
|
||||
/**
|
||||
* Dynamic item renderers render items with custom code.
|
||||
|
|
|
@ -58,8 +58,11 @@ public final class BuiltinItemRendererRegistryImpl implements BuiltinItemRendere
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public static DynamicItemRenderer getRenderer(Item item) {
|
||||
return RENDERERS.get(item);
|
||||
public DynamicItemRenderer get(ItemConvertible item) {
|
||||
Objects.requireNonNull(item.asItem(), "item is null");
|
||||
|
||||
return RENDERERS.get(item.asItem());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package net.fabricmc.fabric.mixin.client.rendering;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
@ -28,13 +29,13 @@ import net.minecraft.client.util.math.MatrixStack;
|
|||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
|
||||
import net.fabricmc.fabric.impl.client.rendering.BuiltinItemRendererRegistryImpl;
|
||||
|
||||
@Mixin(BuiltinModelItemRenderer.class)
|
||||
abstract class BuiltinModelItemRendererMixin {
|
||||
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
|
||||
private void fabric_onRender(ItemStack stack, ModelTransformation.Mode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, CallbackInfo info) {
|
||||
/* @Nullable */ BuiltinItemRendererRegistry.DynamicItemRenderer renderer = BuiltinItemRendererRegistryImpl.getRenderer(stack.getItem());
|
||||
@Nullable
|
||||
BuiltinItemRendererRegistry.DynamicItemRenderer renderer = BuiltinItemRendererRegistry.INSTANCE.get(stack.getItem());
|
||||
|
||||
if (renderer != null) {
|
||||
renderer.render(stack, mode, matrices, vertexConsumers, light, overlay);
|
||||
|
|
Loading…
Reference in a new issue