use of net.minecraft.world.DimensionType 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);
}
}
}
use of net.minecraft.world.DimensionType in project Cavern2 by kegare.
the class PortalCache method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound nbt) {
NBTTagList tagList = nbt.getTagList("LastDim", NBT.TAG_COMPOUND);
if (tagList != null && tagList.tagCount() > 0) {
for (int i = 0; i < tagList.tagCount(); ++i) {
NBTTagCompound tag = tagList.getCompoundTagAt(i);
DimensionType type = null;
try {
type = DimensionType.getById(tag.getInteger("Dim"));
} catch (IllegalArgumentException e) {
continue;
}
if (type != null && tag.hasKey("Key", NBT.TAG_STRING)) {
lastDim.put(new ResourceLocation(tag.getString("Key")), type);
}
}
}
tagList = nbt.getTagList("LastPos", NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); ++i) {
NBTTagCompound tag = tagList.getCompoundTagAt(i);
DimensionType type = null;
try {
type = DimensionType.getById(tag.getInteger("Dim"));
} catch (IllegalArgumentException e) {
continue;
}
if (type != null && tag.hasKey("Key", NBT.TAG_STRING)) {
lastPos.put(new ResourceLocation(tag.getString("Key")), type, NBTUtil.getPosFromTag(tag));
}
}
}
use of net.minecraft.world.DimensionType in project Cavern2 by kegare.
the class PortalCache method writeToNBT.
@Override
public void writeToNBT(NBTTagCompound nbt) {
NBTTagList tagList = new NBTTagList();
for (Entry<ResourceLocation, DimensionType> entry : lastDim.entrySet()) {
ResourceLocation key = entry.getKey();
DimensionType type = entry.getValue();
if (key != null && type != null) {
NBTTagCompound tag = new NBTTagCompound();
tag.setString("Key", key.toString());
tag.setInteger("Dim", type.getId());
tagList.appendTag(tag);
}
}
nbt.setTag("LastDim", tagList);
tagList = new NBTTagList();
for (Cell<ResourceLocation, DimensionType, BlockPos> entry : lastPos.cellSet()) {
ResourceLocation key = entry.getRowKey();
DimensionType type = entry.getColumnKey();
BlockPos pos = entry.getValue();
if (key != null && type != null && pos != null) {
NBTTagCompound tag = NBTUtil.createPosTag(pos);
tag.setString("Key", key.toString());
tag.setInteger("Dim", type.getId());
tagList.appendTag(tag);
}
}
nbt.setTag("LastPos", tagList);
}
Aggregations