use of net.minecraft.nbt.NBTTagList in project NetherEx by LogicTechCorp.
the class TeleporterNether method placeInPortal.
@Override
public void placeInPortal(Entity entity, float rotationYaw) {
if (entity instanceof EntityPlayer) {
PortalPositionAndDimension from = null;
try {
from = new PortalPositionAndDimension((BlockPos) FIELD_LAST_PORTAL_POS.get(entity));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
super.placeInPortal(entity, rotationYaw);
PortalPositionAndDimension to = new PortalPositionAndDimension(entity.getPosition());
NBTTagCompound tagCompound = entity.getEntityData().getCompoundTag("TeleportInfo");
NBTTagList tagList = tagCompound.getTagList("ReturnPortals", Constants.NBT.TAG_COMPOUND);
for (int i = tagList.tagCount() - 1; i >= 0; i--) {
NBTTagCompound portalCompound = tagList.getCompoundTagAt(i);
PortalPositionAndDimension testTo = new PortalPositionAndDimension(BlockPos.fromLong(portalCompound.getLong("To")), portalCompound.getInteger("ToDim"));
if (testTo.dimensionId == entity.world.provider.getDimension() && testTo.distanceSq(to) <= 9) {
tagList.removeTag(i);
}
}
NBTTagCompound portalCompound = new NBTTagCompound();
portalCompound.setLong("From", from.toLong());
portalCompound.setInteger("FromDim", from.dimensionId);
portalCompound.setLong("To", to.toLong());
portalCompound.setInteger("ToDim", to.dimensionId);
tagList.appendTag(portalCompound);
tagCompound.setTag("ReturnPortals", tagList);
entity.getEntityData().setTag("TeleportInfo", tagCompound);
} else {
super.placeInPortal(entity, rotationYaw);
}
}
use of net.minecraft.nbt.NBTTagList in project NetherEx by LogicTechCorp.
the class TeleporterNether method placeInExistingPortal.
@Override
public boolean placeInExistingPortal(Entity entity, float rotationYaw) {
if (entity instanceof EntityPlayer) {
NBTTagCompound tagCompound = entity.getEntityData().getCompoundTag("TeleportInfo");
NBTTagList tagList = tagCompound.getTagList("ReturnPortals", Constants.NBT.TAG_COMPOUND);
for (int i = tagList.tagCount() - 1; i >= 0; i--) {
NBTTagCompound portalCompound = tagList.getCompoundTagAt(i);
PortalPositionAndDimension to = new PortalPositionAndDimension(BlockPos.fromLong(portalCompound.getLong("To")), portalCompound.getInteger("ToDim"));
try {
if (to.dimensionId == entity.getEntityWorld().provider.getDimension() && to.distanceSq((Vec3i) FIELD_LAST_PORTAL_POS.get(entity)) <= 9) {
int x = MathHelper.floor(entity.posX);
int z = MathHelper.floor(entity.posZ);
long key = ChunkPos.asLong(x, z);
PortalPositionAndDimension from = new PortalPositionAndDimension(BlockPos.fromLong(portalCompound.getLong("From")), portalCompound.getInteger("FromDim"));
destinationCoordinateCache.put(key, from);
PortalPosition oldValue = destinationCoordinateCache.get(key);
if (oldValue != null) {
destinationCoordinateCache.put(key, oldValue);
}
tagList.removeTag(i);
tagCompound.setTag("ReturnPortals", tagList);
entity.getEntityData().setTag("TeleportInfo", tagCompound);
return super.placeInExistingPortal(entity, rotationYaw);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return super.placeInExistingPortal(entity, rotationYaw);
}
use of net.minecraft.nbt.NBTTagList in project RFToolsDimensions by McJty.
the class DimensionStorage method writeToNBT.
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
NBTTagList lst = new NBTTagList();
for (Map.Entry<Integer, Integer> me : energy.entrySet()) {
NBTTagCompound tc = new NBTTagCompound();
tc.setInteger("id", me.getKey());
tc.setInteger("energy", me.getValue());
lst.appendTag(tc);
}
tagCompound.setTag("dimensions", lst);
return tagCompound;
}
use of net.minecraft.nbt.NBTTagList in project ImmersiveEngineering by BluSunrize.
the class TileEntityTurret method writeCustomNBT.
@Override
public void writeCustomNBT(NBTTagCompound nbt, boolean descPacket) {
nbt.setBoolean("dummy", dummy);
nbt.setBoolean("redstoneInverted", redstoneControlInverted);
if (facing != null)
nbt.setInteger("facing", facing.ordinal());
energyStorage.writeToNBT(nbt);
if (owner != null)
nbt.setString("owner", owner);
NBTTagList list = new NBTTagList();
for (String s : targetList) list.appendTag(new NBTTagString(s));
nbt.setTag("targetList", list);
nbt.setBoolean("whitelist", whitelist);
nbt.setBoolean("attackAnimals", attackAnimals);
nbt.setBoolean("attackPlayers", attackPlayers);
nbt.setBoolean("attackNeutrals", attackNeutrals);
if (target != null)
nbt.setInteger("target", target.getEntityId());
}
use of net.minecraft.nbt.NBTTagList in project ImmersiveEngineering by BluSunrize.
the class TileEntityTurret method readOnPlacement.
@Override
public void readOnPlacement(@Nullable EntityLivingBase placer, ItemStack stack) {
if (stack.hasTagCompound()) {
NBTTagCompound tag = stack.getTagCompound();
if (tag.hasKey("owner"))
this.owner = tag.getString("owner");
else if (placer != null)
this.owner = placer.getName();
if (tag.hasKey("targetList")) {
NBTTagList list = tag.getTagList("targetList", 8);
targetList.clear();
for (int i = 0; i < list.tagCount(); i++) targetList.add(list.getStringTagAt(i));
} else if (owner != null)
targetList.add(owner);
if (tag.hasKey("whitelist"))
whitelist = tag.getBoolean("whitelist");
if (tag.hasKey("attackAnimals"))
attackAnimals = tag.getBoolean("attackAnimals");
if (tag.hasKey("attackPlayers"))
attackPlayers = tag.getBoolean("attackPlayers");
if (tag.hasKey("attackNeutrals"))
attackNeutrals = tag.getBoolean("attackNeutrals");
if (tag.hasKey("redstoneControlInverted"))
redstoneControlInverted = tag.getBoolean("redstoneControlInverted");
} else if (placer != null) {
this.owner = placer.getName();
targetList.add(owner);
}
}
Aggregations