Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I can't get sheep to drop my custom item.  I've looked at multiple tutorials on doing this, but I still can't get it to work.  I keep getting an error that says "RawLambChop cannot be resolved or is not a field."  You can see where exactly I get this error below in the "Event Handler" spoiler.  Any help would be much appreciated.

 

My Code:

 

Base Class

 

package com.masterkulon.betterfood;

import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;

import com.masterkulon.betterfood.help.Reference;
import com.masterkulon.betterfood.help.RegisterHelper;
import com.masterkulon.betterfood.items.ItemFoodCookedLambChop;
import com.masterkulon.betterfood.items.ItemFoodRawLambChop;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;

@Mod(modid = Reference.MODID, version = Reference.VERSION)
public class BetterFood {
public static ItemFood RawLambChop;
public static ItemFood CookedLambChop;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	RawLambChop = new ItemFoodRawLambChop();
	RegisterHelper.registerItem(RawLambChop); //RegisterHelper simply registers the items

	CookedLambChop = new ItemFoodCookedLambChop();
	RegisterHelper.registerItem(CookedLambChop);

	GameRegistry.addSmelting(RawLambChop, new ItemStack(CookedLambChop), 0.35F);
}

@EventHandler
public void Init(FMLInitializationEvent event) {
	MinecraftForge.EVENT_BUS.register(new BetterFoodEventHandler());
}
}

 

 

Event Handler:

 

package com.masterkulon.betterfood;

import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.item.Item;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class BetterFoodEventHandler {
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(LivingDropsEvent event) {
	if(event.entity instanceof EntitySheep) {
		event.entityLiving.dropItem(Item.RawLambChop.shiftedIndex, 1); //I get the error on "RawLambChop" here
	}
}
}

 

 

Class for Raw Lamb Chop item:

 

package com.masterkulon.betterfood.items;

import com.masterkulon.betterfood.help.Reference;

import net.minecraft.item.ItemFood;

public class ItemFoodRawLambChop extends ItemFood {
public ItemFoodRawLambChop() {
	super(3, 0.3F, true);
	setUnlocalizedName("rawLambChop");
	setTextureName(Reference.MODID + ":" + getUnlocalizedName().substring(5));
}
}

 

Hi.  It looks like you might have been following my tutorial since my example there is sheep and uses similar coding style...

 

Anyway, you can't use Item.RawLambChop because RawLambChop is not a field or method for the Item class.

 

Instead I think you should have BetterFood.RawLambChop because you instantiated the raw lamb chop in your base class.

 

Note that you should use Java naming convention and the field should be rawLambChop (lowercase initial "r").

 

Does that help?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

  • Author

It worked.  Thank you very much!

 

P.S. My coding style is actually derived from many different tutorials, but I may have seen yours among them all.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.