3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-22 06:20:06 +01:00
Paper/nms-patches/EntityArmorStand.patch
2019-12-11 09:00:00 +11:00

163 Zeilen
6.6 KiB
Diff

--- a/net/minecraft/server/EntityArmorStand.java
+++ b/net/minecraft/server/EntityArmorStand.java
@@ -5,6 +5,15 @@
import java.util.function.Predicate;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.ArmorStand;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
+// CraftBukkit end
+
public class EntityArmorStand extends EntityLiving {
private static final Vector3f br = new Vector3f(0.0F, 0.0F, 0.0F);
@@ -53,6 +62,13 @@
this.setPosition(d0, d1, d2);
}
+ // CraftBukkit start - SPIGOT-3607, SPIGOT-3637
+ @Override
+ public float getBukkitYaw() {
+ return this.yaw;
+ }
+ // CraftBukkit end
+
@Override
public boolean bt() {
return !this.isMarker() && super.bt();
@@ -386,6 +402,21 @@
return false;
} else {
ItemStack itemstack2;
+ // CraftBukkit start
+ org.bukkit.inventory.ItemStack armorStandItem = CraftItemStack.asCraftMirror(itemstack1);
+ org.bukkit.inventory.ItemStack playerHeldItem = CraftItemStack.asCraftMirror(itemstack);
+
+ Player player = (Player) entityhuman.getBukkitEntity();
+ ArmorStand self = (ArmorStand) this.getBukkitEntity();
+
+ EquipmentSlot slot = CraftEquipmentSlot.getSlot(enumitemslot);
+ PlayerArmorStandManipulateEvent armorStandManipulateEvent = new PlayerArmorStandManipulateEvent(player,self,playerHeldItem,armorStandItem,slot);
+ this.world.getServer().getPluginManager().callEvent(armorStandManipulateEvent);
+
+ if (armorStandManipulateEvent.isCancelled()) {
+ return true;
+ }
+ // CraftBukkit end
if (entityhuman.abilities.canInstantlyBuild && itemstack1.isEmpty() && !itemstack.isEmpty()) {
itemstack2 = itemstack.cloneItemStack();
@@ -414,12 +445,22 @@
public boolean damageEntity(DamageSource damagesource, float f) {
if (!this.world.isClientSide && !this.dead) {
if (DamageSource.OUT_OF_WORLD.equals(damagesource)) {
- this.die();
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f)) {
+ return false;
+ }
+ // CraftBukkit end
+ this.killEntity(); // CraftBukkit - this.die() -> this.killEntity()
return false;
- } else if (!this.isInvulnerable(damagesource) && !this.armorStandInvisible && !this.isMarker()) {
+ } else if (!this.isInvulnerable(damagesource) && (true || !this.armorStandInvisible) && !this.isMarker()) { // CraftBukkit
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f, true, this.armorStandInvisible)) {
+ return false;
+ }
+ // CraftBukkit end
if (damagesource.isExplosion()) {
this.g(damagesource);
- this.die();
+ this.killEntity(); // CraftBukkit - this.die() -> this.killEntity()
return false;
} else if (DamageSource.FIRE.equals(damagesource)) {
if (this.isBurning()) {
@@ -444,7 +485,7 @@
} else if (damagesource.v()) {
this.F();
this.D();
- this.die();
+ this.killEntity(); // CraftBukkit - this.die() -> this.killEntity()
return flag1;
} else {
long i = this.world.getTime();
@@ -455,7 +496,7 @@
} else {
this.f(damagesource);
this.D();
- this.die();
+ this.die(); // CraftBukkit - SPIGOT-4890: remain as this.die() since above damagesource method will call death event
}
return true;
@@ -482,7 +523,7 @@
f1 -= f;
if (f1 <= 0.5F) {
this.g(damagesource);
- this.die();
+ this.killEntity(); // CraftBukkit - this.die() -> this.killEntity()
} else {
this.setHealth(f1);
}
@@ -490,13 +531,13 @@
}
private void f(DamageSource damagesource) {
- Block.a(this.world, new BlockPosition(this), new ItemStack(Items.ARMOR_STAND));
+ drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(new ItemStack(Items.ARMOR_STAND))); // CraftBukkit - add to drops
this.g(damagesource);
}
private void g(DamageSource damagesource) {
this.F();
- this.d(damagesource);
+ // this.d(damagesource); // CraftBukkit - moved down
ItemStack itemstack;
int i;
@@ -504,7 +545,7 @@
for (i = 0; i < this.handItems.size(); ++i) {
itemstack = (ItemStack) this.handItems.get(i);
if (!itemstack.isEmpty()) {
- Block.a(this.world, (new BlockPosition(this)).up(), itemstack);
+ drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
this.handItems.set(i, ItemStack.a);
}
}
@@ -512,10 +553,11 @@
for (i = 0; i < this.armorItems.size(); ++i) {
itemstack = (ItemStack) this.armorItems.get(i);
if (!itemstack.isEmpty()) {
- Block.a(this.world, (new BlockPosition(this)).up(), itemstack);
+ drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
this.armorItems.set(i, ItemStack.a);
}
}
+ this.d(damagesource); // CraftBukkit - moved from above
}
@@ -616,8 +658,16 @@
return this.isSmall();
}
+ // CraftBukkit start
+ @Override
+ protected boolean isDropExperience() {
+ return true; // MC-157395, SPIGOT-5193 even baby (small) armor stands should drop
+ }
+ // CraftBukkit end
+
@Override
public void killEntity() {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, drops); // CraftBukkit - call event
this.die();
}