Jump to content

[Reopened] Overriding mob drops


darthvader45

Recommended Posts

I'm working for a team creating the Realistic Animal Products and Drops Mod (link: http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/wip-mods/2389704-realistic-animal-products-and-drops-mod)

 

One item is hide, which has different colors depending on the animal it drops from (pig, sheep, cow, horse, donkey, or mule), and another is pelt, which drops from ocelots, cats, and wolves.  How do I access the different mobs to determine the type of hide dropped?

 

 

Edit: Solved by searching the net for adding Wither skelly drops.  Turns out the solution shown there works for EntityHorse as well.  I definitely learned something new today.  Note to self: Find a similar problem and see if solution works with current issue.

Link to comment
Share on other sites

How would this deal with mobs that use multiple variations, such as horses, which have the variations donkey and mule(both stuck in the EntityHorse class as values of the variable i)?

You have to check for it. If you want to e.g. only drop things for mules, check first that the entity in the event is a horse and then check that it is also a mule.

Edit: Excuse me, Jabelar, you still there?

This is a forum, not a chat room.

 

I cannot seem to get the type of horse needed.  How would I call the variable that determines if the horse is a regular horse, a mule, or a donkey?

Link to comment
Share on other sites

also: How do people (you are not the only one) fail to perform these absolute basic steps all the f***ing time? I don't get it.

 

I don't know, I just don't know. ..

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.

Link to comment
Share on other sites

Ok, so. Let me teach you how to do absolute basic research in code.

We want to know something about horses. So, naturally, we start looking in the

EntityHorse

class. How do you find it? Use the "Go to class" action in your IDE (Ctrl-Shift-T in eclipse, Ctrl-N in IntelliJ).

Now that we have that open, let's check the outline (eclipse) or structure (IntelliJ) of the class (same thing). The fields don't really provide anything useful, so let's look at the methods, maybe there is a getter. And, who would have thought, there it is:

public int getHorseType

. Complete with JavaDocs explaining the return type.

 

What more do you want? :o And also: How do people (you are not the only one) fail to perform these absolute basic steps all the f***ing time? I don't get it.

 

Ok, ok, no need to get all wound up.  I only needed confirmation.  I'm only using this variable as a separate condition in an if statement.  For this to work, the left hand side must be a variable, therefore the getter will not work.

 

My code:

package net.sargeant.rapad.eventhandler;
import java.util.Random;

import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.sargeant.rapad.items.ModItems;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class HorseDropEvent 
{
public static Random random;
public static int dropped;

@SubscribeEvent
public void onEntityDrop(LivingDropsEvent event)
{
random = new Random();
dropped = random.nextInt(2) + 1; //DO NOT CHANGE THIS

if(event.entityLiving instanceof EntityHorse )
{
	if (EntityHorse#getHorseType() = 1){

	}
}
}
}

Link to comment
Share on other sites

Okay, so I type EntityHorse in, plus a period.  I don't see anything in the autocomplete even mentioning said variable of getHorseType().  I'd have to type in "this" to get anywhere, and even then it says "cannot convert from int to boolean".  I then try putting  =  1 at the end, and the error changes to "the left-hand side of an assignment must be a variable".

 

Edit:  Found my answer in a separate topic talking about adding drops after detecting Skeleton type.  Tried it with horses, and it worked.  Gonna remember this from now on.

Link to comment
Share on other sites

Okay, so I type EntityHorse in, plus a period.  I don't see anything in the autocomplete even mentioning said variable of getHorseType().  I'd have to type in "this" to get anywhere, and even then it says "cannot convert from int to boolean".  I then try putting  =  1 at the end, and the error changes to "the left-hand side of an assignment must be a variable".

EntityHorse#getHorseType() is not valid Java code (which you should know, since you know Java, right? Right?)

Apparently not...  :o

 

OP, the drop Event has the entity instance in it already. You cannot literally type 'EntityHorse.' and expect magic to happen - as diesieben said, it is NOT a static method.

 

Get the entity from the event, check if that entity is an instanceof EntityHorse, and then cast the entity to EntityHorse to access the method. If you don't know what any of those terms mean, Google them.

Link to comment
Share on other sites

Jesus Christ...

 

((EntityHorse)event.entityLiving).getHorseType() strike any bells?

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.

Link to comment
Share on other sites

Jesus Christ...

 

((EntityHorse)event.entityLiving).getHorseType() strike any bells?

 

I used to think to myself, man, these Forge guys on the forums are a bunch of a-holes to people trying to learn...

 

But then I saw this post...I apologize for my previous assumptions.

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Link to comment
Share on other sites

I used to think to myself, man, these Forge guys on the forums are a bunch of a-holes to people trying to learn...

 

We're not assholes, people are just stupid and claim to have programming knowledge they do not have.

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.

Link to comment
Share on other sites

Okay, some of the drops work, yet some lead to crashes; horse, ocelot and skeleton drops being the three that broke as I have found.

 

My current CustomDropEvents code:

package net.sargeant.rapad.eventhandler;

import java.util.Random;

import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.monster.EntityCaveSpider;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySnowman;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityBat;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntitySquid;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.sargeant.rapad.items.ModItems;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class CustomDropEvent 
{
public static Random random;
public static int dropped;
public EntitySkeleton skeleton;
public EntityHorse horse;
public EntityOcelot cat;

@SubscribeEvent
public void onEntityDrop(LivingDropsEvent event)
{
random = new Random();
dropped = random.nextInt(2) + 1; //DO NOT CHANGE THIS

if(event.entityLiving instanceof EntityHorse)
{
event.entityLiving.entityDropItem(new ItemStack(ModItems.horsemeatraw), dropped);
 if(horse.getHorseType() == 0)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.horsehide), dropped);

}
else if(horse.getHorseType() == 1)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.donkeyhide), dropped);
}
else if(horse.getHorseType() == 2)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.mulehide), dropped);
}
if (event.entityLiving.isBurning())
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.horsemeatcooked), dropped);
}
}
else if(event.entityLiving instanceof EntityWolf)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.wolfmeatraw), dropped);
	if (event.entityLiving.isBurning())
	{
		event.entityLiving.entityDropItem(new ItemStack(ModItems.wolfmeatcooked), dropped);
	}
}
else if(event.entityLiving instanceof EntityOcelot)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.catmeatraw), dropped);
	if (cat.isTamed() == false){
	event.entityLiving.entityDropItem(new ItemStack(ModItems.ocelotpelt), dropped);
	}
	else if(cat.isTamed() == true){
		event.entityLiving.entityDropItem(new ItemStack(ModItems.catpelt), dropped);
	}
	}
	if (event.entityLiving.isBurning())
	{
		event.entityLiving.entityDropItem(new ItemStack(ModItems.catmeatcooked), dropped);
	}
else if(event.entityLiving instanceof EntitySpider)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.venomsac), dropped);
}
else if(event.entityLiving instanceof EntitySquid)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.squidraw), dropped);

}
else if(event.entityLiving instanceof EntityBat)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.batraw), dropped);
	if (event.entityLiving.isBurning())
	{
		event.entityLiving.entityDropItem(new ItemStack(ModItems.batcooked), dropped);
	}


}
else if(event.entityLiving instanceof EntityPig)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.animalfat), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.bone), dropped);	
}
else if(event.entityLiving instanceof EntitySheep)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.animalfat), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.bone), dropped);
	event.entityLiving.entityDropItem(new ItemStack(ModItems.muttonraw), dropped);
	if (event.entity.isBurning())
	{
		event.entityLiving.entityDropItem(new ItemStack(ModItems.muttoncooked), dropped);
	}
}
else if(event.entityLiving instanceof EntityCow)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.animalfat), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.bone), dropped);		
}
else if(event.entityLiving instanceof EntityVillager)
{
	event.entityLiving.entityDropItem(new ItemStack(Items.emerald), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.bread), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.apple), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.cooked_porkchop), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.wheat), dropped);	
	event.entityLiving.entityDropItem(new ItemStack(Items.wheat_seeds), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.potato), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.carrot), dropped);	
}
else if(event.entityLiving instanceof EntityIronGolem)
{
	event.entityLiving.entityDropItem(new ItemStack(Blocks.iron_block), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.iron_ingot), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Blocks.vine), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Blocks.red_flower), dropped);

}
else if(event.entityLiving instanceof EntitySnowman)
{
	event.entityLiving.entityDropItem(new ItemStack(Blocks.pumpkin), dropped);
	event.entityLiving.entityDropItem(new ItemStack(Items.snowball), dropped);		
}
else if(event.entityLiving instanceof EntityZombie)
{
	event.entityLiving.entityDropItem(new ItemStack(Items.bone), dropped);		
}
else if(event.entityLiving instanceof EntitySpider | event.entityLiving instanceof EntityCaveSpider)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.venomsac), dropped);		
}
else if(event.entityLiving instanceof EntityWither)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.witherbone), dropped);		
}

else if(event.entityLiving instanceof EntityPigZombie)
{
	event.entityLiving.entityDropItem(new ItemStack(ModItems.animalfat), dropped);
	event.entityLiving.entityDropItem(new ItemStack(ModItems.pighide), dropped);
}
else if(event.entityLiving instanceof EntityEnderman)
{
	event.entityLiving.entityDropItem(new ItemStack(Items.bone), dropped);

}

else if(event.entityLiving instanceof EntitySkeleton && skeleton.getSkeletonType() == 1)
{
	if (skeleton.getSkeletonType() == 1){
	event.entityLiving.entityDropItem(new ItemStack(ModItems.witherbone), dropped);	
	}
	else if (skeleton.getSkeletonType() != 1)
	{
		event.entityLiving.entityDropItem(new ItemStack(Items.bone), dropped);
		event.entityLiving.entityDropItem(new ItemStack(Items.arrow), dropped);
	}

}

}




}

 

 

 

Edit: Nvm, Draco's code worked.  I was so stupid, checking a separate entity instead of casting.  Sorry for being a total idiot.  I'm kinda new to modifying vanilla mob drops(but NOT to coding).  I do occasionally make a few noobish mistakes, but that happens to even the most experienced coders.

Link to comment
Share on other sites

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

    • Try deliting feur builder  It caused this issue in my modpack
    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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