
Curlip
-
Posts
8 -
Joined
-
Last visited
Posts posted by Curlip
-
-
It's #setTagCompound... but you should have been able to find that out in < 1 second by just typing 'stack.set' in your IDE.
I have tried typing that, immediately after I typed stack.setTagCom the window disappears.
Does it have something to do with #merge(NbtTagCompound)
-
-
I need to save a second compound in the structure:
{
Charger:{
tags...
}
}
-
Ok so I've been working with NBT and some custom interfaces, my problem is that I can't figure out how to save a Compound to the root of an ItemStack.
Their is no setTagCompound() method and the closest I can find is merge(), anyway heres my code.
if(!stack.hasTagCompound()){ stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound save = this.getCharger(stack).save(); for(Object key : save.getKeySet()){ stack.getTagCompound().getCompoundTag("Charger").setTag((String) key, save.getTag((String) key)); }
This is in the onUpdate method, .save() is a method that returns an NBTTagCompound.
Also, is there a method I can override so I don't have to put this in onUpdate(), eg. onLoad, onSave.
- Curlip
-
Whoops...
Found it, I forgot to remove the
setMaxDamage(50);
-
Hello Curlip here,
I have been creating a tool that must be charged using Redstone Dust and when fired uses TNT. Currently that all works fine, however when I started the attempt to display the Redstone level using the Damage bar, it starts with a damage offset of 14 damage and caps the top of the redstone level at 50 instead of 64.
ExplodingMiner:
public class ExplodingTool extends SimpleItem { public ExplodingTool(String itemid) { super(itemid); setMaxDamage(50); setNoRepair(); } @Override public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player){ if(stack.getTagCompound().getInteger("Redstone") != 0){ if(player.inventory.consumeInventoryItem(Blocks.tnt.getItem(player.worldObj, pos))){ player.worldObj.createExplosion(new EntityTNTPrimed(player.worldObj), (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 2, true); NBTTagCompound compound = stack.getTagCompound(); int redstone = compound.getInteger("Redstone"); compound.setInteger("Redstone", redstone - 1); return true; } return false; } return true; } @Override public int getDamage(ItemStack stack){ if(stack.getTagCompound() != null){ int redstone = stack.getTagCompound().getInteger("Redstone"); return getMaxDamage() - redstone; } return getMaxDamage(); } @Override public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityPlayer player){ NBTTagCompound compound = stack.getTagCompound(); System.out.println(compound.getInteger("Redstone")); //Debug if(compound.getInteger("Redstone") != getMaxDamage()){ if(player.inventory.consumeInventoryItem(Items.redstone)){ compound.setInteger("Redstone", (compound.getInteger("Redstone"))+1); } } return stack; } public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if(stack.getTagCompound() == null){ stack.setTagCompound(new NBTTagCompound()); } } @Override public int getMaxDamage(ItemStack stack){ return 64; } @Override public float getDigSpeed(ItemStack stack, IBlockState state){ return 5; } @Override public boolean showDurabilityBar(ItemStack stack){ return true; } }
Thanks in Advance
- Curlip
(First Post)
Saving a CompoundTag inside the root tag
in Modder Support
Posted
Ok, thanks!
My search for the setter is over.
I did realise that is what all these methods do, however I always assumed setTag was private.