aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/unapplied/server/0338-Implement-alternative-item-despawn-rate.patch
blob: e0c9184ee5353d47c62060cb2c3fd3941264e1c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: kickash32 <kickash32@gmail.com>
Date: Mon, 3 Jun 2019 02:02:39 -0400
Subject: [PATCH] Implement alternative item-despawn-rate

Co-authored-by: Noah van der Aa <ndvdaa@gmail.com>

diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
index 9b9d491c7c41590c93d606414902329b6636419f..a7eccb2f364ed633cb6d4914491eb686ff02e647 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -54,6 +54,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
     public final float bobOffs;
     private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
     public boolean canMobPickup = true; // Paper
+    private int despawnRate = -1; // Paper
 
     public ItemEntity(EntityType<? extends ItemEntity> type, Level world) {
         super(type, world);
@@ -190,7 +191,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
                 }
             }
 
-            if (!this.level().isClientSide && this.age >= this.level().spigotConfig.itemDespawnRate) { // Spigot
+            if (!this.level().isClientSide && this.age >= this.despawnRate) { // Spigot // Paper
                 // CraftBukkit start - fire ItemDespawnEvent
                 if (CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
                     this.age = 0;
@@ -214,7 +215,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
         this.lastTick = MinecraftServer.currentTick;
         // CraftBukkit end
 
-        if (!this.level().isClientSide && this.age >= this.level().spigotConfig.itemDespawnRate) { // Spigot
+        if (!this.level().isClientSide && this.age >= this.despawnRate) { // Spigot // Paper
             // CraftBukkit start - fire ItemDespawnEvent
             if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
                 this.age = 0;
@@ -270,7 +271,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
     private boolean isMergable() {
         ItemStack itemstack = this.getItem();
 
-        return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < 6000 && itemstack.getCount() < itemstack.getMaxStackSize();
+        return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < itemstack.getMaxStackSize(); // Paper - respect despawn rate in pickup check.
     }
 
     private void tryToMerge(ItemEntity other) {
@@ -512,6 +513,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
 
     public void setItem(ItemStack stack) {
         this.getEntityData().set(ItemEntity.DATA_ITEM, stack);
+        this.despawnRate = this.level().paperConfig().entities.spawning.altItemDespawnRate.enabled ? this.level().paperConfig().entities.spawning.altItemDespawnRate.items.getOrDefault(stack.getItem(), this.level().spigotConfig.itemDespawnRate) : this.level().spigotConfig.itemDespawnRate; // Paper
     }
 
     @Override
@@ -565,7 +567,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
 
     public void makeFakeItem() {
         this.setNeverPickUp();
-        this.age = this.level().spigotConfig.itemDespawnRate - 1; // Spigot
+        this.age = this.despawnRate - 1; // Spigot // Paper
     }
 
     public float getSpin(float tickDelta) {