Posted October 25, 20204 yr 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!
October 25, 20204 yr 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.
October 25, 20204 yr 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 October 25, 20204 yr by MostafaSabry55
October 25, 20204 yr 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.