3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 04:20:08 +01:00
Paper/nms-patches/EntityItem.patch

107 Zeilen
4.4 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityItem.java
+++ b/net/minecraft/server/EntityItem.java
2016-11-17 02:41:03 +01:00
@@ -4,6 +4,7 @@
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.bukkit.event.player.PlayerPickupItemEvent; // CraftBukkit
public class EntityItem extends Entity {
2016-11-17 02:41:03 +01:00
@@ -15,6 +16,7 @@
private String g;
2016-02-29 22:32:46 +01:00
private String h;
public float a;
2016-11-25 00:31:53 +01:00
+ private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
public EntityItem(World world, double d0, double d1, double d2) {
super(world);
2016-11-25 00:31:53 +01:00
@@ -54,9 +56,12 @@
this.die();
} else {
2016-11-17 02:41:03 +01:00
super.A_();
- if (this.pickupDelay > 0 && this.pickupDelay != 32767) {
- --this.pickupDelay;
- }
+ // CraftBukkit start - Use wall time for pickup and despawn timers
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
2015-02-26 23:41:06 +01:00
+ if (this.pickupDelay != 32767) this.pickupDelay -= elapsedTicks;
+ if (this.age != -32768) this.age += elapsedTicks;
+ this.lastTick = MinecraftServer.currentTick;
+ // CraftBukkit end
this.lastX = this.locX;
this.lastY = this.locY;
2016-11-25 00:31:53 +01:00
@@ -104,9 +109,11 @@
this.motY *= -0.5D;
}
+ /* Craftbukkit start - moved up
if (this.age != -32768) {
++this.age;
}
+ // Craftbukkit end */
2016-06-09 03:43:49 +02:00
this.ak();
2016-11-17 02:41:03 +01:00
if (!this.world.isClientSide) {
2016-11-25 00:31:53 +01:00
@@ -121,6 +128,12 @@
2016-11-17 02:41:03 +01:00
}
2015-02-26 23:41:06 +01:00
if (!this.world.isClientSide && this.age >= 6000) {
+ // CraftBukkit start - fire ItemDespawnEvent
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
+ this.age = 0;
+ return;
+ }
+ // CraftBukkit end
this.die();
}
2016-11-25 00:31:53 +01:00
@@ -162,6 +175,7 @@
2016-11-17 02:41:03 +01:00
} else if (itemstack1.getCount() + itemstack.getCount() > itemstack1.getMaxStackSize()) {
2015-06-26 11:55:33 +02:00
return false;
} else {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemMergeEvent(this, entityitem).isCancelled()) return false; // CraftBukkit
2016-11-17 02:41:03 +01:00
itemstack1.add(itemstack.getCount());
2015-06-26 11:55:33 +02:00
entityitem.pickupDelay = Math.max(entityitem.pickupDelay, this.pickupDelay);
entityitem.age = Math.min(entityitem.age, this.age);
2016-11-25 00:31:53 +01:00
@@ -208,6 +222,11 @@
2016-11-17 02:41:03 +01:00
} else if (!this.getItemStack().isEmpty() && this.getItemStack().getItem() == Items.NETHER_STAR && damagesource.isExplosion()) {
return false;
} else {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f)) {
+ return false;
+ }
+ // CraftBukkit end
2016-06-09 03:43:49 +02:00
this.ap();
2016-02-29 22:32:46 +01:00
this.f = (int) ((float) this.f - f);
if (this.f <= 0) {
2016-11-25 00:31:53 +01:00
@@ -270,6 +289,26 @@
2016-11-17 02:41:03 +01:00
Item item = itemstack.getItem();
int i = itemstack.getCount();
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - fire PlayerPickupItemEvent
+ int canHold = entityhuman.inventory.canHold(itemstack);
2016-11-17 02:41:03 +01:00
+ int remaining = i - canHold;
+
+ if (this.pickupDelay <= 0 && canHold > 0) {
2016-11-17 02:41:03 +01:00
+ itemstack.setCount(canHold);
+ PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining);
+ // event.setCancelled(!entityhuman.canPickUpLoot); TODO
+ this.world.getServer().getPluginManager().callEvent(event);
2016-11-17 02:41:03 +01:00
+ itemstack.setCount(canHold + remaining);
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ // Possibly < 0; fix here so we do not have to modify code below
+ this.pickupDelay = 0;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2016-02-29 22:32:46 +01:00
if (this.pickupDelay == 0 && (this.h == null || 6000 - this.age <= 200 || this.h.equals(entityhuman.getName())) && entityhuman.inventory.pickup(itemstack)) {
2016-11-17 02:41:03 +01:00
if (item == Item.getItemOf(Blocks.LOG)) {
2015-02-26 23:41:06 +01:00
entityhuman.b((Statistic) AchievementList.g);