This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed MixinClientWorld loading on server bug
- Loading branch information
Showing
2 changed files
with
75 additions
and
46 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
57 changes: 57 additions & 0 deletions
57
src/main/java/org/valkyrienskies/mod/fixes/FixAccurateRain.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,57 @@ | ||
package org.valkyrienskies.mod.fixes; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.util.math.AxisAlignedBB; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.RayTraceResult; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
import org.joml.Vector3d; | ||
import org.valkyrienskies.mod.common.config.VSConfig; | ||
import org.valkyrienskies.mod.common.ships.ship_world.IWorldVS; | ||
import org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject; | ||
import org.valkyrienskies.mod.common.util.JOML; | ||
import org.valkyrienskies.mod.common.util.ValkyrienUtils; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Why not just inline this code into MixinClientWorld? There's a strange mixin bug that causes MixinClientWorld to get | ||
* loaded on servers. However by using World.isRemote we can prevent this code from ever being loaded on server side | ||
* therefore preventing an incorrect side crash. | ||
*/ | ||
public class FixAccurateRain { | ||
|
||
public static BlockPos getRainPosFromShips(final World world, final BlockPos originalHeight) { | ||
if (VSConfig.accurateRain && Minecraft.getMinecraft().player != null) { | ||
final AxisAlignedBB boundingBox = new AxisAlignedBB(originalHeight.getX() - .5, 0, originalHeight.getZ() - .5, originalHeight.getX() + .5, 255, originalHeight.getZ() + .5); | ||
final List<PhysicsObject> physicsObjectList = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectsInAABB(boundingBox); | ||
|
||
final Vec3d traceStart = new Vec3d(originalHeight.getX() + .5, Minecraft.getMinecraft().player.posY + 50, originalHeight.getZ() + .5); | ||
final Vec3d traceEnd = new Vec3d(originalHeight.getX() + .5, originalHeight.getY() + .5, originalHeight.getZ() + .5); | ||
|
||
if (traceStart.y < traceEnd.y) { | ||
return originalHeight; | ||
} | ||
|
||
for (final PhysicsObject physicsObject : physicsObjectList) { | ||
final RayTraceResult result = ((IWorldVS) world).rayTraceBlocksInShip(traceStart, traceEnd, true, true, false, physicsObject); | ||
|
||
//noinspection ConstantConditions | ||
if (result != null && result.getBlockPos() != null && result.typeOfHit != RayTraceResult.Type.MISS) { | ||
Vector3d blockPosVector = JOML.convertDouble(result.getBlockPos()) | ||
.add(.5, .5, .5); | ||
|
||
physicsObject | ||
.getShipTransformationManager() | ||
.getCurrentTickTransform() | ||
.getSubspaceToGlobal() | ||
.transformPosition(blockPosVector); | ||
|
||
return new BlockPos(originalHeight.getX(), blockPosVector.y(), originalHeight.getZ()); | ||
} | ||
} | ||
} | ||
return originalHeight; | ||
} | ||
} |