3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-19 04:50:06 +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 // CraftBukkit start
import org.bukkit.craftbukkit.TrigMath; import org.bukkit.craftbukkit.TrigMath;
import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent;
@ -778,20 +779,18 @@ public abstract class EntityLiving extends Entity {
if (!this.isBaby()) { if (!this.isBaby()) {
this.dropDeathLoot(this.lastDamageByPlayerTime > 0, i); this.dropDeathLoot(this.lastDamageByPlayerTime > 0, i);
if (this.lastDamageByPlayerTime > 0) { // CraftBukkit - move rare item drop call to dropDeathLoot
int j = this.random.nextInt(200) - i;
if (j < 5) {
this.b(j <= 0 ? 1 : 0);
}
}
} }
} }
this.world.broadcastEntityEffect(this, (byte) 3); 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) { protected void dropDeathLoot(boolean flag, int i) {
int j = this.getLootId(); 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 CraftEventFactory.callEntityDeathEvent(this, loot); // raise event even for those times when the entity does not drop loot
// CraftBukkit end // 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>(); List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
int j = this.random.nextInt(2 + i); int j = this.random.nextInt(2 + i);
int k;
if (j > 0) { if (j > 0) {
loot.add(new CraftItemStack(Item.ROTTEN_FLESH.id, j)); loot.add(new CraftItemStack(Item.ROTTEN_FLESH.id, j));
} }
@ -131,28 +129,45 @@ public class EntityPigZombie extends EntityZombie {
if (j > 0) { if (j > 0) {
loot.add(new CraftItemStack(Item.GOLD_NUGGET.id, j)); 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); CraftEventFactory.callEntityDeathEvent(this, loot);
// CraftBukkit end // 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) { if (i > 0) {
ItemStack itemstack = new ItemStack(Item.GOLD_SWORD); ItemStack itemstack = new ItemStack(Item.GOLD_SWORD);
EnchantmentManager.a(this.random, itemstack, 5); EnchantmentManager.a(this.random, itemstack, 5);
this.a(itemstack, 0.0F); return itemstack;
} else { } else {
int j = this.random.nextInt(3); int j = this.random.nextInt(3);
if (j == 0) { if (j == 0) {
this.b(Item.GOLD_INGOT.id, 1); return new ItemStack(Item.GOLD_INGOT.id, 1, 0);
} else if (j == 1) { } else if (j == 1) {
this.b(Item.GOLD_SWORD.id, 1); return new ItemStack(Item.GOLD_SWORD.id, 1, 0);
} else if (j == 2) { } 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() { protected int getLootId() {
return Item.ROTTEN_FLESH.id; return Item.ROTTEN_FLESH.id;

Datei anzeigen

@ -1,5 +1,10 @@
package net.minecraft.server; 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 { public class EntitySkeleton extends EntityMonster {
private static final ItemStack a = new ItemStack(Item.BOW, 1); 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)); 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 // 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) { if (i > 0) {
ItemStack itemstack = new ItemStack(Item.BOW); ItemStack itemstack = new ItemStack(Item.BOW);
EnchantmentManager.a(this.random, itemstack, 5); EnchantmentManager.a(this.random, itemstack, 5);
this.a(itemstack, 0.0F); return itemstack;
} else { } 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; 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)) { switch (this.random.nextInt(4)) {
case 0: case 0:
this.b(Item.IRON_SWORD.id, 1); return new ItemStack(Item.IRON_SWORD.id, 1, 0);
break;
case 1: case 1:
this.b(Item.IRON_HELMET.id, 1); return new ItemStack(Item.IRON_HELMET.id, 1, 0);
break;
case 2: case 2:
this.b(Item.IRON_INGOT.id, 1); return new ItemStack(Item.IRON_INGOT.id, 1, 0);
break;
case 3: case 3:
this.b(Item.IRON_SPADE.id, 1); return new ItemStack(Item.IRON_SPADE.id, 1, 0);
default:
return null;
} }
} }
// CraftBukkit end
} }