diff --git a/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch b/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch index c842cddc9f..417f525eae 100644 --- a/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch +++ b/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch @@ -76,9 +76,11 @@ if (!this.field_70729_aU) { Entity entity = p_70645_1_.func_76346_g(); -@@ -1070,11 +1076,24 @@ +@@ -1069,12 +1075,26 @@ + { i = EnchantmentHelper.func_185283_h((EntityLivingBase)entity); } ++ i = net.minecraftforge.common.ForgeHooks.getLootingLevel(this, p_70645_1_, i); + captureDrops = true; + capturedDrops.clear(); @@ -101,7 +103,7 @@ } this.field_70170_p.func_72960_a(this, (byte)3); -@@ -1151,7 +1170,7 @@ +@@ -1151,7 +1171,7 @@ BlockPos blockpos = new BlockPos(i, j, k); IBlockState iblockstate = this.field_70170_p.func_180495_p(blockpos); Block block = iblockstate.func_177230_c(); @@ -110,7 +112,7 @@ } } -@@ -1177,6 +1196,9 @@ +@@ -1177,6 +1197,9 @@ public void func_180430_e(float p_180430_1_, float p_180430_2_) { @@ -120,7 +122,7 @@ super.func_180430_e(p_180430_1_, p_180430_2_); PotionEffect potioneffect = this.func_70660_b(MobEffects.field_76430_j); float f = potioneffect == null ? 0.0F : (float)(potioneffect.func_76458_c() + 1); -@@ -1270,6 +1292,8 @@ +@@ -1270,6 +1293,8 @@ { if (!this.func_180431_b(p_70665_1_)) { @@ -129,7 +131,7 @@ p_70665_2_ = this.func_70655_b(p_70665_1_, p_70665_2_); p_70665_2_ = this.func_70672_c(p_70665_1_, p_70665_2_); float f = p_70665_2_; -@@ -1319,6 +1343,11 @@ +@@ -1319,6 +1344,11 @@ public void func_184609_a(EnumHand p_184609_1_) { @@ -141,7 +143,7 @@ if (!this.field_82175_bq || this.field_110158_av >= this.func_82166_i() / 2 || this.field_110158_av < 0) { this.field_110158_av = -1; -@@ -1521,6 +1550,7 @@ +@@ -1521,6 +1551,7 @@ public void func_110145_l(Entity p_110145_1_) { @@ -149,7 +151,7 @@ if (!(p_110145_1_ instanceof EntityBoat) && !(p_110145_1_ instanceof EntityHorse)) { double d1 = p_110145_1_.field_70165_t; -@@ -1545,7 +1575,7 @@ +@@ -1545,7 +1576,7 @@ if (!this.field_70170_p.func_184143_b(axisalignedbb1)) { @@ -158,7 +160,7 @@ { this.func_70634_a(d11, this.field_70163_u + 1.0D, d12); return; -@@ -1553,14 +1583,14 @@ +@@ -1553,14 +1584,14 @@ BlockPos blockpos = new BlockPos(d11, this.field_70163_u - 1.0D, d12); @@ -175,7 +177,7 @@ { d1 = d11; d13 = this.field_70163_u + 2.0D; -@@ -1631,6 +1661,7 @@ +@@ -1631,6 +1662,7 @@ } this.field_70160_al = true; @@ -183,7 +185,7 @@ } protected void func_70629_bd() -@@ -1903,6 +1934,7 @@ +@@ -1903,6 +1935,7 @@ public void func_70071_h_() { @@ -191,7 +193,7 @@ super.func_70071_h_(); this.func_184608_ct(); -@@ -2409,6 +2441,40 @@ +@@ -2409,6 +2442,40 @@ this.field_70752_e = true; } @@ -232,7 +234,7 @@ public abstract EnumHandSide func_184591_cq(); public boolean func_184587_cr() -@@ -2429,12 +2495,19 @@ +@@ -2429,12 +2496,19 @@ if (itemstack == this.field_184627_bm) { @@ -253,7 +255,7 @@ { this.func_71036_o(); } -@@ -2452,8 +2525,10 @@ +@@ -2452,8 +2526,10 @@ if (itemstack != null && !this.func_184587_cr()) { @@ -265,7 +267,7 @@ if (!this.field_70170_p.field_72995_K) { -@@ -2536,6 +2611,8 @@ +@@ -2536,6 +2612,8 @@ this.func_184584_a(this.field_184627_bm, 16); ItemStack itemstack = this.field_184627_bm.func_77950_b(this.field_70170_p, this); @@ -274,7 +276,7 @@ if (itemstack != null && itemstack.field_77994_a == 0) { itemstack = null; -@@ -2566,7 +2643,8 @@ +@@ -2566,7 +2644,8 @@ { if (this.field_184627_bm != null) { @@ -284,7 +286,7 @@ } this.func_184602_cy(); -@@ -2685,4 +2763,28 @@ +@@ -2685,4 +2764,28 @@ { return true; } diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index 0f2d0850a7..5dce692d56 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -111,6 +111,7 @@ import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; +import net.minecraftforge.event.entity.living.LootingLevelEvent; import net.minecraftforge.event.entity.player.AnvilRepairEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; @@ -517,6 +518,12 @@ public class ForgeHooks return (MinecraftForge.EVENT_BUS.post(event) ? null : new float[]{event.getDistance(), event.getDamageMultiplier()}); } + public static int getLootingLevel(EntityLivingBase target, DamageSource cause, int level) { + LootingLevelEvent event = new LootingLevelEvent(target, cause, level); + MinecraftForge.EVENT_BUS.post(event); + return event.getLootingLevel(); + } + public static boolean isLivingOnLadder(IBlockState state, World world, BlockPos pos, EntityLivingBase entity) { boolean isSpectator = (entity instanceof EntityPlayer && ((EntityPlayer)entity).isSpectator()); diff --git a/src/main/java/net/minecraftforge/event/entity/living/LootingLevelEvent.java b/src/main/java/net/minecraftforge/event/entity/living/LootingLevelEvent.java new file mode 100644 index 0000000000..3d91472c37 --- /dev/null +++ b/src/main/java/net/minecraftforge/event/entity/living/LootingLevelEvent.java @@ -0,0 +1,29 @@ +package net.minecraftforge.event.entity.living; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.DamageSource; + +public class LootingLevelEvent extends LivingEvent { + + private final DamageSource damageSource; + + private int lootingLevel; + + public LootingLevelEvent(EntityLivingBase entity, DamageSource damageSource, int lootingLevel) { + super(entity); + this.damageSource = damageSource; + this.lootingLevel = lootingLevel; + } + + public DamageSource getDamageSource() { + return damageSource; + } + + public int getLootingLevel() { + return lootingLevel; + } + + public void setLootingLevel(int lootingLevel) { + this.lootingLevel = lootingLevel; + } +} diff --git a/src/test/java/net/minecraftforge/debug/LootTablesDebug.java b/src/test/java/net/minecraftforge/debug/LootTablesDebug.java index 7b4a89e948..4e3d943d7a 100644 --- a/src/test/java/net/minecraftforge/debug/LootTablesDebug.java +++ b/src/test/java/net/minecraftforge/debug/LootTablesDebug.java @@ -1,6 +1,9 @@ package net.minecraftforge.debug; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.init.Items; +import net.minecraft.util.DamageSource; import net.minecraft.util.ResourceLocation; import net.minecraft.world.storage.loot.LootEntryItem; import net.minecraft.world.storage.loot.LootPool; @@ -9,6 +12,7 @@ import net.minecraft.world.storage.loot.conditions.LootCondition; import net.minecraft.world.storage.loot.functions.LootFunction; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.LootTableLoadEvent; +import net.minecraftforge.event.entity.living.LootingLevelEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -39,4 +43,13 @@ public class LootTablesDebug { // Get rid of all building mats. Which is pool #3, index starts at 0, but 0 is named "main" event.getTable().removePool("pool3"); } + + @SubscribeEvent + public void lootingEvent(LootingLevelEvent event) { + // if the player shoots something with a projectile, use looting 3 + DamageSource damageSource = event.getDamageSource(); + if(damageSource.isProjectile() && damageSource.getEntity() instanceof EntityPlayer && damageSource.getSourceOfDamage() instanceof EntityArrow) { + event.setLootingLevel(3); + } + } }