Jump to content

Recommended Posts

Posted

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))

Posted
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

Posted
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

Posted
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?😅

Posted
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

 

Posted
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)));

 

Posted
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;
      
    }
}

 

Posted
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)

Posted
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?

Posted
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?)

Posted
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

238101931_.png.5062aeb3d7010eedc08455b25ce0fb28.png

 

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.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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