Jump to content

[1.12.2] extended class of FoodBase.java doesn't work


Mango106

Recommended Posts

I made a bowl food item called fruit_salad, but when eat it, it doesn't restore any hunger or saturation.

 

I have a class that i created to add food items to my mod called FoodBase.java (code for that file below)

 

package com.citrine.testmod.items.food;

import com.citrine.testmod.Main;
import com.citrine.testmod.init.ModItems;
import com.citrine.testmod.util.IHasModel;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemFood;

public class FoodBase extends ItemFood implements IHasModel
{
	public FoodBase(String name, int amount, float saturation, boolean isAnimalFood) 
	/*
	 * amount is shanks filled
	 * saturation is saturation
	 * isAnimalFood determines whether or not you can feed it to dogs
	 * */
	{
		super(amount, saturation, isAnimalFood);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(CreativeTabs.FOOD);
		
		ModItems.ITEMS.add(this);
	}

	@Override
	public void registerModels() 
	{
		Main.proxy.registerItemRenderer(this, 0, "inventory");
	}
}

 

I use this class for adding normal food in my ModItems.java class in the init package. I wanted to add bowl items, that can only stack to one, and return a bowl to the player's inventory when eaten, so i made a new class that extends FoodBase called SoupBase.java (code below)

 

package com.citrine.testmod.items.food;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.items.ItemHandlerHelper;

public class SoupBase extends FoodBase
{
	private Item ReturnStack;
	
	public SoupBase(String name, int amount, float saturation, boolean isAnimalFood, Item item) 
	{
		super(name, amount, saturation, isAnimalFood);
		this.setMaxStackSize(1);
		this.ReturnStack = item;
	}
	
	public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase living) 
	{
		super.onFoodEaten(stack, world, (EntityPlayer)living);
		return new ItemStack(ReturnStack);
	}
}

 

Now that i did that, i added a new SoupBase item called fruit_salad in ModItems.java

 

public static final Item FRUIT_SALAD = new SoupBase("fruit_salad", 11, 6.6f, false, Items.BOWL);

 

Heres the full ModItems.java class:

 

package com.citrine.testmod.init;

import java.util.ArrayList;
import java.util.List;

import com.citrine.testmod.items.ItemBase;
import com.citrine.testmod.items.armor.ArmorBase;
import com.citrine.testmod.items.food.FoodBase;
import com.citrine.testmod.items.food.FoodEffectBase;
import com.citrine.testmod.items.food.SoupBase;
import com.citrine.testmod.items.tools.ToolAxe;
import com.citrine.testmod.items.tools.ToolHoe;
import com.citrine.testmod.items.tools.ToolPickaxe;
import com.citrine.testmod.items.tools.ToolSpade;
import com.citrine.testmod.items.tools.ToolSword;
import com.citrine.testmod.util.Reference;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.common.util.EnumHelper;

public class ModItems 
{
	
	public static final List<Item> ITEMS = new ArrayList<Item>();
	
	//Materials
	public static final ToolMaterial MATERIAL_AQUAMARINE = EnumHelper.addToolMaterial("material_aquamarine", 3, 2124, 9.0f, 4.0f, 25);
	public static final ArmorMaterial ARMOR_MATERIAL_SUGILITE = EnumHelper.addArmorMaterial("armo r_material_sugilite", Reference.MOD_ID + ":sugilite", 15, new int[] {3, 7, 9, 4} , 10, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 0.0f);
	
	//add items
	public static final Item SUGILITE = new ItemBase("sugilite");
	public static final Item URANIUM = new ItemBase("uranium");
	public static final Item URANIUM_SUGILITE_FUSION = new ItemBase("uranium_sugilite_fusion");
	public static final Item AQUAMARINE = new ItemBase("aquamarine");
	
	//food
	//public static final Item BLUEBERRY = new FoodBase("blueberry", 3, 4.0f, false); (60*20 is one minute of ppotion effect)
	public static final Item BLUEBERRY = new FoodEffectBase ("blueberry", 3, 2.0f, false, new PotionEffect(MobEffects.SPEED, /*how long its lasts(3 seconds)*/(3*20),/*potion effect lvl*/ 2, /*whether or not it comes from a beacon*/false, /*shows whether or not particles are shown*/false));
	public static final Item POO = new FoodEffectBase ("poo", 3, 0.0f, false, new PotionEffect(MobEffects.HUNGER, (12*20), 100, false, true));
	public static final Item FISH_AND_CHIPS = new FoodBase("fish_and_chips", 10, 12.8f, false);
	public static final Item FRIED_EGG = new FoodBase("fried_egg", 5, 6, false);
	//public static final Item FRUIT_SALAD = new SoupBase("fruit_salad", 11, 6.6f, false), onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player);
	public static final Item FRUIT_SALAD = new SoupBase("fruit_salad", 11, 6.6f, false, Items.BOWL);
	
	//Tools
	public static final ItemSword AQUAMARINE_SWORD = new ToolSword("aquamarine_sword", MATERIAL_AQUAMARINE);
	public static final ItemSpade AQUAMARINE_SHOVEL = new ToolSpade("aquamarine_shovel", MATERIAL_AQUAMARINE);
	public static final ItemPickaxe AQUAMARINE_PICKAXE = new ToolPickaxe("aquamarine_pickaxe", MATERIAL_AQUAMARINE);
	public static final ItemAxe AQUAMARINE_AXE = new ToolAxe("aquamarine_axe", MATERIAL_AQUAMARINE);
	public static final ItemHoe AQUAMARINE_HOE = new ToolHoe("aquamarine_hoe", MATERIAL_AQUAMARINE);
	
	//armor
	public static final Item SUGILITE_HELMET = new ArmorBase("sugilite_helmet", ARMOR_MATERIAL_SUGILITE, 1, EntityEquipmentSlot.HEAD);
	public static final Item SUGILITE_CHESTPLATE = new ArmorBase("sugilite_chestplate", ARMOR_MATERIAL_SUGILITE, 1, EntityEquipmentSlot.CHEST);
	public static final Item SUGILITE_LEGGINGS = new ArmorBase("sugilite_leggings", ARMOR_MATERIAL_SUGILITE, 2, EntityEquipmentSlot.LEGS);
	public static final Item SUGILITE_BOOTS = new ArmorBase("sugilite_boots", ARMOR_MATERIAL_SUGILITE, 1, EntityEquipmentSlot.FEET);
}

 

When I run client and test out the mod, I can eat the fruit salad, it stacks to 1 like i wanted, and it returns a bowl when its eaten. The only problem is that no hunger or saturation is restored when i eat it, for some reason. I'm quite sure what i did wrong, but I think it has something to do with SoupBase.java, as I don't have this problem with the normal class that it extends from.

Does anyone know how to fix this?

Edited by Mango106
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am trying to override or disable some vanilla recipes, as part of my mod. All of the methods that I have seen online, so far, do not work. So far, I have tried: Creating a JSON file in the "data/minecraft/recipes" folder, that has air as the ingredient and a barrier as the result This only works for crafting table recipes adding a smelting recipe this way works as intended Editing the ordering to AFTER in the forge dependency inside the "mods.toml" file Found an older post about using the FurnaceRecipe class, that no longer exists From: here So, what is required to disable a vanilla smelting recipe? I know some may say to not do this, but part of the progression of my mod kind of requires disabling some of the furnace recipes. Also, it seems that smelting recipes don't technically have to have the same filename as the block used, r as the result. When overriding crafting recipes, just adding the edited/removed recipe file in the minecraft data folder, under the same name as the original recipe.  Edit: the crafting recipes seem to be cached between worlds? I created a new world and the edited crafting recipes works, but it doesn't work in an already made world?
    • Using a modified version of "Fabulously Optimized" installed a few more mods and now my Hot Bar is invisible... Latest log : https://paste.ee/p/72TSs (No DeBug log txt file.)
    • I know that with this you can return the game folder   FMLPaths.GAMEDIR.get() I want the player to be created in the world where a txt file was created in the folder of the same world. How can I return the path of the world folder that the player is in?
    • [09Jun2023 15:38:56.969] [main/ERROR] [mixin/]: Mixin config dynamiclightsreforged.mixins.json does not specify "minVersion" property [09Jun2023 15:38:57.512] [main/ERROR] [mixin/]: Mixin config itshallnottick.mixins.json does not specify "minVersion" property how do i fix those 2
    • Whoops sorry uploaded wrong logs, here are the correct ones: 09:28:31.876 at java.base/java.lang.Thread.run(Thread.java:833) 09:28:31.876 Caused by: java.lang.UnsupportedOperationException: A mod tried to access the state neighbor table directly. Please report this at https://github.com/malte0811/FerriteCore/issues. As a temporary workaround you can enable "populateNeighborTable" in the FerriteCore config 09:28:31.876 at TRANSFORMER/ferritecore@4.2.2/malte0811.ferritecore.fastmap.table.CrashNeighborTable.crashOnAccess(CrashNeighborTable.java:101) 09:28:31.876 at TRANSFORMER/ferritecore@4.2.2/malte0811.ferritecore.fastmap.table.CrashNeighborTable.rowKeySet(CrashNeighborTable.java:77) 09:28:31.876 at TRANSFORMER/canary@0.2.1/com.abdelaziz.canary.common.state.FastImmutableTable.<init>(FastImmutableTable.java:36) 09:28:31.876 at TRANSFORMER/minecraft@1.18.2/net.minecraft.world.level.block.state.StateHolder.handler$bbj000$postCreateWithTable(StateHolder.java:531) 09:28:31.876 at TRANSFORMER/minecraft@1.18.2/net.minecraft.world.level.block.state.StateHolder.m_61133_(StateHolder.java:1052) 09:28:31.876 at TRANSFORMER/minecraft@1.18.2/net.minecraft.world.level.block.state.StateDefinition.<init>(StateDefinition.java:68) 09:28:31.876 at TRANSFORMER/minecraft@1.18.2/net.minecraft.world.level.block.state.StateDefinition$Builder.m_61101_(StateDefinition.java:157) 09:28:31.877 at TRANSFORMER/minecraft@1.18.2/net.minecraft.world.level.block.Block.<init>(Block.java:174) 09:28:31.877 at TRANSFORMER/minecraft@1.18.2/net.minecraft.world.level.block.AirBlock.<init>(AirBlock.java:12) 09:28:31.877 at TRANSFORMER/minecraft@1.18.2/net.minecraft.world.level.block.Blocks.<clinit>(Blocks.java:40) 09:28:31.877 ... 18 more 09:28:32.435 Process crashed with exit code 1
  • Topics

×
×
  • Create New...

Important Information

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