Jump to content

Curlip

Members
  • Posts

    8
  • Joined

  • Last visited

Posts posted by Curlip

  1.   On 9/12/2015 at 1:26 AM, coolAlias said:

    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)

  2.   On 9/11/2015 at 11:47 PM, Draco18s said:

      Quote
    I can't figure out how to save a Compound to the root of an ItemStack.

     

    stack.setTagCompound(new NBTTagCompound());

     

    Like that.  Its magic.  You now have NBT data and can start storing things into it.

     

    stack.getTagCompound().setWhatever("Key",value);

     

    I need to save a second compound in the structure:

     

    {

        Charger:{

            tags...

        }

    }

  3. 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

  4. 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)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.