From 2ea499ba5d39643bc73f2659bd04935a2902fd91 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Fri, 1 Aug 2014 23:21:27 +0200 Subject: [PATCH] It's raining mobheads --- .../mobheads/IguanaMobHeads.java | 4 +- .../mobheads/handlers/MobHeadHandler.java | 106 ++++++++++++++++++ .../RenderPlayerHandler.java | 3 +- .../mobheads/items/IguanaSkull.java | 10 +- 4 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 src/main/java/iguanaman/iguanatweakstconstruct/mobheads/handlers/MobHeadHandler.java rename src/main/java/iguanaman/iguanatweakstconstruct/mobheads/{renderers => handlers}/RenderPlayerHandler.java (91%) diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/IguanaMobHeads.java b/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/IguanaMobHeads.java index 4e9de96..9905db6 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/IguanaMobHeads.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/IguanaMobHeads.java @@ -5,9 +5,10 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; import iguanaman.iguanatweakstconstruct.mobheads.blocks.IguanaSkullBlock; +import iguanaman.iguanatweakstconstruct.mobheads.handlers.MobHeadHandler; import iguanaman.iguanatweakstconstruct.mobheads.items.IguanaSkull; import iguanaman.iguanatweakstconstruct.mobheads.proxy.MobHeadCommonProxy; -import iguanaman.iguanatweakstconstruct.mobheads.renderers.RenderPlayerHandler; +import iguanaman.iguanatweakstconstruct.mobheads.handlers.RenderPlayerHandler; import iguanaman.iguanatweakstconstruct.mobheads.tileentities.IguanaSkullTileEntity; import iguanaman.iguanatweakstconstruct.reference.Reference; import mantle.pulsar.pulse.Handler; @@ -44,6 +45,7 @@ public class IguanaMobHeads { public void postInit(FMLPostInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new RenderPlayerHandler()); + MinecraftForge.EVENT_BUS.register(new MobHeadHandler()); proxy.postInit(); } diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/handlers/MobHeadHandler.java b/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/handlers/MobHeadHandler.java new file mode 100644 index 0000000..1cb9971 --- /dev/null +++ b/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/handlers/MobHeadHandler.java @@ -0,0 +1,106 @@ +package iguanaman.iguanatweakstconstruct.mobheads.handlers; + +import cpw.mods.fml.common.eventhandler.EventPriority; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.registry.EntityRegistry; +import iguanaman.iguanatweakstconstruct.mobheads.IguanaMobHeads; +import iguanaman.iguanatweakstconstruct.mobheads.items.IguanaSkull; +import iguanaman.iguanatweakstconstruct.reference.Config; +import iguanaman.iguanatweakstconstruct.util.Log; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.monster.*; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.event.entity.living.LivingDropsEvent; +import tconstruct.TConstruct; +import tconstruct.library.tools.ToolCore; +import tconstruct.tools.TinkerTools; + +import java.util.Iterator; +import java.util.Random; + +public class MobHeadHandler { + private static Random random = new Random(); + + @SubscribeEvent(priority = EventPriority.LOWEST) + public void LivingDrops(LivingDropsEvent event) + { + // remove regular skull drops (because we modify its drop chance) + Iterator i = event.drops.iterator(); + while (i.hasNext()) { + EntityItem eitem = i.next(); + + if (eitem != null) + if (eitem.getEntityItem() != null) + { + ItemStack item = eitem.getEntityItem(); + if (item.getItem() == Items.skull && item.getItemDamage() != 3) + i.remove(); + } + } + + // add our own drops if the damage source was a player (and no fake player) + Entity entity = event.source.getEntity(); + if(entity == null) + return; + if(!(entity instanceof EntityPlayer) || entity instanceof FakePlayer) + return; + + // how much beheading chance do we have? + EntityPlayer player = (EntityPlayer) event.source.getEntity(); + ItemStack stack = player.getCurrentEquippedItem(); + int beheading = 0; + if (stack != null && stack.hasTagCompound() && stack.getItem() instanceof ToolCore) + { + beheading = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Beheading"); + if (stack.getItem() == TinkerTools.cleaver) + beheading += 2; + } + // roll the dice + if(random.nextInt(100) > beheading * Config.beheadingHeadDropChance + Config.baseHeadDropChance) + return; + + Item skullItem = null; + int skullId = -1; + + Entity mob = event.entityLiving; + // skelly/witherskelly + if (mob instanceof EntitySkeleton) { + skullItem = Items.skull; + skullId = ((EntitySkeleton) event.entityLiving).getSkeletonType(); + } + else if (mob instanceof EntityPigZombie) { + skullItem = IguanaMobHeads.skullItem; + skullId = IguanaSkull.META_PIGZOMBIE; + } + else if (mob instanceof EntityZombie) { + skullItem = Items.skull; + skullId = 2; + } + else if (mob instanceof EntityCreeper) { + skullItem = Items.skull; + skullId = 4; + } + else if (mob instanceof EntityEnderman) { + skullItem = IguanaMobHeads.skullItem; + skullId = IguanaSkull.META_ENDERMAN; + } + else if (mob instanceof EntityBlaze) { + skullItem = IguanaMobHeads.skullItem; + skullId = IguanaSkull.META_BLAZE; + } + + // no skull found? + if(skullItem == null) + return; + + // drop it like it's hot + EntityItem entityitem = new EntityItem(mob.worldObj, mob.posX, mob.posY, mob.posZ, new ItemStack(skullItem, 1, skullId)); + entityitem.delayBeforeCanPickup =10; + event.drops.add(entityitem); + } +} diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/renderers/RenderPlayerHandler.java b/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/handlers/RenderPlayerHandler.java similarity index 91% rename from src/main/java/iguanaman/iguanatweakstconstruct/mobheads/renderers/RenderPlayerHandler.java rename to src/main/java/iguanaman/iguanatweakstconstruct/mobheads/handlers/RenderPlayerHandler.java index 0655fc6..f375e9c 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/renderers/RenderPlayerHandler.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/handlers/RenderPlayerHandler.java @@ -1,4 +1,4 @@ -package iguanaman.iguanatweakstconstruct.mobheads.renderers; +package iguanaman.iguanatweakstconstruct.mobheads.handlers; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.Side; @@ -6,6 +6,7 @@ import cpw.mods.fml.relauncher.SideOnly; import iguanaman.iguanatweakstconstruct.IguanaTweaksTConstruct; import iguanaman.iguanatweakstconstruct.claybuckets.IguanaItems; import iguanaman.iguanatweakstconstruct.mobheads.IguanaMobHeads; +import iguanaman.iguanatweakstconstruct.mobheads.renderers.IguanaTileEntitySkullRenderer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.client.event.RenderPlayerEvent; diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/items/IguanaSkull.java b/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/items/IguanaSkull.java index 1ca8d7c..e752250 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/items/IguanaSkull.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/mobheads/items/IguanaSkull.java @@ -21,13 +21,9 @@ import net.minecraft.world.World; import java.util.List; public class IguanaSkull extends net.minecraft.item.ItemSkull { - public static final int META_ZOMBIE = 2; - public static final int META_SKELETON = 0; - public static final int META_ENDERMAN = 5; - public static final int META_PIGMAN = 6; - public static final int META_BLAZE = 7; - public static final int META_STEVE = 3; - public static final int META_CREEPER = 4; + public static final int META_ENDERMAN = 0; + public static final int META_PIGZOMBIE = 1; + public static final int META_BLAZE = 2; private static final String[] skullTypes = new String[] {"enderman", "pigman", "blaze"}; public static final String[] field_94587_a = new String[] {"skull_enderman", "skull_pigman", "skull_blaze"};