Search in sources :

Example 21 with PhysicsObject

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IThreadListener(net.minecraft.util.IThreadListener) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) UUID(java.util.UUID) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) ITileEntityPilotable(org.valkyrienskies.mod.common.piloting.ITileEntityPilotable)

Example 22 with PhysicsObject

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;
}
Also used : IShipPilotClient(org.valkyrienskies.mod.common.piloting.IShipPilotClient) IThreadListener(net.minecraft.util.IThreadListener) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 23 with PhysicsObject

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;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) ITransformInterpolator(org.valkyrienskies.mod.common.ships.interpolation.ITransformInterpolator) 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) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 24 with PhysicsObject

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;
}
Also used : Vector3d(org.joml.Vector3d) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) IntermediateMovementVariableStorage(org.valkyrienskies.mod.common.ships.entity_interaction.EntityCollisionInjector.IntermediateMovementVariableStorage) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 25 with PhysicsObject

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);
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityMountableChair(org.valkyrienskies.mod.common.entity.EntityMountableChair) CoordinateSpaceType(org.valkyrienskies.mod.common.ships.ship_transform.CoordinateSpaceType) WorldServer(net.minecraft.world.WorldServer) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Aggregations

PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)54 World (net.minecraft.world.World)21 Vector3d (org.joml.Vector3d)21 BlockPos (net.minecraft.util.math.BlockPos)20 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)10 IPhysObjectWorld (org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld)10 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 Vector3dc (org.joml.Vector3dc)9 TileEntity (net.minecraft.tileentity.TileEntity)8 Inject (org.spongepowered.asm.mixin.injection.Inject)8 Polygon (org.valkyrienskies.mod.common.collision.Polygon)8 ShipPolygon (org.valkyrienskies.mod.common.collision.ShipPolygon)8 Entity (net.minecraft.entity.Entity)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)7 IBlockState (net.minecraft.block.state.IBlockState)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)5 ArrayList (java.util.ArrayList)4 IThreadListener (net.minecraft.util.IThreadListener)4 Vec3d (net.minecraft.util.math.Vec3d)4