Java Code Examples for net.minecraft.nbt.NBTTagList#getCompoundTagAt()

The following examples show how to use net.minecraft.nbt.NBTTagList#getCompoundTagAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LitematicaSchematic.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
private List<EntityInfo> readEntitiesFromNBT_v1(NBTTagList tagList)
{
    List<EntityInfo> entityList = new ArrayList<>();
    final int size = tagList.tagCount();

    for (int i = 0; i < size; ++i)
    {
        NBTTagCompound tag = tagList.getCompoundTagAt(i);
        Vec3d posVec = NBTUtils.readVec3d(tag);
        NBTTagCompound entityData = tag.getCompoundTag("EntityData");

        if (posVec != null && entityData.isEmpty() == false)
        {
            // Update the correct position to the Entity NBT, where it is stored in version 2
            NBTUtils.writeVec3dToListTag(posVec, entityData);
            entityList.add(new EntityInfo(posVec, entityData));
        }
    }

    return entityList;
}
 
Example 2
Source File: ContainerRemote.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
private static Set<String> getRelevantVariableNames(ItemStack remote){
    Set<String> variables = new HashSet<String>();
    NBTTagCompound tag = remote.getTagCompound();
    if(tag != null) {
        NBTTagList tagList = tag.getTagList("actionWidgets", 10);
        for(int i = 0; i < tagList.tagCount(); i++) {
            NBTTagCompound widgetTag = tagList.getCompoundTagAt(i);
            variables.add(widgetTag.getString("variableName"));
            variables.add(widgetTag.getString("enableVariable"));
            TextVariableParser parser = new TextVariableParser(widgetTag.getString("text"));
            parser.parse();
            variables.addAll(parser.getRelevantVariables());
        }
    }
    return variables;
}
 
Example 3
Source File: ItemRuler.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public BlockPosEU getPosition(ItemStack rulerStack, int index, boolean isPos1)
{
    ItemStack moduleStack = this.getSelectedModuleStack(rulerStack, ModuleType.TYPE_MEMORY_CARD_MISC);

    if (moduleStack.isEmpty() == false)
    {
        NBTTagList tagList = NBTUtils.getTagList(moduleStack, TAG_WRAPPER, TAG_LOCATIONS, Constants.NBT.TAG_COMPOUND, false);

        if (tagList == null)
        {
            return null;
        }

        if (index < 0)
        {
            index = this.getLocationSelection(rulerStack);
        }

        String tagName = isPos1 ? "Pos1" : "Pos2";
        NBTTagCompound tag = tagList.getCompoundTagAt(index);

        return BlockPosEU.readFromTag(tag.getCompoundTag(tagName));
    }

    return null;
}
 
Example 4
Source File: MaterialCache.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void readMapFromNBT(NBTTagCompound nbt, String tagName, IdentityHashMap<IBlockState, ItemStack> map)
{
    if (nbt.hasKey(tagName, Constants.NBT.TAG_LIST))
    {
        NBTTagList list = nbt.getTagList(tagName, Constants.NBT.TAG_COMPOUND);
        final int count = list.tagCount();

        for (int i = 0; i < count; ++i)
        {
            NBTTagCompound tag = list.getCompoundTagAt(i);

            if (tag.hasKey("Block", Constants.NBT.TAG_COMPOUND) &&
                tag.hasKey("Item", Constants.NBT.TAG_COMPOUND))
            {
                IBlockState state = NBTUtil.readBlockState(tag.getCompoundTag("Block"));

                if (state != null)
                {
                    ItemStack stack = new ItemStack(tag.getCompoundTag("Item"));
                    this.buildItemsForStates.put(state, stack);
                }
            }
        }
    }
}
 
Example 5
Source File: TileEntityPresent.java    From Chisel-2 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound tag) {
	super.readFromNBT(tag);
	NBTTagList nbttaglist = tag.getTagList("Items", 10);

	for (int i = 0; i < nbttaglist.tagCount(); ++i) {
		NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
		int j = nbttagcompound1.getByte("Slot") & 255;

		if (j >= 0 && j < getTrueSizeInventory()) {
			inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
		}
	}

	this.isParent = tag.getBoolean("isParent");

	this.rotation = tag.getInteger("rotation");
	if (tag.hasKey("conDir")) {
		cachedDir = ForgeDirection.values()[tag.getInteger("conDir")];
	}
	autoSearch = true;
}
 
Example 6
Source File: VanillaStructure.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected List<EntityInfo> readEntitiesFromTag(NBTTagCompound tag)
{
    List<EntityInfo> entities = new ArrayList<>();
    NBTTagList tagList = tag.getTagList("entities", Constants.NBT.TAG_COMPOUND);
    final int size = tagList.tagCount();

    for (int i = 0; i < size; ++i)
    {
        NBTTagCompound entityData = tagList.getCompoundTagAt(i);
        Vec3d pos = NBTUtils.readVec3dFromListTag(entityData, "pos");

        if (pos != null && entityData.hasKey("nbt", Constants.NBT.TAG_COMPOUND))
        {
            entities.add(new EntityInfo(pos, entityData.getCompoundTag("nbt")));
        }
    }

    return entities;
}
 
Example 7
Source File: TileEntityAssemblyController.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound tag){

    super.readFromNBT(tag);
    goingToHomePosition = tag.getBoolean("goingToHomePosition");
    foundAllMachines = tag.getBoolean("foundAllMachines");
    foundDuplicateMachine = tag.getBoolean("foundDuplicate");
    displayedText = tag.getString("displayedText");
    for(int i = 0; i < 6; i++) {
        sidesConnected[i] = tag.getBoolean("sideConnected" + i);
    }
    // Read in the ItemStacks in the inventory from NBT
    NBTTagList tagList = tag.getTagList("Items", 10);
    inventory = new ItemStack[getSizeInventory()];
    for(int i = 0; i < tagList.tagCount(); ++i) {
        NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
        byte slot = tagCompound.getByte("Slot");
        if(slot >= 0 && slot < inventory.length) {
            inventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
        }
    }
    if(inventory[PROGRAM_INVENTORY_INDEX] != null) {
        curProgram = ItemAssemblyProgram.getProgramFromItem(inventory[PROGRAM_INVENTORY_INDEX].getItemDamage());
        if(curProgram != null) curProgram.readFromNBT(tag);
    }
}
 
Example 8
Source File: TileEntityPoweredInventoryFluid.java    From BigReactors with MIT License 6 votes vote down vote up
private void readFluidsFromNBT(NBTTagCompound tag) {
	// Initialize tanks to empty, as we send sparse updates.
	for(int i = 0; i < tanks.length; i++) {
		tanks[i].setFluid(null);
	}

	if(tag.hasKey("fluids")) {
		NBTTagList tagList = tag.getTagList("fluids", 10);
		for(int i = 0; i < tagList.tagCount(); i++) {
			NBTTagCompound fluidTag = tagList.getCompoundTagAt(i);
			int fluidIdx = fluidTag.getInteger("tagIdx");
			FluidStack newFluid = FluidStack.loadFluidStackFromNBT(fluidTag);
			tanks[fluidIdx].setFluid(newFluid);
		}
	}
}
 
Example 9
Source File: TileEntityCoordTransporter.java    From ModdingTutorials with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound)
{
	super.readFromNBT(compound);
	
	teleports = new ArrayList<CoordEntry>();
	
	NBTTagList entryList = (NBTTagList) compound.getTag("teleports");
	for(int i = 0; i < entryList.tagCount(); i++)
	{
		NBTTagCompound entryCompound = entryList.getCompoundTagAt(i);
		CoordEntry entry = CoordEntry.readEntryFromNBT(entryCompound);
		teleports.add(entry);
	}
}
 
Example 10
Source File: TileEntityIndustrialWandRecharge.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
public void readFromNBT(NBTTagCompound p_145839_1_) {
    super.readFromNBT(p_145839_1_);
    NBTTagList nbttaglist = p_145839_1_.getTagList("Items", 10);
    this.ItemStacks = new ItemStack[this.getSizeInventory()];

    for (int i = 0; i < nbttaglist.tagCount(); ++i) {
        NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
        byte b0 = nbttagcompound1.getByte("Slot");

        if (b0 >= 0 && b0 < this.ItemStacks.length) {
            this.ItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
        }
    }
}
 
Example 11
Source File: VillageLordInventory.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
public void loadAllItems(NBTTagList list) {
	for (int i = 0; i < list.tagCount(); ++i) {
		NBTTagCompound nbttagcompound = list.getCompoundTagAt(i);
		int slot = nbttagcompound.getByte("Slot") & 255;
		if (slot >= 0 && slot < getSizeInventory()) {
			setInventorySlotContents(slot, new ItemStack(nbttagcompound));
		}
	}
}
 
Example 12
Source File: AbstractPair.java    From NEI-Integration with MIT License 5 votes vote down vote up
protected void loadNBT(NBTTagCompound data) {
    NBTTagList list = data.getTagList("pairings", 10);
    for (byte entry = 0; entry < list.tagCount(); entry++) {
        NBTTagCompound tag = list.getCompoundTagAt(entry);
        int[] c = tag.getIntArray("coords");
        pairings.add(new WorldCoordinate(c[0], c[1], c[2], c[3]));
    }
}
 
Example 13
Source File: AspectList.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reads the list of aspects from nbt
 * @param nbttagcompound
 * @return 
 */
public void readFromNBT(NBTTagCompound nbttagcompound)
   {
       aspects.clear();
       NBTTagList tlist = nbttagcompound.getTagList("Aspects",(byte)10);
	for (int j = 0; j < tlist.tagCount(); j++) {
		NBTTagCompound rs = (NBTTagCompound) tlist.getCompoundTagAt(j);
		if (rs.hasKey("key")) {
			add(	Aspect.getAspect(rs.getString("key")),
					rs.getInteger("amount"));
		}
	}
   }
 
Example 14
Source File: ItemAmadronTablet.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static Map<AmadronOffer, Integer> getShoppingCart(ItemStack tablet){
    Map<AmadronOffer, Integer> offers = new HashMap<AmadronOffer, Integer>();

    if(tablet.hasTagCompound() && tablet.getTagCompound().hasKey("shoppingCart")) {
        NBTTagList list = tablet.getTagCompound().getTagList("shoppingCart", 10);
        for(int i = 0; i < list.tagCount(); i++) {
            NBTTagCompound tag = list.getCompoundTagAt(i);
            offers.put(tag.hasKey("inStock") ? AmadronOfferCustom.loadFromNBT(tag) : AmadronOffer.loadFromNBT(tag), tag.getInteger("amount"));
        }
    }
    return offers;
}
 
Example 15
Source File: GTTileBaseFuelMachine.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	this.fuel = nbt.getInteger("Fuel");
	this.maxFuel = nbt.getInteger("MaxFuel");
	this.progress = nbt.getInteger("Progress");
	this.outputs.clear();
	NBTTagList list = nbt.getTagList("Results", 10);
	for (int i = 0; i < list.tagCount(); ++i) {
		NBTTagCompound data = list.getCompoundTagAt(i);
		this.outputs.add(new MultiSlotOutput(new ItemStack(data), this.getOutputSlots()));
	}
}
 
Example 16
Source File: GTHelperStack.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static int getBookEnchantmentLevel(ItemStack stack) {
	if (!stack.isEmpty() && stack.getItem() instanceof ItemEnchantedBook) {
		NBTTagList nbttaglist = ItemEnchantedBook.getEnchantments(stack);
		for (int i = 0; i < nbttaglist.tagCount(); ++i) {
			NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
			int j = nbttagcompound.getShort("id");
			Enchantment enchantment = Enchantment.getEnchantmentByID(j);
			if (enchantment != null) {
				return nbttagcompound.getShort("lvl");
			}
		}
	}
	return 0;
}
 
Example 17
Source File: LitematicaSchematic.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Map<BlockPos, NextTickListEntry> readBlockTicksFromNBT(NBTTagList tagList)
{
    Map<BlockPos, NextTickListEntry> tickMap = new HashMap<>();
    final int size = tagList.tagCount();

    for (int i = 0; i < size; ++i)
    {
        NBTTagCompound tag = tagList.getCompoundTagAt(i);

        if (tag.hasKey("Block", Constants.NBT.TAG_STRING) &&
            tag.hasKey("Time", Constants.NBT.TAG_ANY_NUMERIC)) // XXX these were accidentally saved as longs in version 3
        {
            Block block = Block.REGISTRY.getObject(new ResourceLocation(tag.getString("Block")));

            if (block != null && block != Blocks.AIR)
            {
                BlockPos pos = new BlockPos(tag.getInteger("x"), tag.getInteger("y"), tag.getInteger("z"));
                NextTickListEntry entry = new NextTickListEntry(pos, block);
                entry.setPriority(tag.getInteger("Priority"));

                // Note: the time is a relative delay at this point
                entry.setScheduledTime(tag.getInteger("Time"));

                tickMap.put(pos, entry);
            }
        }
    }

    return tickMap;
}
 
Example 18
Source File: AspectList.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
public void readFromNBT(NBTTagCompound nbttagcompound, String label)
  {
      aspects.clear();
      NBTTagList tlist = nbttagcompound.getTagList(label,(byte)10);
for (int j = 0; j < tlist.tagCount(); j++) {
	NBTTagCompound rs = (NBTTagCompound) tlist.getCompoundTagAt(j);
	if (rs.hasKey("key")) {
		add(	Aspect.getAspect(rs.getString("key")),
				rs.getInteger("amount"));
	}
}
  }
 
Example 19
Source File: AspectList.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public void readFromNBT(NBTTagCompound nbttagcompound, String label)
  {
      aspects.clear();
      NBTTagList tlist = nbttagcompound.getTagList(label,(byte)10);
for (int j = 0; j < tlist.tagCount(); j++) {
	NBTTagCompound rs = (NBTTagCompound) tlist.getCompoundTagAt(j);
	if (rs.hasKey("key")) {
		add(	Aspect.getAspect(rs.getString("key")),
				rs.getInteger("amount"));
	}
}
  }
 
Example 20
Source File: EntityDrone.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void readEntityFromNBT(NBTTagCompound tag){
    super.readEntityFromNBT(tag);
    progWidgets = TileEntityProgrammer.getWidgetsFromNBT(tag);
    naturallySpawned = tag.getBoolean("naturallySpawned");
    currentAir = tag.getFloat("currentAir");
    volume = tag.getFloat("volume");
    dataWatcher.updateObject(12, currentAir / volume);
    propSpeed = tag.getFloat("propSpeed");
    disabledByHacking = tag.getBoolean("disabledByHacking");
    setGoingToOwner(tag.getBoolean("hackedByOwner"));
    setDroneColor(tag.getInteger("color"));
    aiManager.readFromNBT(tag.getCompoundTag("variables"));
    standby = tag.getBoolean("standby");

    // Read in the ItemStacks in the inventory from NBT
    NBTTagCompound inv = tag.getCompoundTag("Inventory");
    if(inv != null) {
        NBTTagList tagList = inv.getTagList("Inv", 10);

        upgradeInventory = new ItemStack[9];
        NBTTagList upgradeList = inv.getTagList("Items", 10);
        for(int i = 0; i < upgradeList.tagCount(); i++) {
            NBTTagCompound slotEntry = upgradeList.getCompoundTagAt(i);
            int j = slotEntry.getByte("Slot");

            if(j >= 0 && j < 9) {
                upgradeInventory[j] = ItemStack.loadItemStackFromNBT(slotEntry);
            }
        }

        inventory = new InventoryDrone("Drone Inventory", true, 1 + getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE));
        for(int i = 0; i < tagList.tagCount(); ++i) {
            NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
            byte slot = tagCompound.getByte("Slot");
            if(slot >= 0 && slot < inventory.getSizeInventory()) {
                inventory.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tagCompound));
            }
        }
    }

    tank.setCapacity(PneumaticValues.DRONE_TANK_SIZE * (1 + getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE)));
    tank.readFromNBT(tag);

    if(tag.hasKey("amadronOffer")) {
        NBTTagCompound subTag = tag.getCompoundTag("amadronOffer");
        if(subTag.getBoolean("isCustom")) {
            handlingOffer = AmadronOffer.loadFromNBT(subTag);
        } else {
            handlingOffer = AmadronOfferCustom.loadFromNBT(subTag);
        }
        if(subTag.hasKey("id")) {
            usedTablet = ItemStack.loadItemStackFromNBT(subTag);
        } else {
            usedTablet = null;
        }
        buyingPlayer = subTag.getString("buyingPlayer");
    } else {
        handlingOffer = null;
        usedTablet = null;
        buyingPlayer = null;
    }
    offerTimes = tag.getInteger("offerTimes");
}