public static NBTTagList toNative(ListTag tag) { NBTTagList list = new NBTTagList(); for (Tag child : tag.getValue()) { if (child instanceof EndTag) { continue; } list.appendTag(toNative(child)); } return list; }
public PacketJEIRecipe( final ByteBuf stream ) throws IOException { final ByteArrayInputStream bytes = this.getPacketByteArray( stream ); bytes.skip( stream.readerIndex() ); final NBTTagCompound comp = CompressedStreamTools.readCompressed( bytes ); if( comp != null ) { this.recipe = new ItemStack[9][]; for( int x = 0; x < this.recipe.length; x++ ) { final NBTTagList list = comp.getTagList( "#" + x, 10 ); if( list.tagCount() > 0 ) { this.recipe[x] = new ItemStack[list.tagCount()]; for( int y = 0; y < list.tagCount(); y++ ) { this.recipe[x][y] = new ItemStack( list.getCompoundTagAt( y ) ); } } } } }
protected void tickClient(ItemStack stack, EntityPlayer player) { if(!Botania.proxy.isTheClientPlayer(player)) return; NBTTagList blocks = ItemNBTHelper.getList(stack, TAG_BLOCK_POSITIONS, Constants.NBT.TAG_LONG, false); Botania.proxy.setWispFXDepthTest(false); for(int i = 0; i < blocks.tagCount(); i++) { BlockPos pos = BlockPos.fromLong(((NBTTagLong) blocks.get(i)).getLong()); float m = 0.02F; Botania.proxy.wispFX(pos.getX() + (float) Math.random(), pos.getY() + (float) Math.random(), pos.getZ() + (float) Math.random(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 0.15F + 0.05F * (float) Math.random(), m * (float) (Math.random() - 0.5), m * (float) (Math.random() - 0.5), m * (float) (Math.random() - 0.5)); } int[] entities = ItemNBTHelper.getIntArray(stack, TAG_ENTITY_POSITIONS); for(int i : entities) { Entity e = player.world.getEntityByID(i); if(e != null && Math.random() < 0.6) { Botania.proxy.setWispFXDepthTest(Math.random() < 0.6); Botania.proxy.wispFX(e.posX + (float) (Math.random() * 0.5 - 0.25) * 0.45F, e.posY + e.height, e.posZ + (float) (Math.random() * 0.5 - 0.25) * 0.45F, (float) Math.random(), (float) Math.random(), (float) Math.random(), 0.15F + 0.05F * (float) Math.random(), -0.05F - 0.03F * (float) Math.random()); } } Botania.proxy.setWispFXDepthTest(true); }
public static ListTag fromNative(NBTTagList other) { other = other.copy(); List<Tag> list = new ArrayList<>(); Class<? extends Tag> listClass = StringTag.class; int tags = other.tagCount(); for (int i = 0; i < tags; i++) { Tag child = fromNative(other.removeTag(0)); list.add(child); listClass = child.getClass(); } return new ListTag(listClass, list); }
public void loadTrials(NBTTagList trials){ this.completedTrials.clear(); for(int i = 0; i < trials.tagCount(); i++){ String strg = trials.getStringTagAt(i); if(strg != null && !strg.isEmpty()){ this.completedTrials.add(strg); } } } }
public static NBTTagList getTagListSafe(NBTTagCompound tag, String key, int type) { if(tag == null) { return new NBTTagList(); } return tag.getTagList(key, type); }
private NBTTagList getStackList() { NBTTagList list = ItemNBTHelper.getList(stack, key, Constants.NBT.TAG_COMPOUND); if (list == null) ItemNBTHelper.setList(stack, key, list = new NBTTagList()); while (list.tagCount() < size) list.appendTag(new NBTTagCompound()); return list; }
@Override public void apply(@Nonnull ItemStack item) { NBTTagCompound itemTag = new NBTTagCompound(); if (Prep.isValid(item)) { item.writeToNBT(itemTag); tagList.appendTag(itemTag); } } });
protected void tickServer(ItemStack stack, EntityPlayer player) { TIntArrayList entPosBuilder = new TIntArrayList(); NBTTagList blockPosBuilder = new NBTTagList(); scanForStack(player.getHeldItemMainhand(), player, entPosBuilder, blockPosBuilder); scanForStack(player.getHeldItemOffhand(), player, entPosBuilder, blockPosBuilder); int[] currentEnts = entPosBuilder.toArray(); boolean entsEqual = Arrays.equals(currentEnts, ItemNBTHelper.getIntArray(stack, TAG_ENTITY_POSITIONS)); boolean blocksEqual = blockPosBuilder.equals(ItemNBTHelper.getList(stack, TAG_BLOCK_POSITIONS, Constants.NBT.TAG_LONG, false)); if(!entsEqual) ItemNBTHelper.setIntArray(stack, TAG_ENTITY_POSITIONS, currentEnts); if(!blocksEqual) ItemNBTHelper.setList(stack, TAG_BLOCK_POSITIONS, blockPosBuilder); if(!entsEqual || !blocksEqual) BotaniaAPI.internalHandler.sendBaubleUpdatePacket(player, 4); }
NBTTagList nbttaglist = nbttagcompound.getTagList("Pos", 6); World world = logic.getSpawnerWorld(); int j = nbttaglist.tagCount(); double d0 = j >= 1 ? nbttaglist.getDoubleAt(0) : (double) blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) logic.spawnRange + 0.5D; double d1 = j >= 2 ? nbttaglist.getDoubleAt(1) : (double) (blockpos.getY() + world.rand.nextInt(3) - 1); double d2 = j >= 3 ? nbttaglist.getDoubleAt(2) : (double) blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) logic.spawnRange + 0.5D; Entity entity = AnvilChunkLoader.readWorldEntityPos(nbttagcompound, world, d0, d1, d2, false);
@Override public NBTBase getTag(String k) { return list.get(Integer.parseInt(k)); }
public void loadBookmarks(NBTTagList bookmarks){ for(int i = 0; i < bookmarks.tagCount(); i++){ String strg = bookmarks.getStringTagAt(i); if(strg != null && !strg.isEmpty()){ IBookletPage page = BookletUtils.getBookletPageById(strg); this.bookmarks[i] = page; } else{ this.bookmarks[i] = null; } } }
/** * Creates an NBT Tag with the materials that were used to build the item. */ private NBTTagCompound buildData(List<Material> materials) { NBTTagCompound base = new NBTTagCompound(); NBTTagList materialList = new NBTTagList(); for(Material material : materials) { materialList.appendTag(new NBTTagString(material.identifier)); } // pre-type base-modifier list NBTTagList modifierList = new NBTTagList(); // we cannot set the type directly, but it gets typed by adding a tag, so we add and remove one modifierList.appendTag(new NBTTagString()); modifierList.removeTag(0); base.setTag(Tags.BASE_MATERIALS, materialList); base.setTag(Tags.BASE_MODIFIERS, modifierList); return base; }
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, e) && scanInventory(tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, e), pstack)) { blockPosBuilder.appendTag(new NBTTagLong(pos_.toLong())); foundCap = true; break; IInventory inv = (IInventory) tile; if(scanInventory(new InvWrapper(inv), pstack)) blockPosBuilder.appendTag(new NBTTagLong(pos_.toLong()));
private NBTTagList writeList( final IItemList<IAEItemStack> myList ) { final NBTTagList out = new NBTTagList(); for( final IAEItemStack ais : myList ) { out.appendTag( this.writeItem( ais ) ); } return out; }
@Override public void deserializeNBT( NBTTagCompound nbt ) { if( nbt.hasKey( NBT_SPATIAL_DATA_KEY ) ) { final NBTTagList list = (NBTTagList) nbt.getTag( NBT_SPATIAL_DATA_KEY ); this.spatialData.clear(); for( int i = 0; i < list.tagCount(); ++i ) { final NBTTagCompound entry = list.getCompoundTagAt( i ); final StorageCellData data = new StorageCellData(); final int id = entry.getInteger( NBT_SPATIAL_ID_KEY ); data.deserializeNBT( entry ); this.spatialData.put( id, data ); } } }
private void readLog(NBTTagCompound tagCompound) { logMessages.clear(); NBTTagList logList = tagCompound.getTagList("log", Constants.NBT.TAG_STRING); for (int i = 0 ; i < logList.tagCount() ; i++) { logMessages.add(logList.getStringTagAt(i)); } }
@Override public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound nbt) { NBTTagList tagList = new NBTTagList(); for(StructureBoundingBox sbb : islands) { tagList.appendTag(sbb.toNBTTagIntArray());