mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +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;
|
this.internal = internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MatrixTransformStack of(PoseStack ms) {
|
|
||||||
return new MatrixTransformStack(ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PoseStack unwrap() {
|
public PoseStack unwrap() {
|
||||||
return internal;
|
return internal;
|
||||||
}
|
}
|
||||||
|
@ -58,13 +54,13 @@ public class MatrixTransformStack implements TransformStack {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransformStack push() {
|
public TransformStack pushPose() {
|
||||||
internal.pushPose();
|
internal.pushPose();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransformStack pop() {
|
public TransformStack popPose() {
|
||||||
internal.popPose();
|
internal.popPose();
|
||||||
return this;
|
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;
|
package com.jozufozu.flywheel.util.transform;
|
||||||
|
|
||||||
public interface TransformStack extends Scale<TransformStack>, Translate<TransformStack>, Rotate<TransformStack> {
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
TransformStack push();
|
|
||||||
|
|
||||||
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();
|
int j = entity.getDisplayOffset();
|
||||||
if (contents != null) {
|
if (contents != null) {
|
||||||
stack.push();
|
stack.pushPose();
|
||||||
stack.scale(0.75F);
|
stack.scale(0.75F);
|
||||||
stack.translate(-0.5D, (float)(j - 8) / 16, 0.5D);
|
stack.translate(-0.5D, (float)(j - 8) / 16, 0.5D);
|
||||||
stack.multiply(Vector3f.YP.rotationDegrees(90));
|
stack.multiply(Vector3f.YP.rotationDegrees(90));
|
||||||
contents.setTransform(stack.unwrap());
|
contents.setTransform(stack.unwrap());
|
||||||
stack.pop();
|
stack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
body.setTransform(stack.unwrap());
|
body.setTransform(stack.unwrap());
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
||||||
|
|
||||||
private final ModelData base;
|
private final ModelData base;
|
||||||
private final ModelData lid;
|
private final ModelData lid;
|
||||||
private final MatrixTransformStack stack;
|
private final MatrixTransformStack stack = new MatrixTransformStack();
|
||||||
|
|
||||||
private float lastProgress = Float.NaN;
|
private float lastProgress = Float.NaN;
|
||||||
|
|
||||||
|
@ -39,8 +39,6 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
||||||
}
|
}
|
||||||
Quaternion rotation = getDirection().getRotation();
|
Quaternion rotation = getDirection().getRotation();
|
||||||
|
|
||||||
stack = new MatrixTransformStack();
|
|
||||||
|
|
||||||
stack.translate(getInstancePosition())
|
stack.translate(getInstancePosition())
|
||||||
.scale(0.9995f)
|
.scale(0.9995f)
|
||||||
.translateAll(0.00025)
|
.translateAll(0.00025)
|
||||||
|
@ -64,7 +62,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
||||||
|
|
||||||
Quaternion spin = Vector3f.YP.rotationDegrees(270.0F * progress);
|
Quaternion spin = Vector3f.YP.rotationDegrees(270.0F * progress);
|
||||||
|
|
||||||
stack.push()
|
stack.pushPose()
|
||||||
.centre()
|
.centre()
|
||||||
.multiply(spin)
|
.multiply(spin)
|
||||||
.unCentre()
|
.unCentre()
|
||||||
|
@ -72,7 +70,7 @@ public class ShulkerBoxInstance extends TileEntityInstance<ShulkerBoxBlockEntity
|
||||||
|
|
||||||
lid.setTransform(stack.unwrap());
|
lid.setTransform(stack.unwrap());
|
||||||
|
|
||||||
stack.pop();
|
stack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,12 +5,6 @@
|
||||||
"compatibilityLevel": "JAVA_16",
|
"compatibilityLevel": "JAVA_16",
|
||||||
"refmap": "flywheel.refmap.json",
|
"refmap": "flywheel.refmap.json",
|
||||||
"client": [
|
"client": [
|
||||||
"atlas.AtlasDataMixin",
|
|
||||||
"atlas.SheetDataAccessor",
|
|
||||||
"light.LightUpdateMixin",
|
|
||||||
"light.NetworkLightUpdateMixin",
|
|
||||||
"matrix.Matrix3fMixin",
|
|
||||||
"matrix.Matrix4fMixin",
|
|
||||||
"CancelEntityRenderMixin",
|
"CancelEntityRenderMixin",
|
||||||
"ChunkRebuildHooksMixin",
|
"ChunkRebuildHooksMixin",
|
||||||
"FixFabulousDepthMixin",
|
"FixFabulousDepthMixin",
|
||||||
|
@ -21,7 +15,14 @@
|
||||||
"PausedPartialTickAccessor",
|
"PausedPartialTickAccessor",
|
||||||
"RenderHooksMixin",
|
"RenderHooksMixin",
|
||||||
"ShaderCloseMixin",
|
"ShaderCloseMixin",
|
||||||
"ShaderInstanceMixin"
|
"ShaderInstanceMixin",
|
||||||
|
"atlas.AtlasDataMixin",
|
||||||
|
"atlas.SheetDataAccessor",
|
||||||
|
"light.LightUpdateMixin",
|
||||||
|
"light.NetworkLightUpdateMixin",
|
||||||
|
"matrix.Matrix3fMixin",
|
||||||
|
"matrix.Matrix4fMixin",
|
||||||
|
"matrix.PoseStackMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
Loading…
Reference in a new issue