Skip to content

Commit

Permalink
compat: integrated dynamics
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubydesic committed May 23, 2024
1 parent 682a6e8 commit e4109a9
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fun ClientLevel?.transformRenderAABBToWorld(pos: Position, aabb: AABB): AABB {
return aabb
}

fun Entity.getShipManaging(): Ship? = this.level().getShipManagingPos(this.position())
fun Entity?.getShipManaging(): Ship? = this?.let { this.level().getShipManagingPos(this.position()) }

// Level
fun Level?.getShipManagingPos(chunkX: Int, chunkZ: Int) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.valkyrienskies.mod.common.util
import com.mojang.blaze3d.vertex.PoseStack
import net.fabricmc.loader.impl.lib.sat4j.core.Vec
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.core.Position
Expand Down Expand Up @@ -101,6 +102,10 @@ fun Matrix4dc.transform(v: Vector4f) = v.also {
)
}

fun Matrix4dc.transformPosition(v: Vec3): Vec3 {
return transformPosition(v.toJOML()).toMinecraft()
}

// endregion

// region Minecraft
Expand Down
5 changes: 5 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ dependencies {
// Modular Routers
modCompileOnly("curse.maven:mr-250294:4696089")

// Integrated Dynamics
modCompileOnly("curse.maven:integrated-dynamics-236307:5297722")
modCompileOnly("curse.maven:cyclops-core-232758:5262063")
modCompileOnly("curse.maven:common-capabilities-247007:4987207")

// Add Kotlin for Forge (3.12.0)
forgeRuntimeLibrary("maven.modrinth:kotlin-for-forge:${kotlin_version}")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.valkyrienskies.mod.forge.mixin.compat.integrateddynamics;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import org.cyclops.integrateddynamics.core.block.BlockRayTraceResultComponent;
import org.cyclops.integrateddynamics.core.block.VoxelShapeComponents;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;

/**
* This fixes Integrated Dynamics blocks not working on ships. Integrated Dynamics uses a custom raytrace
* for its blocks which are smaller than a full cube in size. This ensures that those raytraces are done in the shipyard.
* <p>
* Note: we already have mixins that do this for the vanilla clip method, but ID made its own clip method that does only one block.
*
* @see <a href="https://github.com/ValkyrienSkies/Valkyrien-Skies-2/issues/218">Issue #218</a>
*/
@Mixin(VoxelShapeComponents.class)
public class MixinVoxelShapeComponents {

@WrapOperation(
method = "Lorg/cyclops/integrateddynamics/core/block/VoxelShapeComponents;rayTrace(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/Entity;)Lorg/cyclops/integrateddynamics/core/block/BlockRayTraceResultComponent;",
remap = false,
at = @At(
value = "INVOKE",
target = "Lorg/cyclops/integrateddynamics/core/block/VoxelShapeComponents;clip(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/core/BlockPos;)Lorg/cyclops/integrateddynamics/core/block/BlockRayTraceResultComponent;",
remap = true
)
)
public BlockRayTraceResultComponent preRaytrace(final VoxelShapeComponents instance, final Vec3 startVec, final Vec3 endVec,
final BlockPos entry, final Operation<BlockRayTraceResultComponent> original, final BlockPos pos, @Nullable final Entity entity) {

// If we're raytracing from an entity (the player), and the player is looking at an Integrated Dynamics block
// in the shipyard, we transform the start and endpoints of the raytrace into the shipyard so that it works
// properly.
if (entity != null) {
final Ship ship = VSGameUtilsKt.getShipManagingPos(entity.getCommandSenderWorld(), pos);
if (ship != null) {
final Vec3 newStart = VectorConversionsMCKt.transformPosition(ship.getWorldToShip(), startVec);
final Vec3 newEnd = VectorConversionsMCKt.transformPosition(ship.getWorldToShip(), endVec);

return original.call(instance, newStart, newEnd, pos);
}
}

// otherwise just default to the original behavior
return original.call(instance, startVec, endVec, pos);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.valkyrienskies.mod.forge.mixin.compat.sodium;

import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.phys.AABB;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.valkyrienskies.mod.common.VSGameUtilsKt;

@Mixin(SodiumWorldRenderer.class)
public class MixinSodiumWorldRenderer {
@Shadow
private ClientLevel world;

@ModifyArg(
method = "*",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/culling/Frustum;isVisible(Lnet/minecraft/world/phys/AABB;)Z")
)
private AABB modifyBoundingBox(final AABB bb) {
return VSGameUtilsKt.transformAabbToWorld(this.world, bb);
}

}
1 change: 1 addition & 0 deletions forge/src/main/resources/valkyrienskies-forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"compat.create.MixinControlledContraptionEntity",
"compat.create.client.trackOutlines.MixinTrackBlockOutline",
"compat.immersivengineering.MixinBlockEntityInventory",
"compat.integrateddynamics.MixinVoxelShapeComponents",
"compat.modular_routers.MixinRouterMenu",
"compat.tfc.MixinTFCChunkGenerator",
"compat.thermalexpansion.MixinTileCoFH",
Expand Down
12 changes: 6 additions & 6 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ include("common")
include("fabric")
include("forge")

try {
def core = file("../vs-core")
if (core.isDirectory()) {
includeBuild(core)
}
} catch (SecurityException ignore) {}
//try {
// def core = file("../vs-core")
// if (core.isDirectory()) {
// includeBuild(core)
// }
//} catch (SecurityException ignore) {}

rootProject.name = "valkyrienskies"

0 comments on commit e4109a9

Please sign in to comment.