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:
parent
858056c089
commit
5f9034d95b
6 changed files with 64 additions and 13 deletions
|
@ -76,15 +76,20 @@
|
||||||
if (!this.field_70729_aU)
|
if (!this.field_70729_aU)
|
||||||
{
|
{
|
||||||
Entity entity = p_70645_1_.func_76346_g();
|
Entity entity = p_70645_1_.func_76346_g();
|
||||||
@@ -1069,12 +1075,26 @@
|
@@ -1063,18 +1069,26 @@
|
||||||
{
|
|
||||||
i = EnchantmentHelper.func_185283_h((EntityLivingBase)entity);
|
|
||||||
}
|
|
||||||
+ i = net.minecraftforge.common.ForgeHooks.getLootingLevel(this, p_70645_1_, i);
|
|
||||||
|
|
||||||
|
if (!this.field_70170_p.field_72995_K)
|
||||||
|
{
|
||||||
|
- int i = 0;
|
||||||
|
+ int i = net.minecraftforge.common.ForgeHooks.getLootingLevel(this, entity, p_70645_1_);
|
||||||
|
|
||||||
|
- if (entity instanceof EntityPlayer)
|
||||||
|
- {
|
||||||
|
- i = EnchantmentHelper.func_185283_h((EntityLivingBase)entity);
|
||||||
|
- }
|
||||||
+ captureDrops = true;
|
+ captureDrops = true;
|
||||||
+ capturedDrops.clear();
|
+ capturedDrops.clear();
|
||||||
+
|
|
||||||
if (this.func_146066_aG() && this.field_70170_p.func_82736_K().func_82766_b("doMobLoot"))
|
if (this.func_146066_aG() && this.field_70170_p.func_82736_K().func_82766_b("doMobLoot"))
|
||||||
{
|
{
|
||||||
boolean flag = this.field_70718_bc > 0;
|
boolean flag = this.field_70718_bc > 0;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
--- ../src-base/minecraft/net/minecraft/world/storage/loot/LootContext.java
|
--- ../src-base/minecraft/net/minecraft/world/storage/loot/LootContext.java
|
||||||
+++ ../src-work/minecraft/net/minecraft/world/storage/loot/LootContext.java
|
+++ ../src-work/minecraft/net/minecraft/world/storage/loot/LootContext.java
|
||||||
@@ -89,6 +89,11 @@
|
@@ -89,6 +89,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@
|
||||||
+ {
|
+ {
|
||||||
+ return field_186499_b;
|
+ return field_186499_b;
|
||||||
+ }
|
+ }
|
||||||
|
+
|
||||||
|
+ public int getLootingModifier()
|
||||||
|
+ {
|
||||||
|
+ return net.minecraftforge.common.ForgeHooks.getLootingLevel(func_186493_a(), func_186492_c(), field_186503_f);
|
||||||
|
+ }
|
||||||
+
|
+
|
||||||
public static class Builder
|
public static class Builder
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
--- ../src-base/minecraft/net/minecraft/world/storage/loot/conditions/RandomChanceWithLooting.java
|
||||||
|
+++ ../src-work/minecraft/net/minecraft/world/storage/loot/conditions/RandomChanceWithLooting.java
|
||||||
|
@@ -23,13 +23,8 @@
|
||||||
|
|
||||||
|
public boolean func_186618_a(Random p_186618_1_, LootContext p_186618_2_)
|
||||||
|
{
|
||||||
|
- int i = 0;
|
||||||
|
+ int i = p_186618_2_.getLootingModifier();
|
||||||
|
|
||||||
|
- if (p_186618_2_.func_186492_c() instanceof EntityLivingBase)
|
||||||
|
- {
|
||||||
|
- i = EnchantmentHelper.func_185283_h((EntityLivingBase)p_186618_2_.func_186492_c());
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
return p_186618_1_.nextFloat() < this.field_186627_a + (float)i * this.field_186628_b;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
--- ../src-base/minecraft/net/minecraft/world/storage/loot/functions/LootingEnchantBonus.java
|
||||||
|
+++ ../src-work/minecraft/net/minecraft/world/storage/loot/functions/LootingEnchantBonus.java
|
||||||
|
@@ -32,7 +32,7 @@
|
||||||
|
|
||||||
|
if (entity instanceof EntityLivingBase)
|
||||||
|
{
|
||||||
|
- int i = EnchantmentHelper.func_185283_h((EntityLivingBase)entity);
|
||||||
|
+ int i = p_186553_3_.getLootingModifier();
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
{
|
|
@ -43,6 +43,7 @@ import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityList;
|
import net.minecraft.entity.EntityList;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
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()});
|
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);
|
LootingLevelEvent event = new LootingLevelEvent(target, cause, level);
|
||||||
MinecraftForge.EVENT_BUS.post(event);
|
MinecraftForge.EVENT_BUS.post(event);
|
||||||
return event.getLootingLevel();
|
return event.getLootingLevel();
|
||||||
|
|
|
@ -21,9 +21,9 @@ package net.minecraftforge.event.entity.player;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||||
|
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.util.DamageSource;
|
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)
|
public PlayerDropsEvent(EntityPlayer entity, DamageSource source, List<EntityItem> drops, boolean recentlyHit)
|
||||||
{
|
{
|
||||||
super(entity, source, drops,
|
super(entity, source, drops, ForgeHooks.getLootingLevel(entity, source.getEntity(), source), recentlyHit);
|
||||||
(source.getEntity() instanceof EntityPlayer) ?
|
|
||||||
EnchantmentHelper.getLootingModifier(((EntityPlayer)source.getEntity())) : 0,
|
|
||||||
recentlyHit);
|
|
||||||
|
|
||||||
this.entityPlayer = entity;
|
this.entityPlayer = entity;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue