Search in sources :

Example 91 with NBTTagList

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);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 92 with NBTTagList

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);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 93 with NBTTagList

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;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Map(java.util.Map) HashMap(java.util.HashMap)

Example 94 with NBTTagList

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());
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 95 with NBTTagList

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);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

NBTTagList (net.minecraft.nbt.NBTTagList)451 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)385 ItemStack (net.minecraft.item.ItemStack)69 NBTTagString (net.minecraft.nbt.NBTTagString)42 BlockPos (net.minecraft.util.math.BlockPos)18 HashMap (java.util.HashMap)17 Map (java.util.Map)17 NotNull (org.jetbrains.annotations.NotNull)17 ArrayList (java.util.ArrayList)14 AMVector3 (am2.api.math.AMVector3)9 ChunkPosition (net.minecraft.world.ChunkPosition)9 NBTBase (net.minecraft.nbt.NBTBase)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 Vec3d (net.minecraft.util.math.Vec3d)7 WorldCoordinate (mods.railcraft.api.core.WorldCoordinate)6 Block (net.minecraft.block.Block)6 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)5 Entity (net.minecraft.entity.Entity)5 TileEntity (net.minecraft.tileentity.TileEntity)5 ChunkPos (net.minecraft.util.math.ChunkPos)5