Jump to content

Recommended Posts

Posted

Im trying to make a vanilla cow drop a new item.

 

ModLivingDropsEvent:

package dudesmods.lozmod;

import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.item.Item;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraft.entity.EntityLiving;

public class ModLivingDropsEvent {

          public static double rand;

          @ForgeSubscribe
          public void onEntityDrop(ModLivingDropsEvent event) {
        	  if(event.entityLiving instanceof EntityCow) {
        		  event.entityLiving.dropItem(LOZmod.greenTannedLeather.itemID);
        	  }
          }
                  
}

 

it gives me a red underline on both of the "entityLiving" parts saying it cannot be resolved or is not a field.

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Posted

It should be like this:

 

   
@ForgeSubscribe
     public void onEntityDrop(LivingDropsEvent event) {

              if (event.entityLiving instanceof EntityCow) {
                 //The integer at the end relates to how many potato will be dropped.
                  event.entityLiving.dropItem(LOZmod.greenTannedLeather.itemID, 1);
              }
       }
}

 

From: http://darkhaxspace.weebly.com/living-drops.html

 

Took me 5 seconds googling.

Posted

I'd just like to point out that there is no way in hell you should have thought that your code would work:

 

public void onEntityDrop(ModLivingDropsEvent event) {

 

So this function takes a parameter of...your class.  No red flags yet.  Weird, but not--technically--incorrect.

 

event.entityLiving

 

Uh.  Your class doesn't have that property.  It only has

 

public static double rand;

 

Because ModLivingDropsEvent doesn't extend or implement any classes.

 

So either:

a) You gave 'event' the wrong type (as the above posters have pointed out, it should be LivingDropsEvent)

b) You didn't properly extend a base class (e.g. ModLivingDropsEvent extends LivingDropsEvent, which in this case is unnecessary).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I'd just like to point out that there is no way in hell you should have thought that your code would work:

 

public void onEntityDrop(ModLivingDropsEvent event) {

 

So this function takes a parameter of...your class.  No red flags yet.  Weird, but not--technically--incorrect.

 

event.entityLiving

 

Uh.  Your class doesn't have that property.  It only has

 

public static double rand;

 

Because ModLivingDropsEvent doesn't extend or implement any classes.

 

So either:

a) You gave 'event' the wrong type (as the above posters have pointed out, it should be LivingDropsEvent)

b) You didn't properly extend a base class (e.g. ModLivingDropsEvent extends LivingDropsEvent, which in this case is unnecessary).

 

b doesn't work since Forge makes an instance of the Event class everytime the event is fired. An unregistered subclass would crash / simply not work if you try to register it and 1) don't put it into the net.minecraftforge(.client).event package 2) don't fire it manually with an instance of your subclass

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

OK. Eclipse messed with my stuff for some reason. fixed now.

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

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.