use of cavern.api.IPortalCache in project Cavern2 by kegare.
the class ItemMirageBook method transferTo.
public boolean transferTo(@Nullable DimensionType dimNew, EntityPlayer entityPlayer) {
if (entityPlayer == null || !(entityPlayer instanceof EntityPlayerMP)) {
return false;
}
EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
ResourceLocation key = CaveUtils.getKey("mirage_worlds");
IPortalCache cache = PortalCache.get(player);
DimensionType dimOld = player.world.provider.getDimensionType();
if (dimNew == null) {
dimNew = cache.getLastDim(key, null);
}
if (dimNew == null || dimOld == dimNew) {
return false;
}
if (CavernAPI.dimension.isMirageWorlds(dimNew)) {
cache.setLastDim(key, dimOld);
}
cache.setLastPos(key, dimOld, player.getPosition());
player.timeUntilPortal = player.getPortalCooldown();
player.changeDimension(dimNew.getId(), this);
if (player.getBedLocation(dimNew.getId()) == null) {
player.setSpawnChunk(player.getPosition(), true, dimNew.getId());
}
return true;
}
use of cavern.api.IPortalCache in project Cavern2 by kegare.
the class TeleporterCavern method placeInPortal.
@Override
public void placeInPortal(Entity entity, float rotationYaw) {
DimensionType type = world.provider.getDimensionType();
boolean flag = false;
if (GeneralConfig.portalCache) {
IPortalCache cache = PortalCache.get(entity);
ResourceLocation key = getKey();
BlockPos prevPos = entity.getPosition();
if (cache.hasLastPos(key, type)) {
BlockPos pos = cache.getLastPos(key, type);
entity.moveToBlockPosAndAngles(pos, entity.rotationYaw, entity.rotationPitch);
if (placeInExistingPortal(entity, rotationYaw)) {
flag = true;
} else {
entity.moveToBlockPosAndAngles(prevPos, entity.rotationYaw, entity.rotationPitch);
}
}
}
if (!flag && !placeInExistingPortal(entity, rotationYaw)) {
makePortal(entity);
placeInExistingPortal(entity, rotationYaw);
}
if (entity instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) entity;
if (CavernAPI.dimension.isInCaveDimensions(player) && player.getBedLocation() == null) {
player.setSpawnPoint(player.getPosition(), true);
}
}
}
Aggregations