|
| 1 | +package com.cak.pattern_schematics.mixin; |
| 2 | + |
| 3 | +import com.cak.pattern_schematics.foundation.ExpandedContraptionRotationState; |
| 4 | +import com.cak.pattern_schematics.foundation.RolledContraptionRotationState; |
| 5 | +import com.jozufozu.flywheel.util.transform.TransformStack; |
| 6 | +import com.mojang.blaze3d.vertex.PoseStack; |
| 7 | +import com.simibubi.create.content.contraptions.AbstractContraptionEntity; |
| 8 | +import com.simibubi.create.content.contraptions.OrientedContraptionEntity; |
| 9 | +import com.simibubi.create.foundation.utility.VecHelper; |
| 10 | +import net.fabricmc.api.EnvType; |
| 11 | +import net.fabricmc.api.Environment; |
| 12 | +import net.minecraft.core.Direction; |
| 13 | +import net.minecraft.world.entity.Entity; |
| 14 | +import net.minecraft.world.entity.EntityType; |
| 15 | +import net.minecraft.world.entity.vehicle.AbstractMinecart; |
| 16 | +import net.minecraft.world.level.Level; |
| 17 | +import net.minecraft.world.phys.Vec3; |
| 18 | +import org.spongepowered.asm.mixin.Mixin; |
| 19 | +import org.spongepowered.asm.mixin.Overwrite; |
| 20 | +import org.spongepowered.asm.mixin.Shadow; |
| 21 | + |
| 22 | +@Mixin(value = OrientedContraptionEntity.class, remap = false) |
| 23 | +public abstract class OrientedContraptionEntityMixin extends Entity{ |
| 24 | + |
| 25 | + public OrientedContraptionEntityMixin(EntityType<?> entityType, Level level) { |
| 26 | + super(entityType, level); |
| 27 | + } |
| 28 | + |
| 29 | + @Shadow public abstract float getInitialYaw(); |
| 30 | + |
| 31 | + @Shadow public abstract float getViewXRot(float partialTicks); |
| 32 | + |
| 33 | + @Shadow public abstract float getViewYRot(float partialTicks); |
| 34 | + |
| 35 | + @Shadow public abstract float getYawOffset(); |
| 36 | + |
| 37 | + @Shadow public float pitch; |
| 38 | + |
| 39 | + @Shadow public float yaw; |
| 40 | + |
| 41 | + @Shadow protected abstract void repositionOnCart(PoseStack matrixStack, float partialTicks, Entity ridingEntity); |
| 42 | + |
| 43 | + @Shadow protected abstract void repositionOnContraption(PoseStack matrixStack, float partialTicks, Entity ridingEntity); |
| 44 | + |
| 45 | + /** |
| 46 | + * @author CAKE |
| 47 | + * @reason DONT CARE |
| 48 | + */ |
| 49 | + @Overwrite |
| 50 | + public AbstractContraptionEntity.ContraptionRotationState getRotationState() { |
| 51 | + ExpandedContraptionRotationState crs = (ExpandedContraptionRotationState) new AbstractContraptionEntity.ContraptionRotationState(); |
| 52 | + |
| 53 | + float yawOffset = getYawOffset(); |
| 54 | + crs.pattern_schematics$setZRotation(pitch); |
| 55 | + crs.pattern_schematics$setYRotation(-yaw + yawOffset); |
| 56 | + |
| 57 | + if (pitch != 0 && yaw != 0) { |
| 58 | + crs.pattern_schematics$setSecondYRotation(-yaw); |
| 59 | + crs.pattern_schematics$setYRotation(yawOffset); |
| 60 | + } |
| 61 | + |
| 62 | + RolledContraptionRotationState rcrs = new RolledContraptionRotationState((AbstractContraptionEntity.ContraptionRotationState) crs); |
| 63 | + rcrs.setRoll(30); |
| 64 | + return rcrs; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @author CAKE |
| 69 | + * @reason DONT CARE |
| 70 | + */ |
| 71 | + @Overwrite |
| 72 | + public Vec3 applyRotation(Vec3 localPos, float partialTicks) { |
| 73 | + localPos = VecHelper.rotate(localPos, getInitialYaw(), Direction.Axis.Y); |
| 74 | + localPos = VecHelper.rotate(localPos, getViewXRot(partialTicks), Direction.Axis.Z); |
| 75 | + localPos = VecHelper.rotate(localPos, 30, Direction.Axis.X); |
| 76 | + localPos = VecHelper.rotate(localPos, getViewYRot(partialTicks), Direction.Axis.Y); |
| 77 | + return localPos; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @author CAKE |
| 82 | + * @reason DONT CARE |
| 83 | + */ |
| 84 | + @Overwrite |
| 85 | + public Vec3 reverseRotation(Vec3 localPos, float partialTicks) { |
| 86 | + localPos = VecHelper.rotate(localPos, -getViewYRot(partialTicks), Direction.Axis.Y); |
| 87 | + localPos = VecHelper.rotate(localPos, -30, Direction.Axis.X); |
| 88 | + localPos = VecHelper.rotate(localPos, -getViewXRot(partialTicks), Direction.Axis.Z); |
| 89 | + localPos = VecHelper.rotate(localPos, -getInitialYaw(), Direction.Axis.Y); |
| 90 | + return localPos; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @author CAKE |
| 95 | + * @reason DONT CARE |
| 96 | + */ |
| 97 | + @Overwrite |
| 98 | + @Environment(EnvType.CLIENT) |
| 99 | + public void applyLocalTransforms(PoseStack matrixStack, float partialTicks) { |
| 100 | + float angleInitialYaw = getInitialYaw(); |
| 101 | + float angleYaw = getViewYRot(partialTicks); |
| 102 | + float anglePitch = getViewXRot(partialTicks); |
| 103 | + |
| 104 | + matrixStack.translate(-.5f, 0, -.5f); |
| 105 | + |
| 106 | + Entity ridingEntity = getVehicle(); |
| 107 | + if (ridingEntity instanceof AbstractMinecart) |
| 108 | + repositionOnCart(matrixStack, partialTicks, ridingEntity); |
| 109 | + else if (ridingEntity instanceof AbstractContraptionEntity) { |
| 110 | + if (ridingEntity.getVehicle() instanceof AbstractMinecart) |
| 111 | + repositionOnCart(matrixStack, partialTicks, ridingEntity.getVehicle()); |
| 112 | + else |
| 113 | + repositionOnContraption(matrixStack, partialTicks, ridingEntity); |
| 114 | + } |
| 115 | + |
| 116 | + TransformStack.cast(matrixStack) |
| 117 | + .nudge(getId()) |
| 118 | + .centre() |
| 119 | + .rotateY(angleYaw) |
| 120 | + .rotateX(getRoll(getContraption))//Create contraption expander |
| 121 | + .rotateZ(anglePitch) |
| 122 | + .rotateY(angleInitialYaw) |
| 123 | + .unCentre(); |
| 124 | + } |
| 125 | + |
| 126 | + |
| 127 | +} |
0 commit comments