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

The following examples show how to use net.minecraft.nbt.NBTTagList#hasNoTags() . 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: GTItemDataOrbStorage.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
	NBTTagCompound nbt = StackUtil.getNbtData(stack);
	NBTTagList list = nbt.getTagList("Items", 10);
	if (list.hasNoTags()) {
		tooltip.add(I18n.format("No Data Stored... How did you get this?"));
		return;
	}
	for (int i = 0; i < list.tagCount(); ++i) {
		if (i < 5) {
			NBTTagCompound data = list.getCompoundTagAt(i);
			ItemStack contained = new ItemStack(data);
			tooltip.add(I18n.format(contained.getDisplayName() + " x" + contained.getCount()));
		}
	}
	int remaining = list.tagCount() - 5;
	if (remaining > 0) {
		tooltip.add(TextFormatting.ITALIC + I18n.format("and " + remaining + " more..."));
	}
}
 
Example 2
Source File: EventManager.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onWorldTick(TickEvent.WorldTickEvent event){
	if (!event.world.isRemote && event.phase == TickEvent.Phase.END){
		NBTTagList list = new NBTTagList();
		TileEntity[] updateArray = toUpdate.values().toArray(new TileEntity[toUpdate.size()]);
		for (int i = 0; i < updateArray.length; i ++){
			TileEntity t = updateArray[i];
			if (!event.world.isRemote){
				list.appendTag(t.getUpdateTag());
			}
		}
		if (!list.hasNoTags()){
			NBTTagCompound tag = new NBTTagCompound();
			tag.setTag("data", list);
			LPPacketHandler.INSTANCE.sendToAll(new MessagePipeContentUpdate(tag));
		}
		toUpdate.clear();
	}
}
 
Example 3
Source File: TileGenericPipe.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    compound = super.writeToNBT(compound);
    NBTTagList list = new NBTTagList();
    for(LPRoutedItem lpri : contents) {
    	list.appendTag(lpri.writeToNBT());
    }
    if(!list.hasNoTags()) {
    	compound.setTag("contents", list);
    }
    NBTTagList list_fluid = new NBTTagList();
    for(LPRoutedFluid lprf : contents_fluid) {
    	list_fluid.appendTag(lprf.writeToNBT());
    }
    if(!list_fluid.hasNoTags()) {
    	compound.setTag("contents_fluid", list_fluid);
    }
    
    return compound;
}
 
Example 4
Source File: StellarBody.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
public void writeToNBT(NBTTagCompound nbt) {
	nbt.setInteger("id", this.id);
	nbt.setInteger("temperature", temperature);
	nbt.setString("name", name);
	nbt.setShort("posX", posX);
	nbt.setShort("posZ", posZ);
	nbt.setFloat("size", size);
	nbt.setFloat("seperation", starSeperation);
	
	NBTTagList list = new NBTTagList();
	
	for(StellarBody body : subStars) {
		NBTTagCompound tag = new NBTTagCompound();
		body.writeToNBT(tag);
		list.appendTag(tag);
	}
	
	if(!list.hasNoTags())
		nbt.setTag("subStars", list);
}
 
Example 5
Source File: GTTileDigitalChest.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void tryReadOrbData(EntityPlayer player) {
	if (dataSlot().isEmpty()) {
		IC2.platform.messagePlayer(player, "No Data Orb present!");
		return;
	}
	if (StackUtil.isStackEqual(dataSlot(), GTMaterialGen.get(GTItems.orbDataStorage), false, true)) {
		if (dataSlot().getCount() > 1) {
			IC2.platform.messagePlayer(player, "Read Failed: Too many orbs");
			return;
		}
		for (int i = 0; i < 54; ++i) {
			ItemStack stack = inventory.get(i);
			if (!stack.isEmpty()) {
				IC2.platform.messagePlayer(player, "Read Failed: Chest is not empty");
				return;
			}
		}
		NBTTagCompound nbt = StackUtil.getNbtData(dataSlot());
		NBTTagList list = nbt.getTagList("Items", 10);
		if (list.hasNoTags()) {
			IC2.platform.messagePlayer(player, "Read Failed: No data to read");
			return;
		}
		for (int i = 0; i < list.tagCount(); ++i) {
			NBTTagCompound data = list.getCompoundTagAt(i);
			int slot = data.getInteger("Slot");
			this.inventory.set(slot, new ItemStack(data));
		}
		dataSlot(GTMaterialGen.get(GTItems.orbData));
	}
}