kitsushadow Posted September 25, 2014 Posted September 25, 2014 I'm trying to Overwrite the vanilla cow class with my own cow class. Im attempting to make the cow drop an item similar to how a chicken does. I believe my custom cow class is fine but that Im registering my cowclass incorrectly or that im not disabling the spawn correctly. Please look at my Main and Cow classes and let me know if something is amiss. Thanks in Advance (Also Spoilers dont seem to be working at the time i was writing this post) MedievalCow.class package com.kitsu.medievalcraft.entity; import com.kitsu.medievalcraft.item.ModItems; import net.minecraft.block.Block; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIFollowParent; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMate; import net.minecraft.entity.ai.EntityAIPanic; import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAITempt; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.passive.EntityCow; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class MedievalCow extends EntityCow { public float field_70886_e; public float destPos; public float field_70884_g; public float field_70888_h; public float field_70889_i = 1.0F; /** The time until the next egg is spawned. */ public int timeUntilNextEgg; public boolean field_152118_bv; private static final String __OBFID = "CL_00001639"; public MedievalCow(World p_i1683_1_) { super(p_i1683_1_); this.setSize(0.9F, 1.3F); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIPanic(this, 2.0D)); this.tasks.addTask(2, new EntityAIMate(this, 1.0D)); this.tasks.addTask(3, new EntityAITempt(this, 1.25D, Items.wheat, false)); this.tasks.addTask(4, new EntityAIFollowParent(this, 1.25D)); this.tasks.addTask(5, new EntityAIWander(this, 1.0D)); this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); this.tasks.addTask(7, new EntityAILookIdle(this)); this.timeUntilNextEgg = this.rand.nextInt(10) + 10; } /** * Returns true if the newer Entity AI code should be run */ public boolean isAIEnabled() { return true; } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.20000000298023224D); } /** * Returns the sound this mob makes while it's alive. */ protected String getLivingSound() { return "mob.cow.say"; } /** * Returns the sound this mob makes when it is hurt. */ protected String getHurtSound() { return "mob.cow.hurt"; } /** * Returns the sound this mob makes on death. */ protected String getDeathSound() { return "mob.cow.hurt"; } protected void func_145780_a(int p_145780_1_, int p_145780_2_, int p_145780_3_, Block p_145780_4_) { this.playSound("mob.cow.step", 0.15F, 1.0F); } /** * Returns the volume for the sounds this mob makes. */ protected float getSoundVolume() { return 0.4F; } protected Item getDropItem() { return Items.leather; } /** * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param * par2 - Level of Looting used to kill this mob. */ public void onLivingUpdate() { super.onLivingUpdate(); this.field_70888_h = this.field_70886_e; this.field_70884_g = this.destPos; this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D); if (this.destPos < 0.0F) { this.destPos = 0.0F; } if (this.destPos > 1.0F) { this.destPos = 1.0F; } if (!this.onGround && this.field_70889_i < 1.0F) { this.field_70889_i = 1.0F; } this.field_70889_i = (float)((double)this.field_70889_i * 0.9D); if (!this.onGround && this.motionY < 0.0D) { this.motionY *= 0.6D; } this.field_70886_e += this.field_70889_i * 2.0F; if (!this.worldObj.isRemote && !this.isChild() && --this.timeUntilNextEgg <= 0) { this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); this.dropItem(Items.egg, 1); this.timeUntilNextEgg = this.rand.nextInt(10) + 10; } } protected void dropFewItems(boolean p_70628_1_, int p_70628_2_) { int j = this.rand.nextInt(4) + this.rand.nextInt(1 + p_70628_2_); int k; for (k = 0; k < j; ++k) { this.dropItem(Items.leather, 1); } j = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + p_70628_2_); for (k = 0; k < j; ++k) { if (this.isBurning()) { this.dropItem(Items.cooked_beef, 1); } else { this.dropItem(Items.beef, 1); } } } /** * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. */ public boolean interact(EntityPlayer p_70085_1_) { ItemStack itemstack = p_70085_1_.inventory.getCurrentItem(); if (itemstack != null && itemstack.getItem() == Items.bucket && !p_70085_1_.capabilities.isCreativeMode) { if (itemstack.stackSize-- == 1) { p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, new ItemStack(Items.milk_bucket)); } else if (!p_70085_1_.inventory.addItemStackToInventory(new ItemStack(Items.milk_bucket))) { p_70085_1_.dropPlayerItemWithRandomChoice(new ItemStack(Items.milk_bucket, 1, 0), false); } return true; } else { return super.interact(p_70085_1_); } } public EntityCow createChild(EntityAgeable p_90011_1_) { return new EntityCow(this.worldObj); } } ________________________________________________________________________________ Main package com.kitsu.medievalcraft; import net.minecraft.entity.EnumCreatureType; import net.minecraft.entity.passive.EntityCow; import net.minecraft.world.biome.BiomeGenBase; import com.kitsu.medievalcraft.block.ModBlocks; import com.kitsu.medievalcraft.crafting.ModCrafting; import com.kitsu.medievalcraft.entity.EntityShit; import com.kitsu.medievalcraft.entity.MedievalCow; import com.kitsu.medievalcraft.item.ModItems; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.EntityRegistry; @Mod(modid = Main.MODID, name = Main.MODNAME, version = Main.VERSION) public class Main { public static final String MODID = "kitsumedievalcraft"; public static final String MODNAME = "Medieval Craft"; public static final String VERSION = "1.0.0"; @Instance public static Main instance = new Main(); @SidedProxy(clientSide="com.kitsu.medievalcraft.ClientProxy", serverSide="com.kitsu.medievalcraft.CommonProxy") public static CommonProxy proxy; /** * Run before anything else. Read your config, create blocks, items, etc, and * register them with the GameRegistry. */ @EventHandler public void preInit(FMLPreInitializationEvent e) { this.proxy.preInit(e); CustomTab.MedievalTab(); ModItems.init(); ModBlocks.init(); ModCrafting.init(); } /** * Do your mod setup. Build whatever data structures you care about. Register recipes. */ @EventHandler public void init(FMLInitializationEvent e) { this.proxy.init(e); EntityRegistry.registerModEntity(EntityShit.class, "itemShit", 1, this, 64, 10, true); EntityRegistry.registerModEntity(MedievalCow.class, "Medieval Cow", 1, this, 80, 3, true); for (int i = 0; i < BiomeGenBase.getBiomeGenArray().length; i++) { if (BiomeGenBase.getBiomeGenArray() != null) { EntityRegistry.removeSpawn(EntityCow.class, EnumCreatureType.monster, BiomeGenBase.getBiomeGenArray()); } } EntityRegistry.addSpawn(MedievalCow.class, 10, 1, 3, EnumCreatureType.monster, BiomeGenBase.birchForest, BiomeGenBase.forest, BiomeGenBase.jungle, BiomeGenBase.plains, BiomeGenBase.savanna, BiomeGenBase.taiga); } /** * Handle interaction with other mods, complete your setup based on this. */ @EventHandler public void postInit(FMLPostInitializationEvent e) { this.proxy.postInit(e); this.proxy.registerRenderer(); //RenderingRegistry.registerEntityRenderingHandler(EntityShit.class, new RenderSnowball(ModItems.itemShit)); } } Quote
Eternaldoom Posted September 25, 2014 Posted September 25, 2014 Do not replace the entity to customize drops. There is an event for that. I think it's called LivingDropsEvent but I'm not quite sure. Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
kitsushadow Posted September 25, 2014 Author Posted September 25, 2014 LivingDropsEvent is for when you kill an animal. I don't want to kill the animal to get my item. I want the item to drop occasionally from cows just like an egg would. I think your right about having to use an event handler though, that's just not the appropriate one Quote
VpzomTrrfrt Posted September 25, 2014 Posted September 25, 2014 Try registering with EntityRegistry.registerGlobalEntityID, maybe that will help? Quote
kitsushadow Posted September 25, 2014 Author Posted September 25, 2014 Use LivingUpdateEvent. Yea, built my EventHandler class and did a test with player interact event and the event registery is working fine as well. However, I cant find the documentation on LivingUpdateEvent in http://www.minecraftforge.net/wiki/Event_Reference page Quote
kitsushadow Posted September 26, 2014 Author Posted September 26, 2014 Yea, got it working exactly how I want it to be. Thanks a lot! Quote
Recommended Posts
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.