use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MessagePlayerStoppedPilotingHandler method onMessage.
@Override
public IMessage onMessage(MessagePlayerStoppedPiloting message, MessageContext ctx) {
IThreadListener mainThread = ctx.getServerHandler().server;
mainThread.addScheduledTask(() -> {
if (message.posToStopPiloting != null) {
BlockPos pos = message.posToStopPiloting;
EntityPlayerMP player = ctx.getServerHandler().player;
TileEntity tileEntity = player.world.getTileEntity(pos);
if (tileEntity instanceof ITileEntityPilotable) {
((ITileEntityPilotable) tileEntity).playerWantsToStopPiloting(player);
}
} else {
final UUID shipID = message.shipIDToStopPiloting;
final PhysicsObject physicsObject = ValkyrienUtils.getPhysObjWorld(ctx.getServerHandler().player.world).getPhysObjectFromUUID(shipID);
if (physicsObject != null && physicsObject.getShipPilot() != null && ctx.getServerHandler().player.getUniqueID().equals(physicsObject.getShipPilot().getPilot())) {
physicsObject.setShipPilot(null);
}
}
});
return null;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MessageStartPilotingHandler method onMessage.
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(MessageStartPiloting message, MessageContext ctx) {
IThreadListener mainThread = Minecraft.getMinecraft();
mainThread.addScheduledTask(() -> {
IShipPilotClient pilot = (IShipPilotClient) Minecraft.getMinecraft().player;
pilot.setControllerInputEnum(message.controlType);
if (message.posToStartPiloting != null) {
pilot.setPosBeingControlled(message.posToStartPiloting);
if (message.setPhysicsWrapperEntityToPilot) {
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(Minecraft.getMinecraft().world, message.posToStartPiloting);
if (physicsObject.isPresent()) {
pilot.setPilotedShip(physicsObject.get());
} else {
new IllegalStateException("Received incorrect piloting message!").printStackTrace();
}
} else {
pilot.setPilotedShip(null);
}
}
if (message.shipPilotingId != null)
pilot.setShipIDBeingControlled(message.shipPilotingId);
});
return null;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipTransformUpdateMessageHandler method onMessage.
@Override
@SuppressWarnings("Convert2Lambda")
public // errors. DON'T USE A LAMBDA
IMessage onMessage(final ShipTransformUpdateMessage message, final MessageContext ctx) {
IThreadListener mainThread = Minecraft.getMinecraft();
mainThread.addScheduledTask(new Runnable() {
@Override
public void run() {
World world = Minecraft.getMinecraft().world;
IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(world);
QueryableShipData worldData = QueryableShipData.get(world);
for (Map.Entry<UUID, Tuple<ShipTransform, AxisAlignedBB>> transformUpdate : message.shipTransforms.entrySet()) {
final UUID shipID = transformUpdate.getKey();
final ShipTransform shipTransform = transformUpdate.getValue().getFirst();
final AxisAlignedBB shipBB = transformUpdate.getValue().getSecond();
final PhysicsObject physicsObject = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectFromUUID(shipID);
if (physicsObject != null) {
// Do not update the transform in ShipData, that will be done by PhysicsObject.tick()
ITransformInterpolator interpolator = physicsObject.getTransformInterpolator();
interpolator.onNewTransformPacket(shipTransform, shipBB);
}
}
}
});
return null;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EntityMoveInjectionMethods method handleMove.
public static IntermediateMovementVariableStorage handleMove(MoverType type, double dx, double dy, double dz, Entity this_) {
if (this_ instanceof EntityPlayer && ((EntityPlayer) this_).isSpectator()) {
return null;
}
double movDistSq = (dx * dx) + (dy * dy) + (dz * dz);
if (movDistSq > 10000) {
// Assume this_ will take us to Ship coordinates
double newX = this_.posX + dx;
double newY = this_.posY + dy;
double newZ = this_.posZ + dz;
BlockPos newPosInBlock = new BlockPos(newX, newY, newZ);
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(this_.world, newPosInBlock);
if (!physicsObject.isPresent()) {
return null;
}
Vector3d endPos = new Vector3d(newX, newY, newZ);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(endPos, TransformType.GLOBAL_TO_SUBSPACE);
dx = endPos.x - this_.posX;
dy = endPos.y - this_.posY;
dz = endPos.z - this_.posZ;
}
IntermediateMovementVariableStorage alteredMovement = EntityCollisionInjector.alterEntityMovement(this_, type, dx, dy, dz);
return alteredMovement;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class TileEntityPassengerChair method tryToMountPlayerToChair.
public void tryToMountPlayerToChair(EntityPlayer player, Vec3d mountPos) {
if (getWorld().isRemote) {
throw new IllegalStateException("tryToMountPlayerToChair is not designed to be called on client side!");
}
boolean isChairEmpty;
if (chairEntityUUID != null) {
Entity chairEntity = ((WorldServer) getWorld()).getEntityFromUuid(chairEntityUUID);
if (chairEntity != null) {
if (chairEntity.isDead || chairEntity.isBeingRidden()) {
// Dead entity, chair is empty.
this.chairEntityUUID = null;
markDirty();
isChairEmpty = true;
} else {
// Everything checks out, this chair is not empty.
isChairEmpty = false;
}
} else {
// Either null or not a chair entity (somehow?). Just consider this chair as empty
this.chairEntityUUID = null;
markDirty();
isChairEmpty = true;
}
} else {
// No UUID for a chair entity, so this chair must be empty.
isChairEmpty = true;
}
if (isChairEmpty) {
// Chair is guaranteed empty.
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(getWorld(), getPos());
CoordinateSpaceType mountCoordType = physicsObject.isPresent() ? CoordinateSpaceType.SUBSPACE_COORDINATES : CoordinateSpaceType.GLOBAL_COORDINATES;
EntityMountableChair entityMountable = new EntityMountableChair(getWorld(), mountPos, mountCoordType, getPos());
chairEntityUUID = entityMountable.getPersistentID();
markDirty();
getWorld().spawnEntity(entityMountable);
player.startRiding(entityMountable);
}
}
Aggregations