-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathShulkerBoxBlockEntityRendererMixin.java
More file actions
99 lines (91 loc) · 4.64 KB
/
ShulkerBoxBlockEntityRendererMixin.java
File metadata and controls
99 lines (91 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package de.rubixdev.enchantedshulkers.mixin.client;
import static de.rubixdev.enchantedshulkers.ClientMod.CLOSED_COLORED_SHULKER_BOXES_TEXTURE_IDS;
import static de.rubixdev.enchantedshulkers.ClientMod.CLOSED_SHULKER_TEXTURE_ID;
import de.rubixdev.enchantedshulkers.ClientMod;
import de.rubixdev.enchantedshulkers.Utils;
import java.util.function.Function;
import net.minecraft.block.entity.ShulkerBoxBlockEntity;
import net.minecraft.client.model.*;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.ShulkerBoxBlockEntityRenderer;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ShulkerBoxBlockEntityRenderer.class)
public class ShulkerBoxBlockEntityRendererMixin {
@Redirect(
method =
"render(Lnet/minecraft/block/entity/ShulkerBoxBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V",
at =
@At(
value = "INVOKE",
target =
"Lnet/minecraft/client/util/SpriteIdentifier;getVertexConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Ljava/util/function/Function;)Lnet/minecraft/client/render/VertexConsumer;"))
private VertexConsumer getVertexConsumer(
SpriteIdentifier instance,
VertexConsumerProvider vertexConsumers,
Function<Identifier, RenderLayer> layerFactory,
ShulkerBoxBlockEntity shulkerBoxBlockEntity) {
if (!ClientMod.glintWhenPlaced() || !Utils.shouldGlint(shulkerBoxBlockEntity))
return instance.getVertexConsumer(vertexConsumers, layerFactory);
return instance.getSprite()
.getTextureSpecificVertexConsumer(ItemRenderer.getDirectItemGlintConsumer(
vertexConsumers, instance.getRenderLayer(layerFactory), false, true));
}
@Unique
private static final ModelPart CLOSED_BOX;
static {
ModelData modelData = new ModelData();
ModelPartData modelPartData = modelData.getRoot();
modelPartData.addChild(
"box",
ModelPartBuilder.create().uv(0, 0).cuboid(-8.0f, 8.0f, -8.0f, 16.0f, 16.0f, 16.0f),
ModelTransform.NONE);
CLOSED_BOX = TexturedModelData.of(modelData, 64, 32).createModel();
}
@Inject(
method =
"render(Lnet/minecraft/block/entity/ShulkerBoxBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V",
at =
@At(
value = "INVOKE",
target =
"Lnet/minecraft/client/render/entity/model/ShulkerEntityModel;getLid()Lnet/minecraft/client/model/ModelPart;"),
cancellable = true)
private void renderGlint(
ShulkerBoxBlockEntity shulkerBoxBlockEntity,
float f,
MatrixStack matrixStack,
VertexConsumerProvider vertexConsumerProvider,
int i,
int j,
CallbackInfo ci) {
if (!ClientMod.customModels()
|| !Utils.shouldGlint(shulkerBoxBlockEntity)
|| shulkerBoxBlockEntity.getAnimationProgress(f) > 0.01f) return;
DyeColor dyeColor;
SpriteIdentifier spriteIdentifier = (dyeColor = shulkerBoxBlockEntity.getColor()) == null
? CLOSED_SHULKER_TEXTURE_ID
: CLOSED_COLORED_SHULKER_BOXES_TEXTURE_IDS.get(dyeColor.getId());
VertexConsumer vertexConsumer = spriteIdentifier
.getSprite()
.getTextureSpecificVertexConsumer(ItemRenderer.getDirectItemGlintConsumer(
vertexConsumerProvider,
spriteIdentifier.getRenderLayer(RenderLayer::getEntityCutout),
false,
true));
CLOSED_BOX.render(matrixStack, vertexConsumer, i, j, 1.0f, 1.0f, 1.0f, 1.0f);
matrixStack.pop();
ci.cancel();
}
}