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

Hello, I'm back with another recipe and data gen problem, so basically I have a hammer item, and 2 ingots, they turn into plates (of their type), I've done that all ready and it works fine, now my problem is that the hammer doesn't seem to get damaged (because I got no idea how), here's my code :

HammerItem: (just incase I've done something wrong here!)

public class HammerItem extends Item {

    private static final Random RAND = new Random();

	public HammerItem() {
		super(new Item.Properties()
				.group(MorePlates.ITEMGROUP)
                .maxStackSize(1)
                .setNoRepair());
	}

	@Override
    public boolean hasContainerItem(ItemStack stack) {
        return true;
    }

    @Override
    public int getMaxDamage(ItemStack stack) {
        return Config.GENERAL.DURABILITY_HAMMER.get();
    }

    @Override
    public int getDamage(ItemStack stack) {
        return !stack.hasTag() ? getMaxDamage(stack) : stack.getOrCreateTag().getInt("Damage");
    }

    @Nonnull
    @Override
    public ItemStack getContainerItem(@Nonnull ItemStack stack) {
    	ItemStack container = stack.copy();
		if(container.attemptDamageItem(1, RAND, null)) {
			return ItemStack.EMPTY;
		} else {
			return container;
		}
    }
    
    @Override
	public boolean isEnchantable(@Nonnull ItemStack stack) {
		return true;
	}

    @Override
    public int getItemEnchantability() {
        return 14;
    }

    @Override
    public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
        return enchantment == Enchantments.UNBREAKING || enchantment == Enchantments.MENDING;
    }
}

 

And here's my recipe bit

Item PLATE = ForgeRegistries.ITEMS.getValue(new ResourceLocation(MorePlates.MODID, material.toString() + "_plate"));
Ingredient INGOT = Ingredient.fromTag(ItemTags.createOptional(material.getTag()));

ConditionalRecipe.builder()                  
.addCondition(        	
and(
    new BooleanCondition(() -> Config.GENERAL.PLATE_RECIPES.get(), BooleanCondition.Type.ENABLE_PLATE.get()),
    itemExists(MorePlates.MODID, material.toString() + "_plate")
   )
)
.addRecipe(
     ShapedRecipeBuilder.shapedRecipe(PLATE)
                        .patternLine("H")
                        .patternLine("I")
                        .patternLine("I")
                        .key('H', ForgeRegistries.ITEMS.getValue(new ResourceLocation(MorePlates.MODID, "hammer")))
                        .key('I', INGOT)
                        .setGroup("")
        	            .addCriterion("has_item", hasItem(ForgeRegistries.ITEMS.getValue(new ResourceLocation(MorePlates.MODID, "hammer"))))
                        ::build
)
.build(consumer, new ResourceLocation(MorePlates.MODID, material.toString() + "_plate"));

Thanks in regards!

Clever way of damaging the item. However, you should not call Item#attemptDamageItem. Just call ItemStack#damageItem and then return the item after that, no checks required. Also, I do not believe the Consumer can be null, that should just point to an empty Consumer.

  • Author

So from my understanding is that attempDamageItem is deprecated, and it should be moreover like this?

ItemStack container = stack.copy();
container.damageItem() //didnt check the pars yet
return container;

Also thanks for the Consumer bit

 

By the way, I am pretty sure this is also a problem.. (from my original post in the ShapedRecipeBuilder text)

.key('H', ForgeRegistries.ITEMS.getValue(new ResourceLocation(MorePlates.MODID, "hammer")))

I should be damaging the Item here, but how do I exactly make it do that? It cannot accept ItemStacks

Edited by MostafaSabry55

45 minutes ago, MostafaSabry55 said:

So from my understanding is that attempDamageItem is deprecated, and it should be moreover like this?

Not deprecated iirc, but it's used within damageItem which already handles everything

45 minutes ago, MostafaSabry55 said:

By the way, I am pretty sure this is also a problem.. (from my original post in the ShapedRecipeBuilder text)

Wouldn't matter, item damage should be handled on the container item itself just like you have done. So, where you are doing it is where it should be done if I'm not mistaken.

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.