From bf211db416bfe78b3b6712e10a80ecf7044d7c15 Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Tue, 27 Jan 2015 23:28:25 -0500 Subject: [PATCH] Wither skeletons will now drop necrotic bones and respect beheading --- .../enderio/entity/EntityWitherSkeleton.java | 40 ++++++++++++++++++- src/main/java/crazypants/util/EntityUtil.java | 33 +++++++++++++-- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/main/java/crazypants/enderio/entity/EntityWitherSkeleton.java b/src/main/java/crazypants/enderio/entity/EntityWitherSkeleton.java index 968566eb..59bda4e0 100644 --- a/src/main/java/crazypants/enderio/entity/EntityWitherSkeleton.java +++ b/src/main/java/crazypants/enderio/entity/EntityWitherSkeleton.java @@ -1,15 +1,22 @@ package crazypants.enderio.entity; +import java.util.Calendar; + +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; import net.minecraft.world.World; - -import java.util.Calendar; +import cpw.mods.fml.common.registry.GameRegistry; +import crazypants.util.EntityUtil; public class EntityWitherSkeleton extends EntitySkeleton { public EntityWitherSkeleton(World world) { @@ -54,4 +61,33 @@ public class EntityWitherSkeleton extends EntitySkeleton { public int getSkeletonType() { return 1; } + + @Override + public void onDeath(DamageSource source) { + super.onDeath(source); + if(source.damageType.equals("player")) { + EntityPlayer player = (EntityPlayer) source.getEntity(); + ItemStack stack = player.getCurrentEquippedItem(); + if(stack != null && stack.hasTagCompound()) { + Item cleaver = GameRegistry.findItem("TConstruct", "cleaver"); + int beheading = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Beheading"); + if(stack.getItem() == cleaver) { + beheading += 2; + } + System.out.println(beheading); + if(beheading > 0 && worldObj.rand.nextInt(100) < beheading * 10) { + EntityUtil.spawnItemInWorldWithRandomMotion(worldObj, new ItemStack(Items.skull, 1, 1), posX, posY, posZ); + } + } + } + if(source.getEntity() instanceof EntityLivingBase) { + int lootingLevel = EnchantmentHelper.getLootingModifier((EntityLivingBase) source.getEntity()); + if(worldObj.rand.nextInt(Math.max(1, 1 - lootingLevel)) == 0) { + Item necroticBone = GameRegistry.findItem("TConstruct", "materials"); + if(necroticBone != null) { + EntityUtil.spawnItemInWorldWithRandomMotion(worldObj, new ItemStack(necroticBone, 1, 8), posX, posY, posZ); + } + } + } + } } diff --git a/src/main/java/crazypants/util/EntityUtil.java b/src/main/java/crazypants/util/EntityUtil.java index 024978e2..2a214658 100644 --- a/src/main/java/crazypants/util/EntityUtil.java +++ b/src/main/java/crazypants/util/EntityUtil.java @@ -5,18 +5,18 @@ import java.util.List; import java.util.Map; import java.util.Set; -import crazypants.vecmath.Vector3d; - import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.boss.IBossDisplayData; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraft.util.StatCollector; import net.minecraft.world.World; +import crazypants.vecmath.Vector3d; public class EntityUtil { @@ -65,5 +65,30 @@ public class EntityUtil { } return collidingBoundingBoxes; } - + + public static void spawnItemInWorldWithRandomMotion(World world, ItemStack item, int x, int y, int z) { + if(item != null) { + spawnItemInWorldWithRandomMotion(world, item, x + 0.5, y + 0.5, z + 0.5); + } + } + + public static void spawnItemInWorldWithRandomMotion(World world, ItemStack item, double x, double y, double z) { + if(item != null) { + spawnItemInWorldWithRandomMotion(new EntityItem(world, x, y, z, item)); + } + } + + public static void spawnItemInWorldWithRandomMotion(EntityItem entity) { + entity.delayBeforeCanPickup = 10; + + float f = (entity.worldObj.rand.nextFloat() * 0.1f) - 0.05f; + float f1 = (entity.worldObj.rand.nextFloat() * 0.1f) - 0.05f; + float f2 = (entity.worldObj.rand.nextFloat() * 0.1f) - 0.05f; + + entity.motionX += f; + entity.motionY += f1; + entity.motionZ += f2; + + entity.worldObj.spawnEntityInWorld(entity); + } }