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