aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0364-Mob-Spawner-API-Enhancements.patch
blob: a36af687a121c09ff8e2a730229af6243c6d83da (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Fri, 19 Apr 2019 12:41:13 -0500
Subject: [PATCH] Mob Spawner API Enhancements


diff --git a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
index cb7cb789b82461093fbbb4c8ae6d03fcbfe57383..41001b02a654194c4a8e25ad5f7af8fdd91090b2 100644
--- a/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerAbstract.java
@@ -47,6 +47,7 @@ public abstract class MobSpawnerAbstract {
         this.mobs.clear(); // CraftBukkit - SPIGOT-3496, MC-92282
     }
 
+    public boolean isActivated() { return h(); } // Paper - OBFHELPER
     private boolean h() {
         BlockPosition blockposition = this.b();
 
@@ -207,6 +208,7 @@ public abstract class MobSpawnerAbstract {
         }
     }
 
+    public void resetTimer() { i(); } // Paper - OBFHELPER
     private void i() {
         if (this.maxSpawnDelay <= this.minSpawnDelay) {
             this.spawnDelay = this.minSpawnDelay;
@@ -224,7 +226,13 @@ public abstract class MobSpawnerAbstract {
     }
 
     public void a(NBTTagCompound nbttagcompound) {
+        // Paper start - use larger int if set
+        if (nbttagcompound.hasKey("Paper.Delay")) {
+            this.spawnDelay = nbttagcompound.getInt("Paper.Delay");
+        } else {
         this.spawnDelay = nbttagcompound.getShort("Delay");
+        }
+        // Paper end
         this.mobs.clear();
         if (nbttagcompound.hasKeyOfType("SpawnPotentials", 9)) {
             NBTTagList nbttaglist = nbttagcompound.getList("SpawnPotentials", 10);
@@ -239,10 +247,15 @@ public abstract class MobSpawnerAbstract {
         } else if (!this.mobs.isEmpty()) {
             this.setSpawnData((MobSpawnerData) WeightedRandom.a(this.a().random, this.mobs));
         }
-
+        // Paper start - use ints if set
+        if (nbttagcompound.hasKeyOfType("Paper.MinSpawnDelay", 99)) {
+            this.minSpawnDelay = nbttagcompound.getInt("Paper.MinSpawnDelay");
+            this.maxSpawnDelay = nbttagcompound.getInt("Paper.MaxSpawnDelay");
+            this.spawnCount = nbttagcompound.getShort("SpawnCount");
+        } else // Paper end
         if (nbttagcompound.hasKeyOfType("MinSpawnDelay", 99)) {
-            this.minSpawnDelay = nbttagcompound.getShort("MinSpawnDelay");
-            this.maxSpawnDelay = nbttagcompound.getShort("MaxSpawnDelay");
+            this.minSpawnDelay = nbttagcompound.getInt("MinSpawnDelay");
+            this.maxSpawnDelay = nbttagcompound.getInt("MaxSpawnDelay");
             this.spawnCount = nbttagcompound.getShort("SpawnCount");
         }
 
@@ -267,9 +280,20 @@ public abstract class MobSpawnerAbstract {
         if (minecraftkey == null) {
             return nbttagcompound;
         } else {
-            nbttagcompound.setShort("Delay", (short) this.spawnDelay);
-            nbttagcompound.setShort("MinSpawnDelay", (short) this.minSpawnDelay);
-            nbttagcompound.setShort("MaxSpawnDelay", (short) this.maxSpawnDelay);
+            // Paper start
+            if (spawnDelay > Short.MAX_VALUE) {
+                nbttagcompound.setInt("Paper.Delay", this.spawnDelay);
+            }
+            nbttagcompound.setShort("Delay", (short) Math.min(Short.MAX_VALUE, this.spawnDelay));
+
+            if (minSpawnDelay > Short.MAX_VALUE || maxSpawnDelay > Short.MAX_VALUE) {
+                nbttagcompound.setInt("Paper.MinSpawnDelay", this.minSpawnDelay);
+                nbttagcompound.setInt("Paper.MaxSpawnDelay", this.maxSpawnDelay);
+            }
+
+            nbttagcompound.setShort("MinSpawnDelay", (short) Math.min(Short.MAX_VALUE, this.minSpawnDelay));
+            nbttagcompound.setShort("MaxSpawnDelay", (short) Math.min(Short.MAX_VALUE, this.maxSpawnDelay));
+            // Paper end
             nbttagcompound.setShort("SpawnCount", (short) this.spawnCount);
             nbttagcompound.setShort("MaxNearbyEntities", (short) this.maxNearbyEntities);
             nbttagcompound.setShort("RequiredPlayerRange", (short) this.requiredPlayerRange);
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
index 5c4c3c70c7450a3e556d664a1bf6bcaf8e3a571c..e78e3804bad9b0b6004939cadf40465dec68fdba 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
@@ -121,4 +121,16 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
     public void setSpawnRange(int spawnRange) {
         this.getSnapshot().getSpawner().spawnRange = spawnRange;
     }
+
+    // Paper start
+    @Override
+    public boolean isActivated() {
+        return this.getSnapshot().getSpawner().isActivated();
+    }
+
+    @Override
+    public void resetTimer() {
+        this.getSnapshot().getSpawner().resetTimer();
+    }
+    // Paper end
 }