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;
}
Aggregations