diff --git a/common/src/main/java/dev/dubhe/chinesefestivals/client/model/LoongBoatModel.java b/common/src/main/java/dev/dubhe/chinesefestivals/client/model/LoongBoatModel.java index ff708a8..8587c6c 100644 --- a/common/src/main/java/dev/dubhe/chinesefestivals/client/model/LoongBoatModel.java +++ b/common/src/main/java/dev/dubhe/chinesefestivals/client/model/LoongBoatModel.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.model.ListModel; +import net.minecraft.client.model.WaterPatchModel; import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.model.geom.PartPose; @@ -17,7 +18,7 @@ import net.minecraft.world.entity.vehicle.Boat; import org.jetbrains.annotations.NotNull; -public class LoongBoatModel extends ListModel { +public class LoongBoatModel extends ListModel implements WaterPatchModel { public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation("chinesefestivals", "loong_boat"), "main"); private static final String BOTTOM = "bottom"; private static final String BACK = "back"; @@ -29,13 +30,13 @@ public class LoongBoatModel extends ListModel { private final ModelPart left; private final ModelPart right; private final ModelPart bottom; - private final ModelPart bottom_no_water; - private final ModelPart paddle_left; - private final ModelPart paddle_left2; - private final ModelPart paddle_left3; - private final ModelPart paddle_right; - private final ModelPart paddle_right2; - private final ModelPart paddle_right3; + private final ModelPart waterPatch; + private final ModelPart paddleLeft; + private final ModelPart paddleLeft2; + private final ModelPart paddleLeft3; + private final ModelPart paddleRight; + private final ModelPart paddleRight2; + private final ModelPart paddleRight3; private final ImmutableList parts; public LoongBoatModel(ModelPart root) { @@ -44,19 +45,19 @@ public LoongBoatModel(ModelPart root) { this.left = root.getChild("left"); this.right = root.getChild("right"); this.bottom = root.getChild("bottom"); - this.bottom_no_water = root.getChild("bottom_no_water"); - this.paddle_left = root.getChild("paddle_left"); - this.paddle_left2 = root.getChild("paddle_left2"); - this.paddle_left3 = root.getChild("paddle_left3"); - this.paddle_right = root.getChild("paddle_right"); - this.paddle_right2 = root.getChild("paddle_right2"); - this.paddle_right3 = root.getChild("paddle_right3"); + this.waterPatch = root.getChild("bottom_no_water"); + this.paddleLeft = root.getChild("paddle_left"); + this.paddleLeft2 = root.getChild("paddle_left2"); + this.paddleLeft3 = root.getChild("paddle_left3"); + this.paddleRight = root.getChild("paddle_right"); + this.paddleRight2 = root.getChild("paddle_right2"); + this.paddleRight3 = root.getChild("paddle_right3"); this.parts = this.createPartsBuilder(root).build(); } protected ImmutableList.Builder createPartsBuilder(ModelPart modelPart) { ImmutableList.Builder builder = new ImmutableList.Builder(); - builder.add(modelPart.getChild(BOTTOM), modelPart.getChild(BACK), modelPart.getChild(FRONT), modelPart.getChild(RIGHT), modelPart.getChild(LEFT), this.paddle_left, this.paddle_left2, this.paddle_left3, this.paddle_right, this.paddle_right2, this.paddle_right3); + builder.add(modelPart.getChild(BOTTOM), modelPart.getChild(BACK), modelPart.getChild(FRONT), modelPart.getChild(RIGHT), modelPart.getChild(LEFT), this.paddleLeft, this.paddleLeft2, this.paddleLeft3, this.paddleRight, this.paddleRight2, this.paddleRight3); return builder; } @@ -147,12 +148,12 @@ protected ImmutableList.Builder createPartsBuilder(ModelPart modelPar @Override public void setupAnim(Boat boat, float f, float g, float h, float i, float j) { - LoongBoatModel.animatePaddle(boat, 0, this.paddle_left, f); - LoongBoatModel.animatePaddle(boat, 0, this.paddle_left2, f); - LoongBoatModel.animatePaddle(boat, 0, this.paddle_left3, f); - LoongBoatModel.animatePaddle(boat, 1, this.paddle_right, f); - LoongBoatModel.animatePaddle(boat, 1, this.paddle_right2, f); - LoongBoatModel.animatePaddle(boat, 1, this.paddle_right3, f); + LoongBoatModel.animatePaddle(boat, 0, this.paddleLeft, f); + LoongBoatModel.animatePaddle(boat, 0, this.paddleLeft2, f); + LoongBoatModel.animatePaddle(boat, 0, this.paddleLeft3, f); + LoongBoatModel.animatePaddle(boat, 1, this.paddleRight, f); + LoongBoatModel.animatePaddle(boat, 1, this.paddleRight2, f); + LoongBoatModel.animatePaddle(boat, 1, this.paddleRight3, f); } private static void animatePaddle(@NotNull Boat boat, int i, @NotNull ModelPart modelPart, float f) { @@ -173,17 +174,22 @@ public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, i left.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); right.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); bottom.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); - bottom_no_water.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); - paddle_left.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); - paddle_left2.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); - paddle_left3.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); - paddle_right.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); - paddle_right2.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); - paddle_right3.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); + waterPatch.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); + paddleLeft.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); + paddleLeft2.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); + paddleLeft3.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); + paddleRight.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); + paddleRight2.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); + paddleRight3.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); } @Override public @NotNull Iterable parts() { return this.parts; } + + @Override + public @NotNull ModelPart waterPatch() { + return this.waterPatch; + } } diff --git a/common/src/main/java/dev/dubhe/chinesefestivals/mixins/BoatRendererMixin.java b/common/src/main/java/dev/dubhe/chinesefestivals/mixins/BoatRendererMixin.java index 8a1ec55..5cbfd41 100644 --- a/common/src/main/java/dev/dubhe/chinesefestivals/mixins/BoatRendererMixin.java +++ b/common/src/main/java/dev/dubhe/chinesefestivals/mixins/BoatRendererMixin.java @@ -12,6 +12,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.BoatRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.vehicle.Boat; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; @@ -21,12 +22,16 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Map; + @Mixin(BoatRenderer.class) public class BoatRendererMixin { @Unique private static final String DEFAULT_LAYER = "main"; @Unique private static ListModel chineseFestivals$model = null; + @Unique + private boolean chineseFestivals$hasChest = false; @Inject( method = "", @@ -36,40 +41,28 @@ private void init(EntityRendererProvider.@NotNull Context context, boolean bl, C ModelLayerLocation modelLayerLocation = LoongBoatModel.LAYER_LOCATION; ModelPart modelPart = context.bakeLayer(modelLayerLocation); BoatRendererMixin.chineseFestivals$model = new LoongBoatModel(modelPart); + this.chineseFestivals$hasChest = bl; } @SuppressWarnings("unchecked") @Redirect( method = "render(Lnet/minecraft/world/entity/vehicle/Boat;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", - at = @At(value = "INVOKE", target = "Lcom/mojang/datafixers/util/Pair;getSecond()Ljava/lang/Object;"), - remap = false - ) - private S getSecond(Pair instance) { - if (Features.LOONG_BOAT.get().isNow()) { - return (S) BoatRendererMixin.chineseFestivals$model; - } - return instance.getSecond(); - } - - @SuppressWarnings("unchecked") - @Redirect( - method = "render(Lnet/minecraft/world/entity/vehicle/Boat;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", - at = @At(value = "INVOKE", target = "Lcom/mojang/datafixers/util/Pair;getFirst()Ljava/lang/Object;"), + at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;"), remap = false ) - private S getFirst(Pair instance) { - if (Features.LOONG_BOAT.get().isNow()) { - return (S) ChineseFestivals.of("textures/entity/loong_boat.png"); + private V get(Map instance, K key) { + if (!this.chineseFestivals$hasChest && key instanceof Boat.Type type && type != Boat.Type.BAMBOO && Features.LOONG_BOAT.get().isNow()) { + return (V) new Pair<>(ChineseFestivals.of("textures/entity/loong_boat.png"), BoatRendererMixin.chineseFestivals$model); } - return instance.getFirst(); + return instance.get(key); } @Inject( method = "render(Lnet/minecraft/world/entity/vehicle/Boat;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;scale(FFF)V") ) - private void render(Boat boat, float f, float g, @NotNull PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) { - if (Features.LOONG_BOAT.get().isNow()) { + private void render(@NotNull Boat boat, float f, float g, @NotNull PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) { + if (!this.chineseFestivals$hasChest && boat.getVariant() != Boat.Type.BAMBOO && Features.LOONG_BOAT.get().isNow()) { poseStack.translate(0.0, 1.0, 0.0); poseStack.rotateAround(Axis.YP.rotationDegrees(90), 0.0f, 0.0f, 0.0f); }