Implement furnace cook speed multiplier API. (#1437)

Adds methods `Furnace#getCookSpeedMultiplier()` and
`Furnace#setCookSpeedMultiplier(double)`.

This PR is basically 3516ae34ef for 1.13.

A test plugin may be found [here](https://gist.github.com/supertassu/fade0cce946261732c6299e1ec89290e).
This commit is contained in:
Tassu 2018-09-18 01:53:27 +03:00 committed by Daniel Ennis
parent f95ffce1af
commit 03c8b8ec27
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,41 @@
From 22461a04950e5ef28f7cd61b5d28b091759234d0 Mon Sep 17 00:00:00 2001
From: Tassu <git@tassu.me>
Date: Thu, 13 Sep 2018 08:45:01 +0300
Subject: [PATCH] Implement furnace cook speed multiplier API
Signed-off-by: Tassu <git@tassu.me>
diff --git a/src/main/java/org/bukkit/block/Furnace.java b/src/main/java/org/bukkit/block/Furnace.java
index ee8a95601..437c7c4fd 100644
--- a/src/main/java/org/bukkit/block/Furnace.java
+++ b/src/main/java/org/bukkit/block/Furnace.java
@@ -36,6 +36,26 @@ public interface Furnace extends Container, Nameable {
*/
public void setCookTime(short cookTime);
+ // Paper start
+ /**
+ * Gets the cook speed multiplier that this {@link Furnace} will cook
+ * compared to vanilla.
+ *
+ * @return the multiplier, a value between 0 and 200
+ */
+ public double getCookSpeedMultiplier();
+
+ /**
+ * Sets the speed multiplier that this {@link Furnace} will cook
+ * compared to vanilla.
+ *
+ * @param multiplier the multiplier to set, a value between 0 and 200
+ * @throws IllegalArgumentException if value is less than 0
+ * @throws IllegalArgumentException if value is more than 200
+ */
+ public void setCookSpeedMultiplier(double multiplier);
+ // Paper end
+
@Override
public FurnaceInventory getInventory();
--
2.19.0

View File

@ -0,0 +1,84 @@
From a67af428c096543ff34c11bd1b292d72a025f514 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 c439b20c80..a537d35b73 100644
--- a/src/main/java/net/minecraft/server/TileEntityFurnace.java
+++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java
@@ -11,6 +11,7 @@ import java.util.Map.Entry;
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;
@@ -27,6 +28,7 @@ public class TileEntityFurnace extends TileEntityContainer implements IWorldInve
private NonNullList<ItemStack> items;
private int burnTime;
private int ticksForCurrentFuel;
+ public double cookSpeedMultiplier = 1.0; // Paper - cook speed multiplier API
private int cookTime;
private int cookTimeTotal;
private IChatBaseComponent l;
@@ -220,6 +222,11 @@ public class TileEntityFurnace extends TileEntityContainer implements IWorldInve
this.l = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
}
+ // Paper start - cook speed API
+ if (nbttagcompound.hasKey("Paper.CookSpeedMultiplier")) {
+ this.cookSpeedMultiplier = nbttagcompound.getDouble("Paper.CookSpeedMultiplier");
+ }
+ // Paper end
}
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
@@ -227,6 +234,7 @@ public class TileEntityFurnace extends TileEntityContainer implements IWorldInve
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.setShort("RecipesUsedSize", (short) this.m.size());
int i = 0;
@@ -301,8 +309,8 @@ public class TileEntityFurnace extends TileEntityContainer implements IWorldInve
}
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.s();
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 469dc4ff2b..0ffbe8cd64 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
@@ -71,4 +71,18 @@ public class CraftFurnace extends CraftContainer<TileEntityFurnace> implements F
furnace.setCustomName(null);
}
}
+
+ // 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
}
--
2.19.0