Started by
ButterKing-28
on
Topic category: Help with Minecraft modding (Java Edition)
Hello!
I am trying to make an item that does not have a decrement when it is eaten and stays in your inventory (so it does not have any decrement). I tried to make a custom item, and it doesn't let you eat it because I think the way I did it just makes it un-edible because It sets the decrement to 0 when it is right-clicked.
Can someone help me figure out how to do it?
Thank you so much!
ButterKing-28
I'm not sure to understand correctly : You want that for example if you have 64 food in you hand and you eat one, you have still 64 at the end ?
In this case, can't you create a procedure that say something like "when food is eaten, add 1 food to player inventory" ?
To avoid problems like your food appear in an other slot, you can create a variable that register the number of items in the main hand when start eating, and when eaten, set the items of the main hand to the variable.
Hi! so I solved this and I forgot what I did but it worked so I transferred it to my IDE for my non-MCreator mod Here is the fabric code:
public class InfinitBakedPotato extends Item {
public InfinitBakedPotato() {
super(new FabricItemSettings().maxCount(1).rarity(Rarity.EPIC).food(ModFoodComponents.INFINIT_BAKED_POTATO_FOOD));
}
@Override
public boolean hasGlint(ItemStack stack) {
return true;
}
@Override
public ItemStack finishUsing(ItemStack itemstack, World world, LivingEntity entity) {
ItemStack retval = new ItemStack(ModItems.INFINIT_BAKED_POTATO);
super.finishUsing(itemstack, world, entity);
if (itemstack.isEmpty()) {
return retval;
} else {
if (entity instanceof PlayerEntity player && !player.getAbilities().creativeMode) {
if (!player.getInventory().insertStack(retval))
player.dropItem(retval, false);
}
return itemstack;
}
}
}