Search in sources :

Example 1 with TileEntityCaptainsChair

use of org.valkyrienskies.mod.common.tileentity.TileEntityCaptainsChair in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class BlockCaptainsChair method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(worldIn, pos);
        if (physicsObject.isPresent()) {
            TileEntity tileEntity = worldIn.getTileEntity(pos);
            if (tileEntity instanceof TileEntityCaptainsChair) {
                Vector3d playerPos = new Vector3d(playerIn.posX, playerIn.posY, playerIn.posZ);
                physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.SUBSPACE_TO_GLOBAL);
                playerIn.posX = playerPos.x;
                playerIn.posY = playerPos.y;
                playerIn.posZ = playerPos.z;
                // Only mount the player if they're standing on the ship.
                final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(playerIn);
                if (entityShipMovementData.getTicksSinceTouchedShip() == 0 && (entityShipMovementData.getLastTouchedShip() == physicsObject.get().getShipData())) {
                    Vector3dc localMountPos = getPlayerMountOffset(state, pos);
                    ValkyrienUtils.fixEntityToShip(playerIn, localMountPos, physicsObject.get());
                }
                ((TileEntityCaptainsChair) tileEntity).setPilotEntity(playerIn);
                physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.GLOBAL_TO_SUBSPACE);
                playerIn.posX = playerPos.x;
                playerIn.posY = playerPos.y;
                playerIn.posZ = playerPos.z;
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityShipMovementData(org.valkyrienskies.mod.common.entity.EntityShipMovementData) Vector3dc(org.joml.Vector3dc) Vector3d(org.joml.Vector3d) TileEntityCaptainsChair(org.valkyrienskies.mod.common.tileentity.TileEntityCaptainsChair) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)1 Vector3d (org.joml.Vector3d)1 Vector3dc (org.joml.Vector3dc)1 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)1 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)1 TileEntityCaptainsChair (org.valkyrienskies.mod.common.tileentity.TileEntityCaptainsChair)1