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.

Featured Replies

Posted

Hey everyone, just wondering if any of y'all could help me  with a little problem I'm having. Basically, I have added a new crafting table-like block to the game,  and it uses multiple different crafting managers depending on what item is in a Modifier Slot. It has a traditional 3x3 grid with an output, as well as the modifier. What I want to do is damage the modifier slot's item when I craft something in the grid. I have seen posts on damaging items used in crafting, however those don't work for this. I've added a method to my CraftingHandler that should do the job, but I don't know where to call it.

 

public void DamageModifier(ContainerXXXXXX container)
{

	if(container.ModifierSlot.getStack() != null) {
		ItemStack j = container.ModifierSlot.getStack();

		if(j.getItem() != null && j.getItem() == ModFile.Modifier) {

			ItemStack k = new ItemStack(ModFile.Modifier, 1, j.getItemDamage() + 1);
			container.ModifierSlot.putStack(k);
		}
	}
}

 

I would call that in OnCrafting, but I don't have a ContainerXXXXXXX object there, and it would cause a crash if the player crafted something in a vanilla table because that doesn't use a ContainerXXXXXXX file. I guess my main questions are: is there a way to check what container the player used to craft something, and how should I do this?

 

EDIT: I thought about using OnStackTakenFromSlot(), but I can't think of a way to make it work.

This is the way how i would do it. That make it easy extendable.

Oh now i understand. You want to add craftdamage to your thingy^^ Easy Enough.

You have to convert the code a little bit but its not that hard. (its a tile code)(just change it to a container code)

 

ContainerClass

   public void onCraftMatrixChanged(IInventory par1IInventory)
    {
        this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
        DamageModifire();
    }

public void DamageModifier()
{
      if(modifireslot[id] != null && modifireslot[id].getItem() instanceof ModifireTool)
      {
             ModifireTool mt = (ModifireTool)modifireslot[id].getItem();
     modifireslot[id] = mt.damageTool(modifireslot[id], 1);
      }
}

 

ItemClass

public class ModifireTool extends Item
{
      public ModifireTool(int id)
      {
           super(id);
           setMaxDamage(3);
      }


      public ItemStack damageTool(ItemStack tool, int damage)
      {
             tool.setItemDamage(tool.getItemDamage()+damage);
             if(tool.getItemDamage() > tool.getMaxDamage())
             {
                  return null;
             }
             return tool;
      }
}

 

I hope that helps^^

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

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.