Jump to content

Recommended Posts

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

 

Posted

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/

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.