Skip to content

Commit

Permalink
调整龙舟
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Jun 8, 2024
1 parent 93057cb commit 6ebae5e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +18,7 @@
import net.minecraft.world.entity.vehicle.Boat;
import org.jetbrains.annotations.NotNull;

public class LoongBoatModel extends ListModel<Boat> {
public class LoongBoatModel extends ListModel<Boat> 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";
Expand All @@ -29,13 +30,13 @@ public class LoongBoatModel extends ListModel<Boat> {
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<ModelPart> parts;

public LoongBoatModel(ModelPart root) {
Expand All @@ -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<ModelPart> createPartsBuilder(ModelPart modelPart) {
ImmutableList.Builder<ModelPart> builder = new ImmutableList.Builder<ModelPart>();
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;
}

Expand Down Expand Up @@ -147,12 +148,12 @@ protected ImmutableList.Builder<ModelPart> 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) {
Expand All @@ -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<ModelPart> parts() {
return this.parts;
}

@Override
public @NotNull ModelPart waterPatch() {
return this.waterPatch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Boat> chineseFestivals$model = null;
@Unique
private boolean chineseFestivals$hasChest = false;

@Inject(
method = "<init>",
Expand All @@ -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> S getSecond(Pair<?, S> 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> S getFirst(Pair<S, ?> instance) {
if (Features.LOONG_BOAT.get().isNow()) {
return (S) ChineseFestivals.of("textures/entity/loong_boat.png");
private <K, V> V get(Map<K, V> 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);
}
Expand Down

0 comments on commit 6ebae5e

Please sign in to comment.