Posted January 3, 20214 yr How to prevent an item from being wasted during crafting? Something like crafting a cake. I know that a bucket of milk is prescribed, that they do not waste when crafting. But I can't do this so that the item is not spent during crafting. Ideally, make it so that with each craft -1 durability. I started digging towards ActionResult <ItemCraftedEvent> but to no avail so far. Help me please translated by Google Translate))
January 3, 20214 yr Author 4 minutes ago, diesieben07 said: Override getContainerItem in your item class and return the item that should be left behind. Is it possible in more detail?😅 Just starting to learn modding for mc
January 4, 20214 yr 1 hour ago, arturkr said: Is it possible in more detail?😅 Just starting to learn modding for mc If it's a custom Item that you're implementing you'll need to create a class for it, and override the hasContainerItem and getContainerItem methods, in the getContainerItem you can return the item you want to appear in the crafting slot once the recipe is crafted, in this case you'd want to return the itemStack and damage by one point if it's a vanilla Item you want that behaviour for... I don't know how to help you
January 4, 20214 yr Author 10 hours ago, kiou.23 said: If it's a custom Item that you're implementing you'll need to create a class for it, and override the hasContainerItem and getContainerItem methods, in the getContainerItem you can return the item you want to appear in the crafting slot once the recipe is crafted, in this case you'd want to return the itemStack and damage by one point if it's a vanilla Item you want that behaviour for... I don't know how to help you Yes, this is for a custom item. But I don't know how to override yet ... My ItemInit.java public class ItemInit { public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Main.MOD_ID); public static final RegistryObject<Item> pounder = ITEMS.register("pounder", () -> new Item(new Item.Properties().group(ItemGroup.TOOLS).maxStackSize(1).setNoRepair().maxDamage(63))); } My Main.java public class Main { public static Random random = new Random(); public static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "magic"; public Main() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); ItemInit.ITEMS.register(bus); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { } } Can you tell me where to override?😅
January 4, 20214 yr Author 3 minutes ago, diesieben07 said: You need a class that extends Item. public class ItemInit extends Item{ public ItemInit(Properties properties) { super(properties); } public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Main.MOD_ID); public static final RegistryObject<Item> pounder = ItemInit.ITEMS.register("pounder", () -> new Item(new Item.Properties().group(ItemGroup.TOOLS).maxStackSize(1).setNoRepair().maxDamage(63))); @Override public ItemStack getContainerItem(ItemStack stack) { ItemStack ret = stack.copy(); if(ret.attemptDamageItem(1, Main.random, null)) return ItemStack.EMPTY; else return ret; } } But when crafting, the item is still spent
January 4, 20214 yr 27 minutes ago, arturkr said: But when crafting, the item is still spent Make a seperate class that extends Item, e.g. MyItem and then use that when registering your item instead of using the Item class: public static final RegistryObject<Item> pounder = ItemInit.ITEMS.register("pounder", () -> new MyItem(new Item.Properties().group(ItemGroup.TOOLS).maxStackSize(1).setNoRepair().maxDamage(63)));
January 4, 20214 yr Author 28 minutes ago, diesieben07 said: Why did you make ItemInit extend Item? Apart from the fact that this makes no sense - you never register any instances of this new item class. register in Main public class Main { public static Random random = new Random(); public static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "magic"; public Main() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); ItemInit.ITEMS.register(bus); Pounder.ITEMS.register(bus); BlockInit.BLOCKS.register(bus); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { } } 8 minutes ago, justAm0dd3r said: Make a seperate class that extends Item, e.g. MyItem and then use that when registering your item instead of using the Item class: public static final RegistryObject<Item> pounder = ItemInit.ITEMS.register("pounder", () -> new MyItem(new Item.Properties().group(ItemGroup.TOOLS).maxStackSize(1).setNoRepair().maxDamage(63))); I didn't succeed, as you suggested. The instrument was not registered. I did it differently and it appeared in the game, but it still disappears when crafting public class Pounder extends Item{ public Pounder(Properties properties) { super(properties); } public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Main.MOD_ID); public static final RegistryObject<Item> pounder = Pounder.ITEMS.register("pounder", () -> new Item(new Item.Properties().group(ItemGroup.TOOLS).maxStackSize(1).setNoRepair().maxDamage(63))); @Override public ItemStack getContainerItem(ItemStack stack) { ItemStack ret = stack.copy(); if(ret.attemptDamageItem(1, Main.random, null)) return ItemStack.EMPTY; else return ret; } }
January 4, 20214 yr Author 1 minute ago, diesieben07 said: You still never register an instance of the Pounder item class. Please learn basic Java before modding. Nope) I want to learn java while studying modding)
January 4, 20214 yr Author 2 minutes ago, diesieben07 said: You clearly do not know enough about Java to start modding. Basic Java knowledge (what are classes, how to override methods) is required. It's true. I know C ++ well and I thought that there was not much difference there ... But Java is just a different world) But still, can you help with the code?
January 4, 20214 yr Author 3 minutes ago, diesieben07 said: You need to make a class that extends Item. You need to override getContainerItem and hasContainerItem. You then need to actually use this class. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA. You understand that I am stupid and do not know Java. Could you write for me where to click and where to write?)
January 4, 20214 yr Author 46 minutes ago, diesieben07 said: No. Ha-ha ItemInit.java public class ItemInit{ public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Main.MOD_ID); public static final RegistryObject<Item> pounder = ItemInit.ITEMS.register("pounder", () -> new Pounder(new Item.Properties().group(ItemGroup.TOOLS).maxStackSize(1).setNoRepair().maxDamage(63))); } Pounder.java public class Pounder extends Item{ public Pounder(Properties properties) { super(properties); } @Override public boolean hasContainerItem(ItemStack stack) { return true; } @Override public ItemStack getContainerItem(ItemStack stack) { ItemStack ret = stack.copy(); if(ret.attemptDamageItem(1, Main.random, null)) return ItemStack.EMPTY; else return ret; } } Main.java public class Main { public static Random random = new Random(); public static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "magic"; public Main() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); ItemInit.ITEMS.register(bus); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { } } ITS WORK and in recipes need add for item "data": 32767. Yeeeey
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.