Skip to content

Commit 8659179

Browse files
committed
Fixed a lot of the remaining issues
1 parent 9a2d915 commit 8659179

File tree

12 files changed

+93
-115
lines changed

12 files changed

+93
-115
lines changed

common/src/main/java/com/zigythebird/bendable_cuboids/impl/BendUtil.java

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.zigythebird.bendable_cuboids.impl;
22

33
import com.mojang.blaze3d.vertex.PoseStack;
4+
import com.mojang.math.Axis;
45
import com.zigythebird.bendable_cuboids.impl.compatibility.PlayerBendHelper;
56
import net.minecraft.client.model.HumanoidModel;
67
import net.minecraft.client.model.PlayerModel;
@@ -10,24 +11,22 @@
1011
import java.lang.Math;
1112

1213
public class BendUtil {
13-
public static BendApplier getBend(BendableCuboid cuboid, float bendAxis, float bendValue) {
14-
return getBend(cuboid.getBendDirection(), cuboid.getBendX(), cuboid.getBendY(), cuboid.getBendZ(),
15-
cuboid.basePlane, cuboid.otherPlane, false, cuboid.bendHeight(), bendAxis, bendValue);
14+
private static final Vector3f Z_AXIS = new Vector3f(0, 0, 1);
15+
16+
public static BendApplier getBend(BendableCuboid cuboid, float bendValue) {
17+
return getBend(cuboid.getBendX(), cuboid.getBendY(), cuboid.getBendZ(),
18+
cuboid.basePlane, cuboid.otherPlane, false, cuboid.bendHeight(), bendValue);
1619
}
1720

1821
/**
1922
* Applies the transformation to every position in posSupplier
20-
* @param bendAxis axis for the bend
2123
* @param bendValue bend value
2224
*/
23-
public static BendApplier getBend(Direction bendDirection, float bendX, float bendY, float bendZ, Plane basePlane, Plane otherPlane,
24-
boolean mirrorBend, float bendHeight, float bendAxis, float bendValue) {
25-
Vector3f axis = new Vector3f((float) Math.cos(bendAxis), 0, (float) Math.sin(bendAxis));
26-
Matrix3f matrix3f = new Matrix3f().set(bendDirection.getRotation());
27-
axis.mul(matrix3f);
25+
public static BendApplier getBend(float bendX, float bendY, float bendZ, Plane basePlane, Plane otherPlane,
26+
boolean mirrorBend, float bendHeight, float bendValue) {
2827
if (mirrorBend) bendValue *= -1;
2928
final float finalBend = bendValue;
30-
Matrix4f transformMatrix = applyBendToMatrix(new Matrix4f(), bendX, bendY, bendZ, bendAxis, bendValue);
29+
Matrix4f transformMatrix = applyBendToMatrix(new Matrix4f(), bendX, bendY, bendZ, bendValue);
3130

3231
float halfSize = bendHeight/2;
3332

@@ -55,29 +54,25 @@ else if (distFromBase + distFromOther <= bendHeight && distFromOther > v) {
5554
});
5655
}
5756

58-
public static BendApplier getBendLegacy(BendableCuboid cuboid, float bendAxis, float bendValue) {
57+
public static BendApplier getBendLegacy(BendableCuboid cuboid, float bendValue) {
5958
return getBendLegacy(cuboid.getBendDirection(), cuboid.getBendX(), cuboid.getBendY(), cuboid.getBendZ(),
60-
cuboid.basePlane, cuboid.otherPlane, cuboid.isBendInverted(), false, cuboid.bendHeight(), bendAxis, bendValue);
59+
cuboid.basePlane, cuboid.otherPlane, cuboid.isBendInverted(), false, cuboid.bendHeight(), bendValue);
6160
}
6261

6362
/**
6463
* Bends in the old pre-1.21.6 way which is more stretchy, but works in more situations, like for GeckoLib armor.
65-
* @param bendAxis axis for the bend
6664
* @param bendValue bend value
6765
*/
6866
public static BendApplier getBendLegacy(Direction bendDirection, float bendX, float bendY, float bendZ, Plane basePlane, Plane otherPlane,
69-
boolean isBendInverted, boolean mirrorBend, float bendHeight, float bendAxis, float bendValue) {
70-
Vector3f axis = new Vector3f((float) Math.cos(bendAxis), 0, (float) Math.sin(bendAxis));
71-
Matrix3f matrix3f = new Matrix3f().set(bendDirection.getRotation());
72-
axis.mul(matrix3f);
67+
boolean isBendInverted, boolean mirrorBend, float bendHeight, float bendValue) {
7368
if (mirrorBend) bendValue *= -1;
7469
final float finalBend = bendValue;
75-
Matrix4f transformMatrix = applyBendToMatrix(new Matrix4f(), bendX, bendY, bendZ, bendAxis, bendValue);
70+
Matrix4f transformMatrix = applyBendToMatrix(new Matrix4f(), bendX, bendY, bendZ, bendValue);
7671

7772
Vector3f directionUnit;
7873

7974
directionUnit = bendDirection.step();
80-
directionUnit.cross(axis);
75+
directionUnit.cross(Z_AXIS);
8176
//parallel to the bend's axis and to the cube's bend direction
8277
Plane bendPlane = new Plane(directionUnit, new Vector3f(bendX, bendY, bendZ));
8378
float halfSize = bendHeight/2;
@@ -112,21 +107,17 @@ else if (isInBendArea) {
112107
});
113108
}
114109

115-
public static Matrix4f applyBendToMatrix(Matrix4f transformMatrix, float bendX, float bendY, float bendZ, float bendAxis, float bendValue) {
116-
Vector3f axis = new Vector3f((float) Math.cos(bendAxis), 0, (float) Math.sin(bendAxis));
117-
110+
public static Matrix4f applyBendToMatrix(Matrix4f transformMatrix, float bendX, float bendY, float bendZ, float bendValue) {
118111
transformMatrix.translate(bendX, bendY, bendZ);
119-
transformMatrix.rotate(bendValue, axis);
112+
transformMatrix.rotateX(bendValue);
120113
transformMatrix.translate(-bendX, -bendY, -bendZ);
121114

122115
return transformMatrix;
123116
}
124117

125-
public static PoseStack applyBendToMatrix(PoseStack transformMatrix, float bendX, float bendY, float bendZ, float bendAxis, float bendValue) {
126-
Vector3f axis = new Vector3f((float) Math.cos(bendAxis), 0, (float) Math.sin(bendAxis));
127-
118+
public static PoseStack applyBendToMatrix(PoseStack transformMatrix, float bendX, float bendY, float bendZ, float bendValue) {
128119
transformMatrix.translate(bendX, bendY, bendZ);
129-
transformMatrix.mulPose(new Quaternionf().rotateAxis(bendValue, axis));
120+
transformMatrix.mulPose(Axis.XP.rotation(bendValue));
130121
transformMatrix.translate(-bendX, -bendY, -bendZ);
131122

132123
return transformMatrix;

common/src/main/java/com/zigythebird/bendable_cuboids/impl/BendableCuboid.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class BendableCuboid {
3131
protected final Plane otherPlane;
3232
protected final float fullSize;
3333

34-
protected float bend, bendAxis;
34+
protected float bend;
3535

3636
/**
3737
* To see how you can make existing model parts bendable look at {@link PlayerBendHelper}
@@ -48,25 +48,24 @@ public BendableCuboid(Quad[] sides, RememberingPos[] positions, float fixX, floa
4848
this.otherPlane = otherPlane;
4949
this.fullSize = fullSize;
5050

51-
this.applyBend(0, 0);//Init values to render
51+
this.applyBend(0);//Init values to render
5252
}
5353

5454
/**
5555
* Apply bend on this cuboid
5656
* Values are in radians
57-
* @param bendAxis bend axis (rotY can be used instead)
5857
* @param bendValue bend value (Same as rotX)
5958
* @return Transformation matrix for transforming children
6059
*/
61-
public Matrix4f applyBend(float bendAxis, float bendValue) {
62-
this.bend = bendValue; this.bendAxis = bendAxis;
63-
BendApplier bendApplier = BendUtil.getBend(this, bendAxis, bendValue);
60+
public Matrix4f applyBend(float bendValue) {
61+
this.bend = bendValue;
62+
BendApplier bendApplier = BendUtil.getBend(this, bendValue);
6463
this.iteratePositions(bendApplier.consumer());
6564
return bendApplier.matrix4f();
6665
}
6766

68-
public Matrix4f applyBendDegrees(float bendAxis, float bendValue) {
69-
return applyBend(bendAxis * Mth.DEG_TO_RAD, bendValue * Mth.DEG_TO_RAD);
67+
public Matrix4f applyBendDegrees(float bendValue) {
68+
return applyBend(bendValue * Mth.DEG_TO_RAD);
7069
}
7170

7271
public Direction getBendDirection() {
@@ -117,10 +116,6 @@ public float getBend() {
117116
return bend;
118117
}
119118

120-
public float getBendAxis() {
121-
return bendAxis;
122-
}
123-
124119
public void render(PoseStack.Pose matrices, VertexConsumer vertexConsumer, int light, int overlay, int color) {
125120
for(Quad quad:sides) {
126121
quad.render(matrices, vertexConsumer, light, overlay, color);
@@ -129,7 +124,7 @@ public void render(PoseStack.Pose matrices, VertexConsumer vertexConsumer, int l
129124

130125
public void copyState(BendableCuboid other) {
131126
if(other instanceof BendableCuboid b){
132-
this.applyBend(b.bendAxis, b.bend); //This works only in J16 or higher
127+
this.applyBend(b.bend); //This works only in J16 or higher
133128
}
134129
}
135130

common/src/main/java/com/zigythebird/bendable_cuboids/impl/compatibility/PlayerBendHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import java.util.Optional;
1212

1313
public class PlayerBendHelper {
14-
public static void bend(ModelPart modelPart, float axis, float rotation) {
14+
public static void bend(ModelPart modelPart, float rotation) {
1515
Optional<MutableCuboid> optionalMutableCuboid = ModelPartAccessor.optionalGetCuboid(modelPart, 0);
1616
if (optionalMutableCuboid.isPresent()) {
1717
MutableCuboid cuboid = optionalMutableCuboid.get();
1818
// Don't enable bend until rotation is bigger than epsilon.
1919
// This should avoid unnecessary heavy calculations.
2020
if (Math.abs(rotation) >= 0.0001f && cuboid.bendableCuboids$hasMutator("bend")) {
21-
cuboid.bendableCuboids$getAndActivateMutator("bend").applyBend(axis, rotation);
21+
cuboid.bendableCuboids$getAndActivateMutator("bend").applyBend(rotation);
2222
}
2323
else cuboid.bendableCuboids$getAndActivateMutator(null);
2424
}
@@ -36,7 +36,7 @@ public static void initCapeBend(ModelPart modelPart) {
3636
}));
3737
}
3838

39-
public static void applyTorsoBendToMatrix(PoseStack poseStack, float axis, float bend) {
40-
BendUtil.applyBendToMatrix(poseStack, 0, 0.375F, 0, axis, bend);
39+
public static void applyTorsoBendToMatrix(PoseStack poseStack, float bend) {
40+
BendUtil.applyBendToMatrix(poseStack, 0, 0.375F, 0, bend);
4141
}
4242
}

common/src/main/java/com/zigythebird/bendable_cuboids/impl/compatibility/geckolib/GeckoLibBendableCuboid.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public GeckoLibBendableCuboid(Quad[] sides, RememberingPos[] positions, float fi
1212
super(sides, positions, fixX, fixY, fixZ, direction, basePlane, otherPlane, fullSize);
1313
}
1414

15-
public Matrix4f applyBend(float bendAxis, float bendValue, PoseStack poseStack) {
16-
this.bend = bendValue; this.bendAxis = bendAxis;
15+
public Matrix4f applyBend(float bendValue, PoseStack poseStack) {
16+
this.bend = bendValue;
1717
BendApplier bendApplier = BendUtil.getBendLegacy(this.getBendDirection(), this.getBendX(), this.getBendY(), this.getBendZ(),
18-
this.basePlane, this.otherPlane, this.isBendInverted(), direction == Direction.UP, this.bendHeight(), bendAxis, direction == Direction.UP ? bendValue : -bendValue);
18+
this.basePlane, this.otherPlane, this.isBendInverted(), direction == Direction.UP, this.bendHeight(), direction == Direction.UP ? bendValue : -bendValue);
1919
this.iteratePositions(vector3f -> {
2020
Vector4f vector = new Vector4f(vector3f.x, vector3f.y, vector3f.z, 1).mul(poseStack.last().pose());
2121
Vector3f vector3f1 = bendApplier.consumer().apply(new Vector3f(vector.x, vector.y, vector.z));

common/src/main/java/com/zigythebird/bendable_cuboids/mixin/playeranim/CapeLayerMixin_playerAnim.java

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.zigythebird.bendable_cuboids.mixin.playeranim;
22

33
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
4+
import com.llamalad7.mixinextras.sugar.Local;
45
import com.mojang.blaze3d.vertex.PoseStack;
56
import com.mojang.math.Axis;
67
import com.zigythebird.bendable_cuboids.impl.compatibility.PlayerBendHelper;
@@ -11,15 +12,12 @@
1112
import com.zigythebird.playeranimcore.bones.PlayerAnimBone;
1213
import net.minecraft.client.model.HumanoidModel;
1314
import net.minecraft.client.model.PlayerModel;
14-
import net.minecraft.client.model.geom.EntityModelSet;
1515
import net.minecraft.client.model.geom.ModelPart;
1616
import net.minecraft.client.renderer.MultiBufferSource;
1717
import net.minecraft.client.renderer.entity.RenderLayerParent;
1818
import net.minecraft.client.renderer.entity.layers.CapeLayer;
1919
import net.minecraft.client.renderer.entity.layers.RenderLayer;
20-
import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
2120
import net.minecraft.client.renderer.entity.state.PlayerRenderState;
22-
import net.minecraft.client.resources.model.EquipmentAssetManager;
2321
import org.joml.Quaternionf;
2422
import org.spongepowered.asm.mixin.Final;
2523
import org.spongepowered.asm.mixin.Mixin;
@@ -29,53 +27,39 @@
2927
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3028

3129
@Mixin(CapeLayer.class)
32-
@SuppressWarnings({"UnstableApiUsage","rawtypes"})
33-
public abstract class CapeLayerMixin_playerAnim<T extends HumanoidRenderState> extends RenderLayer<PlayerRenderState, PlayerModel> {
30+
public abstract class CapeLayerMixin_playerAnim extends RenderLayer<PlayerRenderState, PlayerModel> {
3431
@Shadow @Final private HumanoidModel<PlayerRenderState> model;
3532

36-
@Inject(method = "<init>", at = @At("TAIL"))
37-
private void init(RenderLayerParent renderLayerParent, EntityModelSet entityModelSet, EquipmentAssetManager equipmentAssetManager, CallbackInfo ci) {
38-
PlayerBendHelper.initCapeBend(((PlayerCapeModelAccessor_playerAnim)model).getCape());
39-
}
40-
41-
public CapeLayerMixin_playerAnim(RenderLayerParent<PlayerRenderState, PlayerModel> renderLayerParent) {
33+
private CapeLayerMixin_playerAnim(RenderLayerParent<PlayerRenderState, PlayerModel> renderLayerParent, Void v) {
4234
super(renderLayerParent);
4335
}
4436

4537
@Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/renderer/entity/state/PlayerRenderState;FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/HumanoidModel;renderToBuffer(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;II)V"))
4638
private void render(PoseStack poseStack, MultiBufferSource multiBufferSource, int i, PlayerRenderState playerRenderState, float f, float g, CallbackInfo ci) {
47-
PlayerAnimManager emote = ((IPlayerAnimationState) playerRenderState).playerAnimLib$getAnimManager();
4839
if (model instanceof CapeLayerAccessor capeLayer) {
49-
if (emote.isActive()) {
50-
PlayerAnimBone bone = ((IPlayerAnimationState) playerRenderState).playerAnimLib$getAnimProcessor().getBone("torso");
51-
emote.get3DTransform(bone);
40+
PlayerAnimManager emote = ((IPlayerAnimationState)playerRenderState).playerAnimLib$getAnimManager();
41+
if (emote != null && emote.isActive()) {
5242
ModelPart torso = this.getParentModel().body;
43+
PlayerAnimBone bone = ((IPlayerAnimationState)playerRenderState).playerAnimLib$getAnimProcessor().getBone("cape");
5344

5445
poseStack.translate(torso.x / 16, torso.y / 16, torso.z / 16);
55-
poseStack.mulPose((new Quaternionf()).rotateXYZ(torso.xRot, torso.yRot, torso.zRot));
56-
PlayerBendHelper.applyTorsoBendToMatrix(poseStack, 0, bone.getBend());
46+
poseStack.mulPose((new Quaternionf()).rotateZYX(torso.zRot, torso.yRot, torso.xRot));
47+
PlayerBendHelper.applyTorsoBendToMatrix(poseStack, bone.getBend());
5748
poseStack.translate(0.0F, 0.0F, 0.125F);
58-
poseStack.mulPose(Axis.YP.rotationDegrees(180));
49+
poseStack.mulPose(Axis.YP.rotation(3.14159f));
5950

6051
ModelPart part = capeLayer.getCape();
61-
PlayerAnimBone bone1 = ((IPlayerAnimationState)playerRenderState).playerAnimLib$getAnimProcessor().getBone("cape");
62-
bone1.setToInitialPose();
63-
// bone1.setBendAxis(bone.getBendAxis());
64-
bone1.setBend(bone.getBend());
65-
emote.get3DTransform(bone1);
66-
67-
RenderUtil.translatePartToBone(part, bone1, part.getInitialPose());
52+
bone.setToInitialPose();
53+
emote.get3DTransform(bone);
6854

69-
PlayerBendHelper.bend(part, 0, bone1.getBend());
70-
} else {
71-
PlayerBendHelper.bend(capeLayer.getCape(), 0, 0);
55+
RenderUtil.translatePartToBone(part, bone);
7256
}
7357
}
7458
}
7559

7660

77-
@WrapWithCondition(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/renderer/entity/state/PlayerRenderState;FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/HumanoidModel;setupAnim(Lnet/minecraft/client/renderer/entity/state/HumanoidRenderState;)V"))
78-
private boolean setupAnim(HumanoidModel instance, T playerRenderState) {
61+
@WrapWithCondition(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/renderer/entity/state/PlayerRenderState;FF)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;translate(FFF)V"))
62+
private boolean translate(PoseStack instance, float f, float g, float h, @Local(argsOnly = true) PlayerRenderState playerRenderState) {
7963
PlayerAnimManager emote = ((IPlayerAnimationState)playerRenderState).playerAnimLib$getAnimManager();
8064
return emote == null || !emote.isActive();
8165
}

0 commit comments

Comments
 (0)