2021-06-11 14:02:28 +02:00
|
|
|
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
|
2021-06-14 04:41:44 +02:00
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2021-11-24 18:58:26 +01:00
|
|
|
index c81364946460a6366bf70457c2025d4275f50f77..2395fa36a230ee48f6b86b60121217d0c60f5327 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2021-11-24 18:58:26 +01:00
|
|
|
@@ -523,5 +523,52 @@ public class PaperWorldConfig {
|
2021-11-24 10:01:27 +01:00
|
|
|
private void lightQueueSize() {
|
|
|
|
lightQueueSize = getInt("light-queue-size", lightQueueSize);
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2021-11-24 10:01:27 +01:00
|
|
|
-}
|
2021-06-15 15:20:52 +02:00
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public boolean altItemDespawnRateEnabled;
|
2021-06-15 15:20:52 +02:00
|
|
|
+ public java.util.Map<org.bukkit.Material, Integer> altItemDespawnRateMap;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ private void altItemDespawnRate() {
|
|
|
|
+ String path = "alt-item-despawn-rate";
|
|
|
|
+
|
|
|
|
+ altItemDespawnRateEnabled = getBoolean(path + ".enabled", false);
|
|
|
|
+
|
2021-06-15 15:20:52 +02:00
|
|
|
+ java.util.Map<org.bukkit.Material, Integer> altItemDespawnRateMapDefault = new java.util.EnumMap<>(org.bukkit.Material.class);
|
|
|
|
+ altItemDespawnRateMapDefault.put(org.bukkit.Material.COBBLESTONE, 300);
|
|
|
|
+ for (org.bukkit.Material key : altItemDespawnRateMapDefault.keySet()) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ config.addDefault("world-settings.default." + path + ".items." + key, altItemDespawnRateMapDefault.get(key));
|
|
|
|
+ }
|
|
|
|
+
|
2021-06-15 15:20:52 +02:00
|
|
|
+ java.util.Map<String, Integer> rawMap = new java.util.HashMap<>();
|
2021-06-11 14:02:28 +02:00
|
|
|
+ try {
|
2021-06-15 15:20:52 +02:00
|
|
|
+ org.bukkit.configuration.ConfigurationSection mapSection = config.getConfigurationSection("world-settings." + worldName + "." + path + ".items");
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (mapSection == null) {
|
|
|
|
+ mapSection = config.getConfigurationSection("world-settings.default." + path + ".items");
|
|
|
|
+ }
|
|
|
|
+ for (String key : mapSection.getKeys(false)) {
|
|
|
|
+ int val = mapSection.getInt(key);
|
|
|
|
+ rawMap.put(key, val);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e) {
|
|
|
|
+ logError("alt-item-despawn-rate was malformatted");
|
|
|
|
+ altItemDespawnRateEnabled = false;
|
|
|
|
+ }
|
|
|
|
+
|
2021-06-15 15:20:52 +02:00
|
|
|
+ altItemDespawnRateMap = new java.util.EnumMap<>(org.bukkit.Material.class);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (!altItemDespawnRateEnabled) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for(String key : rawMap.keySet()) {
|
|
|
|
+ try {
|
2021-06-15 15:20:52 +02:00
|
|
|
+ altItemDespawnRateMap.put(org.bukkit.Material.valueOf(key), rawMap.get(key));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logError("Could not add item " + key + " to altItemDespawnRateMap: " + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(altItemDespawnRateEnabled) {
|
2021-06-15 15:20:52 +02:00
|
|
|
+ for(org.bukkit.Material key : altItemDespawnRateMap.keySet()) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ log("Alternative item despawn rate of " + key + ": " + altItemDespawnRateMap.get(key));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
2021-11-24 10:01:27 +01:00
|
|
|
+}
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
2021-11-24 10:01:27 +01:00
|
|
|
index 1378c8ab35b3828f7c0ad504e64bb72484a1026d..5a6534904e977b5ffbd55d05c4b65f02b3995910 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
2021-11-24 10:01:27 +01:00
|
|
|
@@ -174,7 +174,7 @@ public class ItemEntity extends Entity {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (!this.level.isClientSide && this.age >= level.spigotConfig.itemDespawnRate) { // Spigot
|
|
|
|
+ if (!this.level.isClientSide && this.age >= this.getDespawnRate()) { // Spigot // Paper
|
|
|
|
// CraftBukkit start - fire ItemDespawnEvent
|
|
|
|
if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
|
|
|
|
this.age = 0;
|
2021-11-24 10:01:27 +01:00
|
|
|
@@ -198,7 +198,7 @@ public class ItemEntity extends Entity {
|
2021-06-11 14:02:28 +02:00
|
|
|
this.lastTick = MinecraftServer.currentTick;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
- if (!this.level.isClientSide && this.age >= level.spigotConfig.itemDespawnRate) { // Spigot
|
|
|
|
+ if (!this.level.isClientSide && this.age >= this.getDespawnRate()) { // Spigot // Paper
|
|
|
|
// CraftBukkit start - fire ItemDespawnEvent
|
|
|
|
if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
|
|
|
|
this.age = 0;
|
2021-11-24 10:01:27 +01:00
|
|
|
@@ -558,9 +558,16 @@ public class ItemEntity extends Entity {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
public void makeFakeItem() {
|
|
|
|
this.setNeverPickUp();
|
|
|
|
- this.age = level.spigotConfig.itemDespawnRate - 1; // Spigot
|
2021-06-14 04:41:44 +02:00
|
|
|
+ this.age = this.getDespawnRate() - 1; // Spigot
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ public int getDespawnRate(){
|
2021-06-14 04:41:44 +02:00
|
|
|
+ org.bukkit.Material material = this.getItem().getBukkitStack().getType();
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return level.paperConfig.altItemDespawnRateMap.getOrDefault(material, level.spigotConfig.itemDespawnRate);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
2021-06-14 04:41:44 +02:00
|
|
|
public float getSpin(float tickDelta) {
|
|
|
|
return ((float) this.getAge() + tickDelta) / 20.0F + this.bobOffs;
|
|
|
|
}
|