use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsClient method onChunkLoadEvent.
/**
* Used to handle when a chunk in a ship gets updated. This allows us to create ships on the client without
* requiring all the chunks are present at the time of ship creation.
*/
@SubscribeEvent
public void onChunkLoadEvent(ChunkEvent.Load event) {
if (!event.getWorld().isRemote) {
return;
}
Chunk chunk = event.getChunk();
QueryableShipData queryableShipData = QueryableShipData.get(event.getWorld());
Optional<ShipData> shipClaimingOptional = queryableShipData.getShipFromChunk(chunk.x, chunk.z);
if (shipClaimingOptional.isPresent()) {
ShipData shipData = shipClaimingOptional.get();
IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(event.getWorld());
PhysicsObject physicsObject = physObjectWorld.getPhysObjectFromUUID(shipData.getUuid());
if (physicsObject != null) {
physicsObject.updateChunk(chunk);
}
}
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinNetHandlerPlayServer method onSetPlayerLocation.
/**
* Fixes things such that when mods try to teleport players into the ship space, VS will either
* redirect the teleport or block it. Looking at you SimpleTeleporters mod >:/
*/
@Inject(method = "setPlayerLocation(DDDFFLjava/util/Set;)V", at = @At("HEAD"), cancellable = true)
public void onSetPlayerLocation(double x, double y, double z, float yaw, float pitch, Set<SPacketPlayerPosLook.EnumFlags> relativeSet, CallbackInfo callbackInfo) {
if (!redirectingSetPlayerLocation) {
BlockPos pos = new BlockPos(x, y, z);
// If the player is being teleported to ship space then we have to stop it.
if (ShipChunkAllocator.isBlockInShipyard(pos)) {
callbackInfo.cancel();
redirectingSetPlayerLocation = true;
World world = player.getEntityWorld();
Optional<ShipData> ship = ValkyrienUtils.getShipManagingBlock(world, pos);
if (ship.isPresent()) {
Vector3d tpPos = new Vector3d(x, y, z);
ship.get().getShipTransform().transformPosition(tpPos, TransformType.SUBSPACE_TO_GLOBAL);
// Now call this again with the transformed position.
// player.sendMessage(new TextComponentString("Transformed the player tp from <"
// + x + ":" + y + ":" + z + "> to" + tpPos));
thisAsNetHandler.setPlayerLocation(tpPos.x, tpPos.y, tpPos.z, yaw, pitch, relativeSet);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.printf("Player was teleported to %.1f, %.1f, %.1f, redirected to %.1f, %.1f, %.1f\n", x, y, z, tpPos.x, tpPos.y, tpPos.z);
}
} else {
if (VSConfig.showAnnoyingDebugOutput) {
System.out.printf("Player was teleported to %.1f, %.1f, %.1f, cancelling because no ship found\n", x, y, z);
}
player.sendMessage(new TextComponentString("Tried teleporting you to shipyard but there was no ship; teleportation canceled."));
}
redirectingSetPlayerLocation = false;
}
}
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipIndexDataMessageHandler method onMessage.
@Override
@SuppressWarnings("Convert2Lambda")
public // errors. DON'T USE A LAMBDA
IMessage onMessage(ShipIndexDataMessage message, 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 (ShipData shipData : message.indexedData) {
worldData.addOrUpdateShipPreservingPhysObj(shipData, world);
}
for (UUID loadID : message.shipsToLoad) {
physObjectWorld.queueShipLoad(loadID);
}
for (UUID unloadID : message.shipsToUnload) {
physObjectWorld.queueShipUnload(unloadID);
}
}
});
return null;
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ItemShipTracker method onItemRightClick.
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand) {
if (!worldIn.isRemote) {
final ItemStack heldItemStack = player.getHeldItem(hand);
final NBTTagCompound stackTagCompound;
if (heldItemStack.hasTagCompound()) {
stackTagCompound = heldItemStack.stackTagCompound;
} else {
stackTagCompound = new NBTTagCompound();
}
if (stackTagCompound.hasKey(NBT_DATA_KEY)) {
// Tell the player the ship location
final UUID shipUUID = UUID.fromString(stackTagCompound.getString(NBT_DATA_KEY));
final Optional<ShipData> shipDataOptional = ValkyrienUtils.getQueryableData(worldIn).getShip(shipUUID);
if (shipDataOptional.isPresent()) {
final ShipData shipData = shipDataOptional.get();
final ShipTransform currentTransform = shipData.getShipTransform();
final Vector3d shipPosition = new Vector3d(currentTransform.getPosX(), currentTransform.getPosY(), currentTransform.getPosZ());
// Only print up to 2 digits after the decimal place
final String shipPositionString = shipPosition.toString(new DecimalFormat("############.##"));
player.sendMessage(new TextComponentString(String.format("The ship %s is currently at %s.", shipData.getName(), shipPositionString)));
} else {
player.sendMessage(new TextComponentString(String.format("No ship with UUID %s found! Maybe it was destroyed.", shipUUID.toString())));
}
} else {
player.sendMessage(new TextComponentString("Not tracking any ships. Right click on a ship to track it."));
}
}
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PlayerMovementDataGenerator method generatePlayerMovementDataForClient.
/**
* Only works on the client.
*/
public static PlayerMovementData generatePlayerMovementDataForClient() {
final EntityPlayerSP entityPlayer = Minecraft.getMinecraft().player;
final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(entityPlayer);
final ShipData lastTouchedShip = entityShipMovementData.getLastTouchedShip();
final UUID lastTouchedShipId = lastTouchedShip != null ? lastTouchedShip.getUuid() : null;
final Vector3d playerPosInLocal = new Vector3d(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ);
final Vector3d playerLookInLocal = JOML.convert(entityPlayer.getLook(1));
final boolean onGround = entityPlayer.onGround;
if (lastTouchedShip != null) {
final ShipTransform shipTransform = lastTouchedShip.getShipTransform();
shipTransform.transformPosition(playerPosInLocal, TransformType.GLOBAL_TO_SUBSPACE);
shipTransform.transformDirection(playerLookInLocal, TransformType.GLOBAL_TO_SUBSPACE);
}
return new PlayerMovementData(lastTouchedShipId, entityShipMovementData.getTicksSinceTouchedShip(), entityShipMovementData.getTicksPartOfGround(), playerPosInLocal, playerLookInLocal, onGround);
}
Aggregations