-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Create utilities VoidValueBox position and fixed Mi…
…xinTrackBlockOutline
- Loading branch information
Showing
10 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...java/org/valkyrienskies/mod/mixin/mod_compat/create_utilities/MixinVoidLinkBehaviour.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.valkyrienskies.mod.mixin.mod_compat.create_utilities; | ||
|
||
import me.duquee.createutilities.blocks.voidtypes.VoidLinkBehaviour; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.valkyrienskies.core.api.ships.Ship; | ||
import org.valkyrienskies.mod.common.VSGameUtilsKt; | ||
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; | ||
|
||
@Mixin(VoidLinkBehaviour.class) | ||
public class MixinVoidLinkBehaviour { | ||
|
||
|
||
|
||
|
||
@Redirect( | ||
method = "testHit", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/phys/Vec3;subtract(Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/world/phys/Vec3;" | ||
) | ||
) | ||
public Vec3 redirectSubtract(Vec3 instance, Vec3 vec) { | ||
Level level = ((VoidLinkBehaviour) (Object) this).getWorld(); | ||
|
||
Vec3 pos1 = instance; | ||
Vec3 pos2 = vec; | ||
|
||
if (level != null) { | ||
Ship ship1 = VSGameUtilsKt.getShipManagingPos(level, pos1.x, pos1.y, pos1.z); | ||
Ship ship2 = VSGameUtilsKt.getShipManagingPos(level, pos2.x, pos2.y, pos2.z); | ||
if (ship1 != null && ship2 == null) { | ||
pos2 = VectorConversionsMCKt.toMinecraft( | ||
ship1.getWorldToShip().transformPosition(VectorConversionsMCKt.toJOML(pos2)) | ||
); | ||
} else if (ship1 == null && ship2 != null) { | ||
pos1 = VectorConversionsMCKt.toMinecraft( | ||
ship2.getWorldToShip().transformPosition(VectorConversionsMCKt.toJOML(pos1)) | ||
); | ||
} | ||
} | ||
return pos1.subtract(pos2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...trackOutlines/MixinTrackBlockOutline.java → ...trackOutlines/MixinTrackBlockOutline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...yrienskies/mod/forge/mixin/compat/create/client/trackOutlines/MixinTrackBlockOutline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package org.valkyrienskies.mod.forge.mixin.compat.create.client.trackOutlines; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import com.simibubi.create.content.trains.track.TrackBlockOutline; | ||
import com.simibubi.create.content.trains.track.TrackBlockOutline.BezierPointSelection; | ||
import net.minecraft.client.Camera; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import net.minecraft.world.phys.Vec3; | ||
import net.minecraftforge.client.event.RenderHighlightEvent.Block; | ||
import org.joml.Quaterniond; | ||
import org.joml.Vector3d; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
import org.valkyrienskies.core.api.ships.Ship; | ||
import org.valkyrienskies.core.impl.game.ships.ShipObjectClient; | ||
import org.valkyrienskies.mod.common.VSClientGameUtils; | ||
import org.valkyrienskies.mod.common.VSGameUtilsKt; | ||
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; | ||
|
||
@Mixin(value = TrackBlockOutline.class, remap = false) | ||
public class MixinTrackBlockOutline { | ||
@Unique | ||
private static Vec3 valkyrienskies$cameraVec3; | ||
@Unique | ||
private static Vec3 valkyrienskies$vec; | ||
@Unique | ||
private static Vec3 valkyrienskies$angles; | ||
|
||
@Inject(method = "drawCurveSelection(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/phys/Vec3;)V", | ||
at = @At(value = "INVOKE", | ||
target = "Lcom/simibubi/create/content/trains/track/TrackBlockOutline$BezierPointSelection;angles()Lnet/minecraft/world/phys/Vec3;"), | ||
locals = LocalCapture.CAPTURE_FAILHARD) | ||
private static void harvestDrawCurveSelection(final PoseStack ms, final MultiBufferSource buffer, final Vec3 camera, | ||
final CallbackInfo ci, final Minecraft mc, | ||
final BezierPointSelection result, final VertexConsumer vb, final Vec3 vec) { | ||
|
||
valkyrienskies$cameraVec3 = camera; | ||
valkyrienskies$vec = result.vec(); | ||
valkyrienskies$angles = result.angles(); | ||
} | ||
|
||
@ModifyArg(method = "drawCurveSelection(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/phys/Vec3;)V", | ||
at = @At(value = "INVOKE", | ||
target = "Lcom/simibubi/create/content/trains/track/TrackBlockOutline;renderShape(Lnet/minecraft/world/phys/shapes/VoxelShape;Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;Ljava/lang/Boolean;)V"), | ||
index = 1) | ||
private static PoseStack redirectTransformStackTranslate(final PoseStack ms) { | ||
|
||
final Level level = Minecraft.getInstance().level; | ||
if (level != null && valkyrienskies$vec != null) { | ||
final ShipObjectClient ship; | ||
if ((ship = (ShipObjectClient) VSGameUtilsKt.getShipManagingPos(level, valkyrienskies$vec)) != null) { | ||
final Quaterniond rotation = new Quaterniond().identity(); | ||
final Quaterniond yawQuat = new Quaterniond().rotateY(valkyrienskies$angles.y); | ||
final Quaterniond pitchQuat = new Quaterniond().rotateX(valkyrienskies$angles.x); | ||
|
||
yawQuat.mul(pitchQuat, rotation); | ||
ship.getRenderTransform().getShipToWorldRotation().mul(rotation, rotation); | ||
|
||
final Vector3d worldVec = ship.getRenderTransform().getShipToWorld() | ||
.transformPosition( | ||
new Vector3d(valkyrienskies$vec.x, valkyrienskies$vec.y + .125, valkyrienskies$vec.z), | ||
new Vector3d()); | ||
|
||
ms.popPose(); | ||
ms.pushPose(); | ||
ms.translate(worldVec.x - valkyrienskies$cameraVec3.x, | ||
worldVec.y - valkyrienskies$cameraVec3.y, | ||
worldVec.z - valkyrienskies$cameraVec3.z); | ||
ms.mulPose(VectorConversionsMCKt.toFloat(rotation)); | ||
ms.translate(-.5, -.125f, -.5); | ||
} | ||
} | ||
return ms; | ||
} | ||
|
||
@Unique | ||
private static Camera valkyrienskies$info; | ||
@Unique | ||
private static BlockHitResult valkyrienskies$hitResult; | ||
|
||
@ModifyArg(method = "drawCustomBlockSelection", at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/world/level/border/WorldBorder;isWithinBounds(Lnet/minecraft/core/BlockPos;)Z")) | ||
private static BlockPos modIsWithinBounds(final BlockPos blockPos) { | ||
final Level level = Minecraft.getInstance().level; | ||
if (level != null) { | ||
final Ship ship; | ||
if ((ship = VSGameUtilsKt.getShipManagingPos(level, blockPos)) != null) { | ||
return BlockPos.containing(VectorConversionsMCKt.toMinecraft(ship.getShipToWorld() | ||
.transformPosition(VectorConversionsMCKt.toJOMLD(blockPos)))); | ||
} | ||
} | ||
return blockPos; | ||
} | ||
|
||
@Inject(method = "drawCustomBlockSelection", | ||
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;translate(DDD)V")) | ||
private static void harvest(Block event, CallbackInfo ci) { | ||
valkyrienskies$info = event.getCamera(); | ||
valkyrienskies$hitResult = (BlockHitResult) event.getTarget(); | ||
} | ||
|
||
@Redirect(method = "drawCustomBlockSelection", | ||
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;translate(DDD)V")) | ||
private static void redirectTranslate(final PoseStack instance, final double d, final double e, final double f) { | ||
final Level level = Minecraft.getInstance().level; | ||
if (level != null) { | ||
final ShipObjectClient ship; | ||
if ((ship = (ShipObjectClient) VSGameUtilsKt.getShipManagingPos(level, | ||
valkyrienskies$hitResult.getBlockPos())) != null) { | ||
final Vec3 camPos = valkyrienskies$info.getPosition(); | ||
VSClientGameUtils.transformRenderWithShip(ship.getRenderTransform(), instance, | ||
valkyrienskies$hitResult.getBlockPos(), | ||
camPos.x, camPos.y, camPos.z); | ||
} else { | ||
instance.translate(d, e, f); | ||
} | ||
} else { | ||
instance.translate(d, e, f); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters