Call Looting Event on player death and loot table drops (#3275)

* Call Looting Event on player death and loot table drops

* Simplify patches

* More code cleanup: Replace old usage with compact forgehooks implementation
This commit is contained in:
boni authored and cpw committed 2016-10-30 10:53:50 -05:00
1 parent 858056c089
commit 5f9034d95b
6 files changed
+64 -13

No files matched your search

@@ -43,6 +43,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
@@ -518,7 +519,22 @@ 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) {
public static int getLootingLevel(Entity target, Entity killer, DamageSource cause)
{
int looting = 0;
if (killer instanceof EntityLivingBase)
{
looting = EnchantmentHelper.getLootingModifier((EntityLivingBase)killer);
}
if (target instanceof EntityLivingBase)
{
looting = getLootingLevel((EntityLivingBase)target, cause, looting);
}
return looting;
}
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();
@@ -21,9 +21,9 @@ package net.minecraftforge.event.entity.player;
import java.util.List;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
@@ -48,10 +48,7 @@ public class PlayerDropsEvent extends LivingDropsEvent
*/
public PlayerDropsEvent(EntityPlayer entity, DamageSource source, List<EntityItem> drops, boolean recentlyHit)
{
super(entity, source, drops,
(source.getEntity() instanceof EntityPlayer) ?
EnchantmentHelper.getLootingModifier(((EntityPlayer)source.getEntity())) : 0,
recentlyHit);
super(entity, source, drops, ForgeHooks.getLootingLevel(entity, source.getEntity(), source), recentlyHit);
this.entityPlayer = entity;
}