Search in sources :

Example 1 with CoordinateSpaceType

use of org.valkyrienskies.mod.common.ships.ship_transform.CoordinateSpaceType 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

Entity (net.minecraft.entity.Entity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 WorldServer (net.minecraft.world.WorldServer)1 EntityMountableChair (org.valkyrienskies.mod.common.entity.EntityMountableChair)1 CoordinateSpaceType (org.valkyrienskies.mod.common.ships.ship_transform.CoordinateSpaceType)1 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)1