Search in sources :

Example 26 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project LogisticsPipes by RS485.

the class CoreRoutedPipe method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);
    synchronized (routerIdLock) {
        if (routerId == null || routerId.isEmpty()) {
            if (router != null) {
                routerId = router.getId().toString();
            } else {
                routerId = UUID.randomUUID().toString();
            }
        }
    }
    nbttagcompound.setString("routerId", routerId);
    nbttagcompound.setLong("stat_lifetime_sent", stat_lifetime_sent);
    nbttagcompound.setLong("stat_lifetime_recieved", stat_lifetime_recieved);
    nbttagcompound.setLong("stat_lifetime_relayed", stat_lifetime_relayed);
    if (getLogisticsModule() != null) {
        getLogisticsModule().writeToNBT(nbttagcompound);
    }
    NBTTagCompound upgradeNBT = new NBTTagCompound();
    upgradeManager.writeToNBT(upgradeNBT);
    nbttagcompound.setTag("upgradeManager", upgradeNBT);
    NBTTagCompound powerNBT = new NBTTagCompound();
    powerHandler.writeToNBT(powerNBT);
    if (!powerNBT.hasNoTags()) {
        nbttagcompound.setTag("powerHandler", powerNBT);
    }
    NBTTagList sendqueue = new NBTTagList();
    for (Triplet<IRoutedItem, ForgeDirection, ItemSendMode> p : _sendQueue) {
        NBTTagCompound tagentry = new NBTTagCompound();
        NBTTagCompound tagentityitem = new NBTTagCompound();
        p.getValue1().writeToNBT(tagentityitem);
        tagentry.setTag("entityitem", tagentityitem);
        tagentry.setByte("from", (byte) (p.getValue2().ordinal()));
        tagentry.setByte("mode", (byte) (p.getValue3().ordinal()));
        sendqueue.appendTag(tagentry);
    }
    nbttagcompound.setTag("sendqueue", sendqueue);
    for (int i = 0; i < 6; i++) {
        if (signItem[i] != null) {
            nbttagcompound.setBoolean("PipeSign_" + i, true);
            int signType = -1;
            List<Class<? extends IPipeSign>> typeClasses = ItemPipeSignCreator.signTypes;
            for (int j = 0; j < typeClasses.size(); j++) {
                if (typeClasses.get(j) == signItem[i].getClass()) {
                    signType = j;
                    break;
                }
            }
            nbttagcompound.setInteger("PipeSign_" + i + "_type", signType);
            NBTTagCompound tag = new NBTTagCompound();
            signItem[i].writeToNBT(tag);
            nbttagcompound.setTag("PipeSign_" + i + "_tags", tag);
        } else {
            nbttagcompound.setBoolean("PipeSign_" + i, false);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IPipeSign(logisticspipes.pipes.signs.IPipeSign) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 27 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project LogisticsPipes by RS485.

the class LogisticsTileGenericSubMultiBlock method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);
    NBTTagList nbtList = new NBTTagList();
    for (DoubleCoordinates pos : mainPipePos) {
        NBTTagCompound compound = new NBTTagCompound();
        pos.writeToNBT("MainPipePos_", compound);
        nbtList.appendTag(compound);
    }
    nbt.setTag("MainPipePosList", nbtList);
    NBTTagList nbtTypeList = new NBTTagList();
    for (CoreMultiBlockPipe.SubBlockTypeForShare type : subTypes) {
        if (type == null)
            continue;
        nbtTypeList.appendTag(new NBTTagString(type.name()));
    }
    nbt.setTag("SubTypeList", nbtTypeList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 28 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project LogisticsPipes by RS485.

the class ItemIdentifierInventory method readFromNBT.

public void readFromNBT(NBTTagCompound nbttagcompound, String prefix) {
    NBTTagList nbttaglist = nbttagcompound.getTagList(prefix + "items", nbttagcompound.getId());
    for (int j = 0; j < nbttaglist.tagCount(); ++j) {
        NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j);
        int index = nbttagcompound2.getInteger("index");
        if (index < _contents.length) {
            ItemStack stack = ItemStack.loadItemStackFromNBT(nbttagcompound2);
            if (stack != null) {
                ItemIdentifierStack itemstack = ItemIdentifierStack.getFromStack(stack);
                if (isValidStack(itemstack)) {
                    _contents[index] = itemstack;
                }
            }
        } else {
            LogisticsPipes.log.fatal("SimpleInventory: java.lang.ArrayIndexOutOfBoundsException: " + index + " of " + _contents.length);
        }
    }
    updateContents();
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 29 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project LogisticsPipes by RS485.

the class SimpleStackInventory method readFromNBT.

public void readFromNBT(NBTTagCompound nbttagcompound, String prefix) {
    NBTTagList nbttaglist = nbttagcompound.getTagList(prefix + "items", nbttagcompound.getId());
    for (int j = 0; j < nbttaglist.tagCount(); ++j) {
        NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j);
        int index = nbttagcompound2.getInteger("index");
        if (index < _contents.length) {
            _contents[index] = ItemStack.loadItemStackFromNBT(nbttagcompound2);
        } else {
            LogisticsPipes.log.fatal("SimpleInventory: java.lang.ArrayIndexOutOfBoundsException: " + index + " of " + _contents.length);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 30 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project SimplyJetpacks by Tonius.

the class ItemMysteriousPotato method onItemUse.

@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int meta, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        TileEntity tile = world.getTileEntity(x, y, z);
        if (tile instanceof TileEntityMobSpawner) {
            NBTTagCompound tag = new NBTTagCompound();
            tile.writeToNBT(tag);
            tag.setString("EntityId", "Zombie");
            NBTTagList spawnPotentials = new NBTTagList();
            NBTTagCompound zombieSpawn = new NBTTagCompound();
            zombieSpawn.setString("Type", "Zombie");
            zombieSpawn.setInteger("Weight", 1);
            NBTTagCompound zombieSpawnProperties = new NBTTagCompound();
            zombieSpawnProperties.setString("id", "Zombie");
            NBTTagList equipment = new NBTTagList();
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(ModItems.jetpackPotato.writeToNBT(new NBTTagCompound()));
            zombieSpawnProperties.setTag("Equipment", equipment);
            NBTTagList dropChances = new NBTTagList();
            for (int i = 0; i <= 4; i++) {
                dropChances.appendTag(new NBTTagFloat(0.0F));
            }
            zombieSpawnProperties.setTag("DropChances", dropChances);
            zombieSpawn.setTag("Properties", zombieSpawnProperties);
            spawnPotentials.appendTag(zombieSpawn);
            tag.setTag("SpawnPotentials", spawnPotentials);
            tag.setShort("SpawnCount", (short) 2);
            tag.setShort("SpawnRange", (short) 8);
            tag.setShort("Delay", (short) -1);
            tag.setShort("MinSpawnDelay", (short) 30);
            tag.setShort("MaxSpawnDelay", (short) 60);
            tag.setShort("MaxNearbyEntities", (short) 10);
            tag.setShort("RequiredPlayerRange", (short) 96);
            tile.readFromNBT(tag);
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner)

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