Search in sources :

Example 1 with ShipData

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);
        }
    }
}
Also used : QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Chunk(net.minecraft.world.chunk.Chunk) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with ShipData

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;
        }
    }
}
Also used : Vector3d(org.joml.Vector3d) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with ShipData

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;
}
Also used : ShipData(org.valkyrienskies.mod.common.ships.ShipData) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) IThreadListener(net.minecraft.util.IThreadListener) World(net.minecraft.world.World) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) UUID(java.util.UUID) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData)

Example 4 with ShipData

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));
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) ShipData(org.valkyrienskies.mod.common.ships.ShipData) DecimalFormat(java.text.DecimalFormat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with ShipData

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);
}
Also used : EntityShipMovementData(org.valkyrienskies.mod.common.entity.EntityShipMovementData) Vector3d(org.joml.Vector3d) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) ShipData(org.valkyrienskies.mod.common.ships.ShipData) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) UUID(java.util.UUID)

Aggregations

ShipData (org.valkyrienskies.mod.common.ships.ShipData)25 QueryableShipData (org.valkyrienskies.mod.common.ships.QueryableShipData)14 Vector3d (org.joml.Vector3d)9 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)6 Chunk (net.minecraft.world.chunk.Chunk)4 UUID (java.util.UUID)3 IBlockState (net.minecraft.block.state.IBlockState)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 BlockPos (net.minecraft.util.math.BlockPos)3 Vec3d (net.minecraft.util.math.Vec3d)3 World (net.minecraft.world.World)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 WorldServer (net.minecraft.world.WorldServer)2