|
1 | 1 | package de.dafuqs.spectrum.blocks.chests;
|
2 | 2 |
|
3 | 3 | import de.dafuqs.spectrum.*;
|
| 4 | +import de.dafuqs.spectrum.registries.SpectrumBlocks; |
4 | 5 | import net.fabricmc.api.*;
|
| 6 | +import net.minecraft.block.BlockState; |
| 7 | +import net.minecraft.block.ChestBlock; |
5 | 8 | import net.minecraft.client.model.*;
|
6 | 9 | import net.minecraft.client.render.*;
|
7 | 10 | import net.minecraft.client.render.block.entity.*;
|
8 | 11 | import net.minecraft.client.util.*;
|
9 | 12 | import net.minecraft.client.util.math.*;
|
10 | 13 | import net.minecraft.screen.*;
|
| 14 | +import net.minecraft.util.math.Direction; |
| 15 | +import net.minecraft.util.math.MathHelper; |
| 16 | +import net.minecraft.util.math.RotationAxis; |
11 | 17 | import org.jetbrains.annotations.*;
|
12 | 18 |
|
13 | 19 | @Environment(EnvType.CLIENT)
|
14 | 20 | public class BlackHoleChestBlockEntityRenderer implements BlockEntityRenderer<BlackHoleChestBlockEntity> {
|
15 | 21 |
|
16 |
| - private static final SpriteIdentifier spriteIdentifier = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, SpectrumCommon.locate("block/black_block")); |
| 22 | + private static final SpriteIdentifier spriteIdentifier = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, SpectrumCommon.locate("block/black_hole_chest")); |
17 | 23 | private final ModelPart root;
|
| 24 | + private final ModelPart shell; |
| 25 | + private final ModelPart cap; |
| 26 | + private final ModelPart storage; |
| 27 | + private final ModelPart orb; |
18 | 28 |
|
19 | 29 | public BlackHoleChestBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {
|
20 | 30 | TexturedModelData texturedModelData = getTexturedModelData();
|
21 |
| - root = texturedModelData.createModel(); |
| 31 | + this.root = texturedModelData.createModel(); |
| 32 | + this.shell = root.getChild("shell"); |
| 33 | + this.cap = root.getChild("cap"); |
| 34 | + this.storage = root.getChild("storage"); |
| 35 | + this.orb = root.getChild("orb"); |
22 | 36 | }
|
23 | 37 |
|
24 | 38 | public static @NotNull TexturedModelData getTexturedModelData() {
|
25 | 39 | ModelData modelData = new ModelData();
|
26 | 40 | ModelPartData modelPartData = modelData.getRoot();
|
27 |
| - modelPartData.addChild("lid", ModelPartBuilder.create().uv(1, 1).cuboid(5.0F, 7.0F, 5.0F, 6.0F, 3.0F, 6.0F), ModelTransform.pivot(0.0F, 0.0F, 0.0F)); |
28 |
| - modelPartData.addChild("lid2", ModelPartBuilder.create().uv(1, 1).cuboid(7.0F, 4.0F, 7.0F, 2.0F, 3.0F, 2.0F), ModelTransform.pivot(0.0F, 0.0F, 0.0F)); |
29 |
| - return TexturedModelData.of(modelData, 32, 32); |
| 41 | + ModelPartData shell = modelPartData.addChild("shell", ModelPartBuilder.create().uv(0, 0).cuboid(-7.0F, -9.0F, -7.0F, 14.0F, 9.0F, 14.0F, new Dilation(0.0F)) |
| 42 | + .uv(0, 39).cuboid(-5.0F, -9.0F, -5.0F, 10.0F, 9.0F, 10.0F, new Dilation(0.0F)), ModelTransform.pivot(0.0F, 24.0F, 0.0F)); |
| 43 | + |
| 44 | + ModelPartData cap = modelPartData.addChild("cap", ModelPartBuilder.create().uv(40, 39).cuboid(-5.0F, -6.0F, -5.0F, 10.0F, 4.0F, 10.0F, new Dilation(0.0F)) |
| 45 | + .uv(82, 2).cuboid(-4.0F, -5.0F, -4.0F, 8.0F, 3.0F, 8.0F, new Dilation(0.0F)), ModelTransform.pivot(0.0F, 24.0F, 0.0F)); |
| 46 | + |
| 47 | + ModelPartData storage = modelPartData.addChild("storage", ModelPartBuilder.create().uv(42, 0).cuboid(-5.0F, -2.0F, -5.0F, 10.0F, 2.0F, 10.0F, new Dilation(0.0F)) |
| 48 | + .uv(56, 13).cuboid(-4.0F, -2.0F, -4.0F, 8.0F, 2.0F, 8.0F, new Dilation(0.0F)), ModelTransform.pivot(0.0F, 24.0F, 0.0F)); |
| 49 | + |
| 50 | + ModelPartData orb = modelPartData.addChild("orb", ModelPartBuilder.create().uv(0, 0).cuboid(-1.0F, -1.0F, -1.0F, 2.0F, 2.0F, 2.0F, new Dilation(0.0F)) |
| 51 | + .uv(30, 39).cuboid(-2.5F, -2.5F, -2.5F, 5.0F, 5.0F, 5.0F, new Dilation(0.0F)), ModelTransform.pivot(0.0F, 15.4F, 0.0F)); |
| 52 | + return TexturedModelData.of(modelData, 128, 128); |
30 | 53 | }
|
31 | 54 |
|
32 | 55 | @Override
|
33 |
| - public void render(BlackHoleChestBlockEntity entity, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumers, int light, int overlay) { |
| 56 | + public void render(BlackHoleChestBlockEntity chest, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumers, int light, int overlay) { |
34 | 57 | matrixStack.push();
|
35 |
| - matrixStack.translate(0.5D, 0.5D, 0.5D); |
36 |
| - matrixStack.translate(-0.5D, -0.5D, -0.5D); |
37 | 58 |
|
38 |
| - float openFactor = entity.getAnimationProgress(tickDelta); |
39 |
| - openFactor = 1.0F - openFactor; |
40 |
| - openFactor = 1.0F - openFactor * openFactor * openFactor; |
| 59 | + boolean bl = chest.getWorld() != null; |
| 60 | + BlockState blockState = bl ? chest.getCachedState() : SpectrumBlocks.BLACK_HOLE_CHEST.getDefaultState().with(ChestBlock.FACING, Direction.SOUTH); |
| 61 | + float f = (blockState.get(ChestBlock.FACING)).asRotation(); |
| 62 | + matrixStack.translate(0.5D, 1.5D, 0.5D); |
| 63 | + matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-f)); |
| 64 | + matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180)); |
| 65 | + var time = chest.getRenderTime(); |
| 66 | + |
| 67 | + final double orbTransform = Math.sin((time + tickDelta) / 9F); |
| 68 | + final float potentialYaw = (time + tickDelta) / 6F; |
| 69 | + switch (chest.getState()) { |
| 70 | + case OPEN_ACTIVE -> { |
| 71 | + chest.storageTarget = 9; |
| 72 | + chest.capTarget = 12; |
| 73 | + chest.orbTarget = (float) (15 + orbTransform); |
| 74 | + chest.yawTarget = potentialYaw; |
| 75 | + } |
| 76 | + case OPEN_INACTIVE -> { |
| 77 | + chest.storageTarget = 9; |
| 78 | + chest.capTarget = 12; |
| 79 | + chest.orbTarget = chest.capTarget; |
| 80 | + } |
| 81 | + case CLOSED_ACTIVE -> { |
| 82 | + chest.capTarget = 0; |
| 83 | + chest.storageTarget = 0; |
| 84 | + chest.orbTarget = (float) (12.5 + orbTransform * 2.5F); |
| 85 | + chest.yawTarget = potentialYaw; |
| 86 | + |
| 87 | + } |
| 88 | + case CLOSED_INACTIVE -> { |
| 89 | + chest.capTarget = 0; |
| 90 | + chest.storageTarget = chest.capTarget; |
| 91 | + chest.orbTarget = chest.capTarget; |
| 92 | + } |
| 93 | + case FULL -> { |
| 94 | + chest.capTarget = 9; |
| 95 | + chest.storageTarget = chest.capTarget; |
| 96 | + chest.orbTarget = chest.capTarget; |
| 97 | + } |
| 98 | + } |
41 | 99 |
|
42 |
| - root.pivotY = openFactor * 5; |
43 |
| - |
44 |
| - VertexConsumer vertexConsumer = spriteIdentifier.getVertexConsumer(vertexConsumers, RenderLayer::getEntityCutout); |
| 100 | + var interp = MathHelper.clamp((chest.interpTicks + tickDelta) / chest.interpLength, 0F, 1F); |
| 101 | + chest.capPos = MathHelper.lerp(interp, chest.lastCapTarget, chest.capTarget); |
| 102 | + chest.storagePos = MathHelper.lerp(interp, chest.lastStorageTarget, chest.storageTarget); |
| 103 | + chest.orbPos = MathHelper.lerp(interp, chest.lastOrbTarget, chest.orbTarget); |
| 104 | + chest.orbYaw = MathHelper.lerp(interp, chest.lastYawTarget, chest.yawTarget); |
| 105 | + |
| 106 | + cap.pivotY = 24 - chest.capPos; |
| 107 | + storage.pivotY = 24 - chest.storagePos; |
| 108 | + orb.pivotY = 15.4F - chest.orbPos; |
| 109 | + orb.yaw = chest.yawTarget; |
| 110 | + |
| 111 | + |
| 112 | + storage.hidden = storage.pivotY > 23.99F; |
| 113 | + VertexConsumer vertexConsumer = spriteIdentifier.getVertexConsumer(vertexConsumers, RenderLayer::getEntityTranslucent); |
45 | 114 | root.render(matrixStack, vertexConsumer, light, overlay);
|
46 |
| - |
| 115 | + |
47 | 116 | matrixStack.pop();
|
48 | 117 | }
|
49 | 118 |
|
|
0 commit comments