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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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