Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Curlip

Members
  • Joined

  • Last visited

Posts posted by Curlip

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

        }

    }

  2. Posted

    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

  3. Posted

    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)

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.