Java Code Examples for net.minecraft.nbt.NBTTagList#tagCount()
The following examples show how to use
net.minecraft.nbt.NBTTagList#tagCount() .
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: TileEntityInventory.java From BigReactors with MIT License | 6 votes |
@Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); // Inventories NBTTagList tagList = new NBTTagList(); for(int i = 0; i < _inventories.length; i++) { if((_inventories[i]) != null) { NBTTagCompound itemTag = new NBTTagCompound(); itemTag.setByte("Slot", (byte)i); _inventories[i].writeToNBT(itemTag); tagList.appendTag(itemTag); } } if(tagList.tagCount() > 0) { tag.setTag("Items", tagList); } }
Example 2
Source File: TileEntityUniversalSensor.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
@Override public void readFromNBT(NBTTagCompound tag){ super.readFromNBT(tag); setSensorSetting(tag.getString("sensorSetting")); invertedRedstone = tag.getBoolean("invertedRedstone"); dishSpeed = tag.getFloat("dishSpeed"); sensorGuiText = tag.getString("sensorText"); // 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); } } positions = getGPSPositionsStatic(this, getRange()); }
Example 3
Source File: TileEntityOmnidirectionalHopper.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
@Override public void readFromNBT(NBTTagCompound tag){ super.readFromNBT(tag); inputDir = ForgeDirection.getOrientation(tag.getInteger("inputDir")); redstoneMode = tag.getInteger("redstoneMode"); leaveMaterial = tag.getBoolean("leaveMaterial"); NBTTagList tagList = tag.getTagList("Inventory", 10); inventory = new ItemStack[inventory.length]; 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); } } }
Example 4
Source File: TileEntityHardMEDrive.java From ExtraCells1 with MIT License | 6 votes |
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList nbttaglist = nbt.getTagList("Items"); this.slots = new ItemStack[this.getSizeInventory()]; if (nbt.hasKey("CustomName")) { this.customName = nbt.getString("CustomName"); } for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i); int j = nbttagcompound1.getByte("Slot") & 255; if (j >= 0 && j < this.slots.length) { this.slots[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } }
Example 5
Source File: TileEntityPotteryTable.java From GardenCollection with MIT License | 6 votes |
@Override public void readFromNBT (NBTTagCompound tag) { super.readFromNBT(tag); NBTTagList itemList = tag.getTagList("Items", 10); tableItemStacks = new ItemStack[getSizeInventory()]; for (int i = 0; i < itemList.tagCount(); i++) { NBTTagCompound item = itemList.getCompoundTagAt(i); byte slot = item.getByte("Slot"); if (slot >= 0 && slot < tableItemStacks.length) tableItemStacks[slot] = ItemStack.loadItemStackFromNBT(item); } if (tag.hasKey("CustomName", 8)) customName = tag.getString("CustomName"); }
Example 6
Source File: TileEntityElevatorBase.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
@Override public void readFromNBT(NBTTagCompound tag){ super.readFromNBT(tag); extension = tag.getFloat("extension"); targetExtension = tag.getFloat("targetExtension"); redstoneMode = tag.getInteger("redstoneMode"); if(!tag.hasKey("maxFloorHeight")) {//backwards compatibility implementation. updateMaxElevatorHeight(); } else { maxFloorHeight = tag.getInteger("maxFloorHeight"); } 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[inventory.length]; 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); } } }
Example 7
Source File: TileEntityNewBrewingStand.java From Et-Futurum with The Unlicense | 6 votes |
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList nbttaglist = nbt.getTagList("Items", 10); inventory = new ItemStack[getSizeInventory()]; for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbt1 = nbttaglist.getCompoundTagAt(i); byte b0 = nbt1.getByte("Slot"); if (b0 >= 0 && b0 < inventory.length) inventory[b0] = ItemStack.loadItemStackFromNBT(nbt1); } brewTime = nbt.getShort("BrewTime"); if (nbt.hasKey("Fuel", Constants.NBT.TAG_SHORT)) { fuel = nbt.getShort("Fuel"); if (fuel > 0) currentFuel = 30; } else { fuel = nbt.getInteger("Fuel"); currentFuel = nbt.getInteger("CurrentFuel"); } }
Example 8
Source File: TileMotor.java From Framez with GNU General Public License v3.0 | 6 votes |
protected void readFromPacketNBT(NBTTagCompound tag) { face = ForgeDirection.getOrientation(tag.getInteger("face")); getMovement().readFromNBT(tag.getCompoundTag("movement")); settings.clear(); NBTTagList l = tag.getTagList("settings", new NBTTagString().getId()); for (int i = 0; i < l.tagCount(); i++) settings.add(MotorSetting.values()[Integer.parseInt(l.getStringTagAt(i))]); blocking = new ArrayList<Vec3i>(); if (tag.hasKey("blocking")) { NBTTagList blocking = tag.getTagList("blocking", new NBTTagCompound().getId()); for (int i = 0; i < blocking.tagCount(); i++) { NBTTagCompound t = blocking.getCompoundTagAt(i); this.blocking.add(new Vec3i(t.getInteger("x"), t.getInteger("y"), t.getInteger("z"))); } } storedPower = tag.getDouble("power"); markForRenderUpdate(); }
Example 9
Source File: TileEntityBloomeryFurnace.java From GardenCollection with MIT License | 6 votes |
@Override public void readFromNBT (NBTTagCompound tag) { super.readFromNBT(tag); NBTTagList list = tag.getTagList("Items", Constants.NBT.TAG_COMPOUND); furnaceItemStacks = new ItemStack[getSizeInventory()]; for (int i = 0, n = list.tagCount(); i < n; i++) { NBTTagCompound itemTag = list.getCompoundTagAt(i); byte slot = itemTag.getByte("Slot"); if (slot >= 0 && slot < furnaceItemStacks.length) furnaceItemStacks[slot] = ItemStack.loadItemStackFromNBT(itemTag); } furnaceBurnTime = tag.getShort("BurnTime"); furnaceCookTime = tag.getShort("CookTime"); currentItemBurnTime = getItemBurnTime(furnaceItemStacks[SLOT_FUEL]); if (tag.hasKey("CustomName", Constants.NBT.TAG_STRING)) customName = tag.getString("CustomName"); }
Example 10
Source File: EntityAuraCore.java From Gadomancy with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void readEntityFromNBT(NBTTagCompound compound) { super.readEntityFromNBT(compound); this.internalAuraList = new PrimalAspectList(); ticksExisted = compound.getInteger("ticksExisted"); NBTTagList list = compound.getTagList("auraList", compound.getId()); for (int i = 0; i < list.tagCount(); i++) { NBTTagCompound cmp = list.getCompoundTagAt(i); if(cmp.hasKey("tag") && cmp.hasKey("amt")) { internalAuraList.add(Aspect.getAspect(cmp.getString("tag")), cmp.getInteger("amt")); } } if(compound.hasKey("activationVecX") && compound.hasKey("activationVecY") && compound.hasKey("activationVecZ")) { int x = compound.getInteger("activationVecX"); int y = compound.getInteger("activationVecY"); int z = compound.getInteger("activationVecZ"); activationLocation = new ChunkCoordinates(x, y, z); } sendAspectData(electParliament()); initGathering(); blockCount = compound.getInteger("blockCount"); }
Example 11
Source File: ItemLivingManipulator.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@Nullable private String getEntityName(ItemStack containerStack, int index, boolean useDisplayNameFormatting) { ItemStack moduleStack = this.getSelectedModuleStack(containerStack, ModuleType.TYPE_MEMORY_CARD_MISC); if (moduleStack.isEmpty()) { return null; } NBTTagList tagList = NBTUtils.getTagList(moduleStack, WRAPPER_TAG_NAME, "Entities", Constants.NBT.TAG_COMPOUND, false); if (tagList != null && tagList.tagCount() > index) { return this.getNameForEntityFromTag(tagList.getCompoundTagAt(index), useDisplayNameFormatting); } return null; }
Example 12
Source File: VanillaStructure.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
@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 13
Source File: AspectList.java From Chisel-2 with GNU General Public License v2.0 | 5 votes |
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 14
Source File: GTIDSUStorageManager.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void readFromNBT(NBTTagCompound nbt) { wrappers.clear(); NBTTagList list = nbt.getTagList("data", 10); for (int i = 0; i < list.tagCount(); i++) { NBTTagCompound compound = list.getCompoundTagAt(i); EnergyWrapper wrapper = new EnergyWrapper(this); wrapper.setEnergy(compound.getInteger("Energy")); wrappers.put(compound.getUniqueId("owner"), wrapper); } }
Example 15
Source File: RecipeCrudeHaloInfusion.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) { ItemStack foundHalo = ItemStack.EMPTY; boolean foundGlueStick = false; int availableItems = 0; for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack stack = inv.getStackInSlot(i); if (stack.getItem() == Items.SLIME_BALL) { if (foundGlueStick) return false; foundGlueStick = true; } else if (stack.getItem() == ModItems.FAKE_HALO) { if (!foundHalo.isEmpty()) return false; foundHalo = stack; } else if (HaloInfusionItemRegistry.isHaloInfusionItem(stack)) availableItems++; else if (!stack.isEmpty()) { return false; } } if (!foundGlueStick || foundHalo.isEmpty() || availableItems <= 0) return false; NBTTagList slots = NBTHelper.getList(foundHalo, "slots", NBTTagString.class); if (slots == null) return availableItems <= 7; int freeSlots = 0; for (int j = 0; j < slots.tagCount(); j++) { if (freeSlots >= 7) break; String string = slots.getStringTagAt(j); HaloInfusionItem infusionItem = HaloInfusionItemRegistry.getItemFromName(string); if (infusionItem == HaloInfusionItemRegistry.EMPTY) freeSlots++; } return freeSlots >= availableItems; }
Example 16
Source File: PlacementProperties.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
private void readFromNBT(NBTTagCompound nbt) { if (nbt == null || nbt.hasKey("PlacementProperties", Constants.NBT.TAG_LIST) == false) { return; } NBTTagList tagListPlayers = nbt.getTagList("PlacementProperties", Constants.NBT.TAG_COMPOUND); int countPlayers = tagListPlayers.tagCount(); for (int playerIndex = 0; playerIndex < countPlayers; playerIndex++) { this.readAllDataForPlayerFromNBT(tagListPlayers.getCompoundTagAt(playerIndex)); } }
Example 17
Source File: ItemBookCode.java From Minecoprocessors with GNU General Public License v3.0 | 5 votes |
/** * Load data from the specified NBT tag. * * @param nbt the tag to load the data from. */ public void readFromNBT(final NBTTagCompound nbt) { pages.clear(); final NBTTagList pagesNbt = nbt.getTagList(TAG_PAGES, net.minecraftforge.common.util.Constants.NBT.TAG_STRING); for (int index = 0; index < pagesNbt.tagCount(); index++) { pages.add(Arrays.asList(PATTERN_LINES.split(pagesNbt.getStringTagAt(index)))); } selectedPage = nbt.getInteger(TAG_SELECTED); validateSelectedPage(); }
Example 18
Source File: UtilItemModular.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns the ItemStack of the (currently selected, if multiple) installed module of type moduleType. * @param containerStack * @param moduleType * @return */ public static ItemStack getSelectedModuleStack(ItemStack containerStack, ModuleType moduleType) { NBTTagList nbtTagList = NBTUtils.getStoredItemsList(containerStack, false); if (nbtTagList == null) { return ItemStack.EMPTY; } int listNumStacks = nbtTagList.tagCount(); int selected = getClampedModuleSelection(containerStack, moduleType); // Get the selected-th TAG_Compound of the given module type for (int i = 0, count = -1; i < listNumStacks && count < selected; ++i) { ItemStack moduleStack = NBTUtils.loadItemStackFromTag(nbtTagList.getCompoundTagAt(i)); if (moduleStack.isEmpty() == false && moduleTypeEquals(moduleStack, moduleType)) { if (++count >= selected) { return moduleStack; } } } return ItemStack.EMPTY; }
Example 19
Source File: IslandMap.java From TFC2 with GNU General Public License v3.0 | 4 votes |
public void readFromNBT(NBTTagCompound nbt) { NBTTagList centerList = nbt.getTagList("centers", 10); NBTTagList cornerList = nbt.getTagList("corners", 10); NBTTagList edgeList = nbt.getTagList("edges", 10); Center c; centers.clear(); corners.clear(); edges.clear(); //First we create empty centers, corners, and edges that can be referenced from each other for(int i = 0; i < centerList.tagCount(); i++) { centers.add(new Center(i)); } for(int i = 0; i < cornerList.tagCount(); i++) { corners.add(new Corner(i)); } for(int i = 0; i < edgeList.tagCount(); i++) { edges.add(new Edge(i)); } for(int i = 0; i < centers.size(); i++) { c = centers.get(i); c.readFromNBT(centerList.getCompoundTagAt(i), this); //Rebuild the lake list if(c.hasAttribute(Attribute.Lake)) { int lakeID = ((LakeAttribute)c.getAttribute(Attribute.Lake)).getLakeID(); if(lakes.size() <= lakeID) lakes.setSize(lakeID+1); if(lakes.get(lakeID) == null) { lakes.set(lakeID, new Lake()); lakes.get(lakeID).lakeID = lakeID; } lakes.get(lakeID).addCenter(c); } } for(int i = 0; i < corners.size(); i++) { corners.get(i).readFromNBT(cornerList.getCompoundTagAt(i), this); } for(int i = 0; i < edges.size(); i++) { edges.get(i).readFromNBT(edgeList.getCompoundTagAt(i), this); } NBTTagList dungeonList = nbt.getTagList("dungeons", 10); for(int i = 0; i < dungeonList.tagCount(); i++) { Dungeon d = new Dungeon("generic", 0, 0, 0); d.readFromNBT(this, dungeonList.getCompoundTagAt(i)); dungeons.add(d); } this.islandData = new IslandData(this, this.getParams()); islandData.readFromNBT(nbt.getCompoundTag("data")); }
Example 20
Source File: TileEntityAirCannon.java From PneumaticCraft with GNU General Public License v3.0 | 4 votes |
@Override public void readFromNBT(NBTTagCompound tag){ super.readFromNBT(tag); redstonePowered = tag.getBoolean("redstonePowered"); targetRotationAngle = tag.getFloat("targetRotationAngle"); targetHeightAngle = tag.getFloat("targetHeightAngle"); rotationAngle = tag.getFloat("rotationAngle"); heightAngle = tag.getFloat("heightAngle"); gpsX = tag.getInteger("gpsX"); gpsY = tag.getInteger("gpsY"); gpsZ = tag.getInteger("gpsZ"); if(tag.hasKey("fireOnRightAngle")) { redstoneMode = tag.getBoolean("fireOnRightAngle") ? 0 : 1; //TODO remove legacy } else { redstoneMode = tag.getByte("redstoneMode"); } coordWithinReach = tag.getBoolean("targetWithinReach"); // 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); } } trackedItemIds = new HashSet<UUID>(); tagList = tag.getTagList("trackedItems", 10); for(int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound t = tagList.getCompoundTagAt(i); trackedItemIds.add(new UUID(t.getLong("UUIDMost"), t.getLong("UUIDLeast"))); } if(tag.hasKey("inventoryX")) { lastInsertingInventory = new ChunkPosition(tag.getInteger("inventoryX"), tag.getInteger("inventoryY"), tag.getInteger("inventoryZ")); lastInsertingInventorySide = ForgeDirection.getOrientation(tag.getByte("inventorySide")); } else { lastInsertingInventory = null; lastInsertingInventorySide = null; } }