use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method rayTraceBlocksForGetBlockDensity.
/**
* Use Bresenham's tracing algorithm instead of raytracing for getBlockDensity, makes it way faster
*/
@Redirect(method = "getBlockDensity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;rayTraceBlocks(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/RayTraceResult;"))
private RayTraceResult rayTraceBlocksForGetBlockDensity(World world, Vec3d start, Vec3d end) {
if (VSConfig.explosionMode == ExplosionMode.VANILLA) {
// Vanilla raytrace, ignore ships and perform the function like normal
this.shouldInterceptRayTrace = false;
RayTraceResult result = rayTraceBlocks(start, end);
this.shouldInterceptRayTrace = true;
return result;
} else if (VSConfig.explosionMode == ExplosionMode.SLOW_VANILLA) {
// Vanilla raytrace, include ships and perform the function like normal
return rayTraceBlocks(start, end);
}
java.util.function.Predicate<BlockPos> canCollide = pos -> {
IBlockState blockState = world.getBlockState(pos);
return blockState.getBlock().canCollideCheck(blockState, false);
};
// Get all the blocks between start and end
List<BlockPos> blocks = VSMath.generateLineBetween(start, end, BlockPos::new);
// Whether or not this ray trace hit a block that was collidable.
boolean collided = blocks.stream().anyMatch(canCollide);
IPhysObjectWorld physObjectWorld = ((IHasShipManager) (this)).getManager();
if (physObjectWorld != null) {
List<PhysicsObject> nearbyShips = physObjectWorld.getPhysObjectsInAABB(new AxisAlignedBB(start.x, start.y, start.z, end.x, end.y, end.z));
for (PhysicsObject obj : nearbyShips) {
Vec3d transformedStart = obj.transformVector(start, TransformType.GLOBAL_TO_SUBSPACE);
Vec3d transformedEnd = obj.transformVector(end, TransformType.GLOBAL_TO_SUBSPACE);
// Transform the raytrace into ship space and check whether or not it hit a block
List<BlockPos> physoBlocks = VSMath.generateLineBetween(transformedStart, transformedEnd, BlockPos::new);
collided |= physoBlocks.stream().anyMatch(canCollide);
}
}
// important information in the ray trace result.
return collided ? DUMMY_RAYTRACE_RESULT : null;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntityMinecart method moveToSubspace.
private void moveToSubspace() {
Vec3d position = self.getPositionVector();
for (PhysicsObject ship : ValkyrienUtils.getPhysosLoadedInWorld(self.world)) {
if (ship.getShipBB().contains(position)) {
transform = ship.getShipTransform();
transformThis(transform.getGlobalToSubspace());
isInGlobal = false;
return;
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinCPacketPlayerDigging method getPacketParent.
@Override
public ShipData getPacketParent(NetHandlerPlayServer server) {
World world = server.player.getEntityWorld();
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, thisPacketTryUse.getPosition());
if (physicsObject.isPresent()) {
return physicsObject.get().getShipData();
} else {
return null;
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinCPacketUpdateSign method getPacketParent.
@Override
public ShipData getPacketParent(NetHandlerPlayServer server) {
World world = server.player.getEntityWorld();
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, thisAsPacketSign.getPosition());
if (physicsObject.isPresent()) {
return physicsObject.get().getShipData();
} else {
return null;
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinCPacketPlayerTryUseItemOnBlock method getPacketParent.
@Override
public ShipData getPacketParent(NetHandlerPlayServer server) {
World world = server.player.getEntityWorld();
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, thisPacketTryUse.getPos());
if (physicsObject.isPresent()) {
return physicsObject.get().getShipData();
} else {
return null;
}
}
Aggregations