Search in sources :

Example 1 with EntityMountableChair

use of org.valkyrienskies.mod.common.entity.EntityMountableChair in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class RegisterEvents method onRegisterEntitiesEvent.

/**
 * This method will be called by Forge when it is time for the mod to register its entity
 * entries.
 */
@SubscribeEvent
public static void onRegisterEntitiesEvent(@Nonnull final RegistryEvent.Register<EntityEntry> event) {
    final ResourceLocation physicsWrapperEntity = new ResourceLocation(ValkyrienSkiesMod.MOD_ID, "PhysWrapper");
    final ResourceLocation entityMountable = new ResourceLocation(ValkyrienSkiesMod.MOD_ID, "entity_mountable");
    final ResourceLocation entityMountableChair = new ResourceLocation(ValkyrienSkiesMod.MOD_ID, "entity_mountable_chair");
    // Used to ensure no duplicates of entity network id's
    int entityId = 0;
    event.getRegistry().registerAll(EntityEntryBuilder.create().entity(EntityMountable.class).id(entityMountable, entityId++).name(entityMountable.getPath()).tracker(ValkyrienSkiesMod.VS_ENTITY_LOAD_DISTANCE, 1, false).build(), EntityEntryBuilder.create().entity(EntityMountableChair.class).id(entityMountableChair, entityId++).name(entityMountableChair.getPath()).tracker(ValkyrienSkiesMod.VS_ENTITY_LOAD_DISTANCE, 1, false).build());
}
Also used : EntityMountableChair(org.valkyrienskies.mod.common.entity.EntityMountableChair) ResourceLocation(net.minecraft.util.ResourceLocation) EntityMountable(org.valkyrienskies.mod.common.entity.EntityMountable) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with EntityMountableChair

use of org.valkyrienskies.mod.common.entity.EntityMountableChair 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)

Example 3 with EntityMountableChair

use of org.valkyrienskies.mod.common.entity.EntityMountableChair in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class TileEntityPassengerChair method createRelocatedTile.

public TileEntity createRelocatedTile(BlockPos newPos, ShipTransform transform, CoordinateSpaceType coordinateSpaceType) {
    TileEntityPassengerChair relocatedTile = new TileEntityPassengerChair();
    relocatedTile.setWorld(getWorld());
    relocatedTile.setPos(newPos);
    if (chairEntityUUID != null) {
        EntityMountableChair chairEntity = (EntityMountableChair) ((WorldServer) getWorld()).getEntityFromUuid(chairEntityUUID);
        if (chairEntity != null) {
            Vec3d newMountPos = transform.transform(chairEntity.getMountPos(), TransformType.SUBSPACE_TO_GLOBAL);
            chairEntity.setMountValues(newMountPos, coordinateSpaceType, newPos);
        } else {
            chairEntityUUID = null;
        }
    }
    relocatedTile.chairEntityUUID = this.chairEntityUUID;
    // Move everything to the new tile.
    this.chairEntityUUID = null;
    this.markDirty();
    return relocatedTile;
}
Also used : EntityMountableChair(org.valkyrienskies.mod.common.entity.EntityMountableChair) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

EntityMountableChair (org.valkyrienskies.mod.common.entity.EntityMountableChair)3 Entity (net.minecraft.entity.Entity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Vec3d (net.minecraft.util.math.Vec3d)1 WorldServer (net.minecraft.world.WorldServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 EntityMountable (org.valkyrienskies.mod.common.entity.EntityMountable)1 CoordinateSpaceType (org.valkyrienskies.mod.common.ships.ship_transform.CoordinateSpaceType)1 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)1