mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 23:47:09 +01:00
Implement TransformStack directly on PoseStack
- Add helper method to cast to the interface.
This commit is contained in:
parent
0d2907e187
commit
e8f5e4a6c1
7 changed files with 83 additions and 23 deletions
|
@ -0,0 +1,56 @@
|
|||
package com.jozufozu.flywheel.mixin.matrix;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Quaternion;
|
||||
|
||||
@Mixin(PoseStack.class)
|
||||
public abstract class PoseStackMixin implements TransformStack {
|
||||
@Shadow
|
||||
public abstract void mulPose(Quaternion pQuaternion);
|
||||
|
||||
@Shadow
|
||||
public abstract void shadow$scale(float factorX, float factorY, float factorZ);
|
||||
|
||||
@Shadow
|
||||
public abstract void shadow$pushPose();
|
||||
|
||||
@Shadow
|
||||
public abstract void shadow$popPose();
|
||||
|
||||
@Shadow
|
||||
public abstract void shadow$translate(double x, double y, double z);
|
||||
|
||||
@Override
|
||||
public TransformStack multiply(Quaternion quaternion) {
|
||||
mulPose(quaternion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack scale(float factorX, float factorY, float factorZ) {
|
||||
shadow$scale(factorX, factorY, factorZ);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack pushPose() {
|
||||
shadow$pushPose();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack popPose() {
|
||||
shadow$popPose();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack translate(double x, double y, double z) {
|
||||
shadow$translate(x, y, z);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -15,10 +15,6 @@ public class MatrixTransformStack implements TransformStack {
|
|||
this.internal = internal;
|
||||
}
|
||||
|
||||
public static MatrixTransformStack of(PoseStack ms) {
|
||||
return new MatrixTransformStack(ms);
|
||||
}
|
||||
|
||||
public PoseStack unwrap() {
|
||||
return internal;
|
||||
}
|
||||
|
@ -58,13 +54,13 @@ public class MatrixTransformStack implements TransformStack {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TransformStack push() {
|
||||
public TransformStack pushPose() {
|
||||
internal.pushPose();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack pop() {
|
||||
public TransformStack popPose() {
|
||||
internal.popPose();
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.jozufozu.flywheel.util.transform;
|
||||
|
||||
public interface TStack<Self> {
|
||||
Self pushPose();
|
||||
|
||||
Self popPose();
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package com.jozufozu.flywheel.util.transform;
|
||||
|
||||
public interface TransformStack extends Scale<TransformStack>, Translate<TransformStack>, Rotate<TransformStack> {
|
||||
TransformStack push();
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
TransformStack pop();
|
||||
public interface TransformStack extends Scale<TransformStack>, Translate<TransformStack>, Rotate<TransformStack>, TStack<TransformStack> {
|
||||
static TransformStack cast(PoseStack stack) {
|
||||
return (TransformStack) stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,12 +111,12 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
|
|||
|
||||
int j = entity.getDisplayOffset();
|
||||
if (contents != null) {
|
||||
stack.push();
|
||||
stack.pushPose();
|
||||
stack.scale(0.75F);
|
||||
stack.translate(-0.5D, (float)(j - 8) / 16, 0.5D);
|
||||
stack.multiply(Vector3f.YP.rotationDegrees(90));
|
||||
contents.setTransform(stack.unwrap());
|
||||
stack.pop();
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
body.setTransform(stack.unwrap());
|
||||
|
|
|
@ -24,7 +24,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
|||
|
||||
private final ModelData base;
|
||||
private final ModelData lid;
|
||||
private final MatrixTransformStack stack;
|
||||
private final MatrixTransformStack stack = new MatrixTransformStack();
|
||||
|
||||
private float lastProgress = Float.NaN;
|
||||
|
||||
|
@ -39,8 +39,6 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
|||
}
|
||||
Quaternion rotation = getDirection().getRotation();
|
||||
|
||||
stack = new MatrixTransformStack();
|
||||
|
||||
stack.translate(getInstancePosition())
|
||||
.scale(0.9995f)
|
||||
.translateAll(0.00025)
|
||||
|
@ -64,7 +62,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
|||
|
||||
Quaternion spin = Vector3f.YP.rotationDegrees(270.0F * progress);
|
||||
|
||||
stack.push()
|
||||
stack.pushPose()
|
||||
.centre()
|
||||
.multiply(spin)
|
||||
.unCentre()
|
||||
|
@ -72,7 +70,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
|||
|
||||
lid.setTransform(stack.unwrap());
|
||||
|
||||
stack.pop();
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,12 +5,6 @@
|
|||
"compatibilityLevel": "JAVA_16",
|
||||
"refmap": "flywheel.refmap.json",
|
||||
"client": [
|
||||
"atlas.AtlasDataMixin",
|
||||
"atlas.SheetDataAccessor",
|
||||
"light.LightUpdateMixin",
|
||||
"light.NetworkLightUpdateMixin",
|
||||
"matrix.Matrix3fMixin",
|
||||
"matrix.Matrix4fMixin",
|
||||
"CancelEntityRenderMixin",
|
||||
"ChunkRebuildHooksMixin",
|
||||
"FixFabulousDepthMixin",
|
||||
|
@ -21,7 +15,14 @@
|
|||
"PausedPartialTickAccessor",
|
||||
"RenderHooksMixin",
|
||||
"ShaderCloseMixin",
|
||||
"ShaderInstanceMixin"
|
||||
"ShaderInstanceMixin",
|
||||
"atlas.AtlasDataMixin",
|
||||
"atlas.SheetDataAccessor",
|
||||
"light.LightUpdateMixin",
|
||||
"light.NetworkLightUpdateMixin",
|
||||
"matrix.Matrix3fMixin",
|
||||
"matrix.Matrix4fMixin",
|
||||
"matrix.PoseStackMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in a new issue