aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0294-Implement-furnace-cook-speed-multiplier-API.patch
blob: a5612b1d3e578801bb3469635f10943fa48157c2 (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tassu <git@tassu.me>
Date: Thu, 13 Sep 2018 08:45:21 +0300
Subject: [PATCH] Implement furnace cook speed multiplier API

Signed-off-by: Tassu <git@tassu.me>

diff --git a/src/main/java/net/minecraft/server/TileEntityFurnace.java b/src/main/java/net/minecraft/server/TileEntityFurnace.java
index 623cd63711c6cb79dce7a46056e193fdb13334a5..f4f50fb8375fec3f6868bbccc50bc78a5cd81965 100644
--- a/src/main/java/net/minecraft/server/TileEntityFurnace.java
+++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java
@@ -10,6 +10,7 @@ import java.util.List;
 import java.util.Map;
 import javax.annotation.Nullable;
 // CraftBukkit start
+import java.util.List;
 import org.bukkit.craftbukkit.block.CraftBlock;
 import org.bukkit.craftbukkit.entity.CraftHumanEntity;
 import org.bukkit.craftbukkit.inventory.CraftItemStack;
@@ -28,6 +29,7 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I
     protected NonNullList<ItemStack> items;
     public int burnTime;
     private int ticksForCurrentFuel;
+    public double cookSpeedMultiplier = 1.0; // Paper - cook speed multiplier API
     public int cookTime;
     public int cookTimeTotal;
     protected final IContainerProperties b;
@@ -228,6 +230,11 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I
             this.n.put(new MinecraftKey(s), nbttagcompound1.getInt(s));
         }
 
+        // Paper start - cook speed API
+        if (nbttagcompound.hasKey("Paper.CookSpeedMultiplier")) {
+            this.cookSpeedMultiplier = nbttagcompound.getDouble("Paper.CookSpeedMultiplier");
+        }
+        // Paper end
     }
 
     @Override
@@ -236,6 +243,7 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I
         nbttagcompound.setShort("BurnTime", (short) this.burnTime);
         nbttagcompound.setShort("CookTime", (short) this.cookTime);
         nbttagcompound.setShort("CookTimeTotal", (short) this.cookTimeTotal);
+        nbttagcompound.setDouble("Paper.CookSpeedMultiplier", this.cookSpeedMultiplier); // Paper - cook speed multiplier API
         ContainerUtil.a(nbttagcompound, this.items);
         NBTTagCompound nbttagcompound1 = new NBTTagCompound();
 
@@ -295,8 +303,8 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I
                 }
 
                 if (this.isBurning() && this.canBurn(irecipe)) {
-                    ++this.cookTime;
-                    if (this.cookTime == this.cookTimeTotal) {
+                    this.cookTime += cookSpeedMultiplier; // Paper - cook speed multiplier API
+                    if (this.cookTime >= this.cookTimeTotal) { // Paper - cook speed multiplier API
                         this.cookTime = 0;
                         this.cookTimeTotal = this.getRecipeCookingTime();
                         this.burn(irecipe);
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
index 27c8cc130e7466c396b514dd77f1385f967bebdb..05643f6cd28d22680a18c8b742af8e5e945d1503 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
@@ -63,4 +63,18 @@ public abstract class CraftFurnace<T extends TileEntityFurnace> extends CraftCon
     public void setCookTimeTotal(int cookTimeTotal) {
         this.getSnapshot().cookTimeTotal = cookTimeTotal;
     }
+
+    // Paper start - cook speed multiplier API
+    @Override
+    public double getCookSpeedMultiplier() {
+        return this.getSnapshot().cookSpeedMultiplier;
+    }
+
+    @Override
+    public void setCookSpeedMultiplier(double multiplier) {
+        com.google.common.base.Preconditions.checkArgument(multiplier >= 0, "Furnace speed multiplier cannot be negative");
+        com.google.common.base.Preconditions.checkArgument(multiplier <= 200, "Furnace speed multiplier cannot more than 200");
+        this.getSnapshot().cookSpeedMultiplier = multiplier;
+    }
+    // Paper end
 }