use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MainCommand method deletePhyso.
private static void deletePhyso(ICommandSender sender, ShipData shipData, DeconstructState state) {
final WorldServerShipManager world = ValkyrienUtils.getServerShipManager(sender.getEntityWorld());
final PhysicsObject obj = world.getPhysObjectFromUUID(shipData.getUuid());
if (obj != null) {
obj.setDeconstructState(state);
switch(state) {
case DECONSTRUCT_NORMAL:
sender.sendMessage(new TextComponentString("That ship is being deconstructed"));
break;
case DECONSTRUCT_IMMEDIATE_NO_COPY:
sender.sendMessage(new TextComponentString("That ship will be deleted in the next tick."));
break;
}
} else {
sender.sendMessage(new TextComponentString("That ship is not loaded"));
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PilotControlsMessageHandler method onMessage.
@Override
public IMessage onMessage(final PilotControlsMessage message, final MessageContext ctx) {
IThreadListener mainThread = ctx.getServerHandler().server;
mainThread.addScheduledTask(() -> {
if (message.controlBlockPos != null) {
World worldObj = ctx.getServerHandler().player.world;
BlockPos posFor = message.controlBlockPos;
TileEntity tile = worldObj.getTileEntity(posFor);
if (tile instanceof ITileEntityPilotable) {
((ITileEntityPilotable) tile).onPilotControlsMessage(message, ctx.getServerHandler().player);
}
} else {
final PhysicsObject physicsObject = ValkyrienUtils.getPhysObjWorld(ctx.getServerHandler().player.world).getPhysObjectFromUUID(message.shipFor);
if (physicsObject != null && physicsObject.getShipPilot() != null && physicsObject.getShipPilot().getPilot().equals(ctx.getServerHandler().player.getUniqueID())) {
physicsObject.getShipPilot().processControlMessage(message, ctx.getServerHandler().player);
}
}
});
return null;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class QueryableShipData method addOrUpdateShipPreservingPhysObj.
/**
* Adds the ShipData if it doesn't exist, or updates the values of the old ShipData to match the input.
*
* @return reference to the "real" ShipData object used by {@link IPhysObjectWorld} and {@link PhysicsObject}.
*/
public ShipData addOrUpdateShipPreservingPhysObj(ShipData ship, World world) {
Optional<ShipData> old = getShip(ship.getUuid());
if (old.isPresent()) {
PhysicsObject physicsObject = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectFromUUID(ship.getUuid());
if (physicsObject != null) {
// Ship transform updates are now done by ShipTransformUpdateMessageHandler
// ITransformInterpolator interpolator = physicsObject.getTransformInterpolator();
// interpolator.onNewTransformPacket(ship.getShipTransform(), ship.getShipBB());
} else {
old.get().setShipTransform(ship.getShipTransform());
old.get().setPrevTickShipTransform(ship.getPrevTickShipTransform());
old.get().setShipBB(ship.getShipBB());
}
// old.get().setName(ship.getName());
old.get().setPhysicsEnabled(ship.isPhysicsEnabled());
// Update inertia data
old.get().getInertiaData().setGameMoITensor(ship.getInertiaData().getGameMoITensor());
old.get().getInertiaData().setGameTickMass(ship.getInertiaData().getGameTickMass());
old.get().getInertiaData().setGameTickCenterOfMass(ship.getInertiaData().getGameTickCenterOfMass());
return old.get();
} else {
this.allShips.add(ship);
return ship;
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class VSNetwork method sendToAllNearExcept.
public static void sendToAllNearExcept(@Nullable EntityPlayer except, double x, double y, double z, double radius, int dimension, Packet<?> packetIn) {
BlockPos pos = new BlockPos(x, y, z);
World worldIn;
if (except == null) {
worldIn = DimensionManager.getWorld(dimension);
} else {
worldIn = except.world;
}
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(worldIn, pos);
Vector3d packetPosition = new Vector3d(x, y, z);
if (physicsObject.isPresent()) {
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(packetPosition, TransformType.SUBSPACE_TO_GLOBAL);
// Special treatment for certain packets.
if (packetIn instanceof SPacketSoundEffect) {
SPacketSoundEffect soundEffect = (SPacketSoundEffect) packetIn;
packetIn = new SPacketSoundEffect(soundEffect.sound, soundEffect.category, packetPosition.x, packetPosition.y, packetPosition.z, soundEffect.soundVolume, soundEffect.soundPitch);
}
if (packetIn instanceof SPacketEffect) {
SPacketEffect effect = (SPacketEffect) packetIn;
BlockPos blockpos = new BlockPos(packetPosition.x, packetPosition.y, packetPosition.z);
packetIn = new SPacketEffect(effect.soundType, blockpos, effect.soundData, effect.serverWide);
}
}
List<EntityPlayer> playerEntityList = ((WorldServer) worldIn).playerEntities;
// Original method here.
for (int i = 0; i < playerEntityList.size(); ++i) {
EntityPlayerMP entityplayermp = (EntityPlayerMP) playerEntityList.get(i);
if (entityplayermp != except && entityplayermp.dimension == dimension) {
double d0 = x - entityplayermp.posX;
double d1 = y - entityplayermp.posY;
double d2 = z - entityplayermp.posZ;
double d3 = packetPosition.x - entityplayermp.posX;
double d4 = packetPosition.y - entityplayermp.posY;
double d5 = packetPosition.z - entityplayermp.posZ;
// Cover both cases; if player is in ship space or if player is in world space.
if ((d0 * d0 + d1 * d1 + d2 * d2 < radius * radius) || (d3 * d3 + d4 * d4 + d5 * d5 < radius * radius)) {
entityplayermp.connection.sendPacket(packetIn);
}
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EntityCollisionInjector method getLadderCollisions.
/**
* Returns all the possible ladders that the entity could potentially climb with
*/
public static Iterable<Triple<PhysicsObject, BlockPos, IBlockState>> getLadderCollisions(final EntityLivingBase entity, final List<PhysicsObject> collidingShips) {
final boolean isSpectator = entity instanceof EntityPlayer && ((EntityPlayer) entity).isSpectator();
final World world = entity.getEntityWorld();
final List<Triple<PhysicsObject, BlockPos, IBlockState>> ladderCollisions = new ArrayList<>();
if (!isSpectator) {
final AxisAlignedBB bb = entity.getEntityBoundingBox();
for (PhysicsObject physicsObject : collidingShips) {
final Polygon playerPolyInShip = new Polygon(bb, physicsObject.getShipTransform(), TransformType.GLOBAL_TO_SUBSPACE);
final AxisAlignedBB playerPolyInShipBB = playerPolyInShip.getEnclosedAABB();
int mX = MathHelper.floor(playerPolyInShipBB.minX);
int mY = MathHelper.floor(playerPolyInShipBB.minY);
int mZ = MathHelper.floor(playerPolyInShipBB.minZ);
for (int y2 = mY; (double) y2 < playerPolyInShipBB.maxY; ++y2) {
for (int x2 = mX; (double) x2 < playerPolyInShipBB.maxX; ++x2) {
for (int z2 = mZ; (double) z2 < playerPolyInShipBB.maxZ; ++z2) {
BlockPos tmp = new BlockPos(x2, y2, z2);
IBlockState state = world.getBlockState(tmp);
if (state.getBlock().isLadder(state, world, tmp, entity)) {
ladderCollisions.add(Triple.of(physicsObject, tmp, state));
}
}
}
}
}
}
return ladderCollisions;
}
Aggregations