3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

[Bleeding] Account for new rare drops in EntityDeath events. Fixes BUKKIT-1105

Dieser Commit ist enthalten in:
zerg960 2012-03-20 20:55:45 -05:00 committet von EvilSeph
Ursprung 1c95413f49
Commit 96c4bb7da6
4 geänderte Dateien mit 77 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -9,6 +9,7 @@ import java.util.Random;
// CraftBukkit start
import org.bukkit.craftbukkit.TrigMath;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
@ -778,20 +779,18 @@ public abstract class EntityLiving extends Entity {
if (!this.isBaby()) {
this.dropDeathLoot(this.lastDamageByPlayerTime > 0, i);
if (this.lastDamageByPlayerTime > 0) {
int j = this.random.nextInt(200) - i;
if (j < 5) {
this.b(j <= 0 ? 1 : 0);
}
}
// CraftBukkit - move rare item drop call to dropDeathLoot
}
}
this.world.broadcastEntityEffect(this, (byte) 3);
}
protected void b(int i) {}
// CraftBukkit start - change return type to ItemStack
protected ItemStack b(int i) {
return null;
}
// CraftBukkit end
protected void dropDeathLoot(boolean flag, int i) {
int j = this.getLootId();
@ -811,6 +810,18 @@ public abstract class EntityLiving extends Entity {
}
}
// Determine rare item drops and add them to the loot
if (this.lastDamageByPlayerTime > 0) {
int k = this.random.nextInt(200) - i;
if (k < 5) {
ItemStack itemstack = this.b(k <= 0 ? 1 : 0);
if (itemstack != null) {
loot.add(new CraftItemStack(itemstack));
}
}
}
CraftEventFactory.callEntityDeathEvent(this, loot); // raise event even for those times when the entity does not drop loot
// CraftBukkit end
}

Datei anzeigen

@ -120,8 +120,6 @@ public class EntityPigZombie extends EntityZombie {
List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
int j = this.random.nextInt(2 + i);
int k;
if (j > 0) {
loot.add(new CraftItemStack(Item.ROTTEN_FLESH.id, j));
}
@ -131,28 +129,45 @@ public class EntityPigZombie extends EntityZombie {
if (j > 0) {
loot.add(new CraftItemStack(Item.GOLD_NUGGET.id, j));
}
// Determine rare item drops and add them to the loot
if (this.lastDamageByPlayerTime > 0) {
int k = this.random.nextInt(200) - i;
if (k < 5) {
ItemStack itemstack = this.b(k <= 0 ? 1 : 0);
if (itemstack != null) {
loot.add(new CraftItemStack(itemstack));
}
}
}
CraftEventFactory.callEntityDeathEvent(this, loot);
// CraftBukkit end
}
protected void b(int i) {
// CraftBukkit start - return rare dropped item instead of dropping it
protected ItemStack b(int i) {
if (i > 0) {
ItemStack itemstack = new ItemStack(Item.GOLD_SWORD);
EnchantmentManager.a(this.random, itemstack, 5);
this.a(itemstack, 0.0F);
return itemstack;
} else {
int j = this.random.nextInt(3);
if (j == 0) {
this.b(Item.GOLD_INGOT.id, 1);
return new ItemStack(Item.GOLD_INGOT.id, 1, 0);
} else if (j == 1) {
this.b(Item.GOLD_SWORD.id, 1);
return new ItemStack(Item.GOLD_SWORD.id, 1, 0);
} else if (j == 2) {
this.b(Item.GOLD_HELMET.id, 1);
return new ItemStack(Item.GOLD_HELMET.id, 1, 0);
} else {
return null;
}
}
}
// CraftBukkit end
protected int getLootId() {
return Item.ROTTEN_FLESH.id;

Datei anzeigen

@ -1,5 +1,10 @@
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
// CraftBukkit end
public class EntitySkeleton extends EntityMonster {
private static final ItemStack a = new ItemStack(Item.BOW, 1);
@ -93,18 +98,32 @@ public class EntitySkeleton extends EntityMonster {
loot.add(new org.bukkit.inventory.ItemStack(org.bukkit.Material.BONE, count));
}
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, loot);
// Determine rare item drops and add them to the loot
if (this.lastDamageByPlayerTime > 0) {
int k = this.random.nextInt(200) - i;
if (k < 5) {
ItemStack itemstack = this.b(k <= 0 ? 1 : 0);
if (itemstack != null) {
loot.add(new CraftItemStack(itemstack));
}
}
}
CraftEventFactory.callEntityDeathEvent(this, loot);
// CraftBukkit end
}
protected void b(int i) {
// CraftBukkit start - return rare dropped item instead of dropping it
protected ItemStack b(int i) {
if (i > 0) {
ItemStack itemstack = new ItemStack(Item.BOW);
EnchantmentManager.a(this.random, itemstack, 5);
this.a(itemstack, 0.0F);
return itemstack;
} else {
this.b(Item.BOW.id, 1);
return new ItemStack(Item.BOW.id, 1, 0);
}
}
// CraftBukkit end
}

Datei anzeigen

@ -75,22 +75,20 @@ public class EntityZombie extends EntityMonster {
return MonsterType.UNDEAD;
}
protected void b(int i) {
// CraftBukkit start - return rare dropped item instead of dropping it
protected ItemStack b(int i) {
switch (this.random.nextInt(4)) {
case 0:
this.b(Item.IRON_SWORD.id, 1);
break;
case 1:
this.b(Item.IRON_HELMET.id, 1);
break;
case 2:
this.b(Item.IRON_INGOT.id, 1);
break;
case 3:
this.b(Item.IRON_SPADE.id, 1);
case 0:
return new ItemStack(Item.IRON_SWORD.id, 1, 0);
case 1:
return new ItemStack(Item.IRON_HELMET.id, 1, 0);
case 2:
return new ItemStack(Item.IRON_INGOT.id, 1, 0);
case 3:
return new ItemStack(Item.IRON_SPADE.id, 1, 0);
default:
return null;
}
}
// CraftBukkit end
}