diff options
author | LemonCaramel <[email protected]> | 2021-12-14 05:57:39 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2021-12-13 12:57:39 -0800 |
commit | 7f310957bc18cc0a54d399bd5b767129058c71a7 (patch) | |
tree | aa6b91f6937ebc80377ef76bea1e34fc8bc6caee | |
parent | d8747c13e5a34b871d0a1c712c0ed6452430562d (diff) | |
download | Paper-7f310957bc18cc0a54d399bd5b767129058c71a7.tar.gz Paper-7f310957bc18cc0a54d399bd5b767129058c71a7.zip |
Add more Campfire API (#5779)
-rw-r--r-- | patches/api/0346-Add-more-Campfire-API.patch | 51 | ||||
-rw-r--r-- | patches/server/0830-Add-more-Campfire-API.patch | 111 |
2 files changed, 162 insertions, 0 deletions
diff --git a/patches/api/0346-Add-more-Campfire-API.patch b/patches/api/0346-Add-more-Campfire-API.patch new file mode 100644 index 0000000000..80cdc0bb39 --- /dev/null +++ b/patches/api/0346-Add-more-Campfire-API.patch @@ -0,0 +1,51 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: LemonCaramel <[email protected]> +Date: Fri, 16 Jul 2021 00:38:52 +0900 +Subject: [PATCH] Add more Campfire API + + +diff --git a/src/main/java/org/bukkit/block/Campfire.java b/src/main/java/org/bukkit/block/Campfire.java +index f8a344cabb7b5a6d1c5409798a0a98b023bcd756..9c3952459ed216f727b3654b2ed536f17f320402 100644 +--- a/src/main/java/org/bukkit/block/Campfire.java ++++ b/src/main/java/org/bukkit/block/Campfire.java +@@ -69,4 +69,40 @@ public interface Campfire extends TileState { + * @param cookTimeTotal Cook time total + */ + void setCookTimeTotal(int index, int cookTimeTotal); ++ ++ // Paper start ++ /** ++ * Disable cooking in all slots. ++ */ ++ void stopCooking(); ++ ++ /** ++ * Re-enable cooking in all slots. ++ */ ++ void startCooking(); ++ ++ /** ++ * Disable cooking in the specified slot index. ++ * ++ * @param index item slot index ++ * @return whether the slot had cooking enabled before this call ++ */ ++ boolean stopCooking(int index); ++ ++ /** ++ * Re-enable cooking in the specified slot index. ++ * ++ * @param index item slot index ++ * @return whether the slot couldn't cook before this call ++ */ ++ boolean startCooking(int index); ++ ++ /** ++ * State of slot index. ++ * ++ * @param index item slot index ++ * @return {@code true} if the specified slot index cannot cook ++ */ ++ boolean isCookingDisabled(int index); ++ // Paper end + } diff --git a/patches/server/0830-Add-more-Campfire-API.patch b/patches/server/0830-Add-more-Campfire-API.patch new file mode 100644 index 0000000000..ceffa1575f --- /dev/null +++ b/patches/server/0830-Add-more-Campfire-API.patch @@ -0,0 +1,111 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: LemonCaramel <[email protected]> +Date: Fri, 16 Jul 2021 00:39:03 +0900 +Subject: [PATCH] Add more Campfire API + + +diff --git a/src/main/java/net/minecraft/world/level/block/entity/CampfireBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/CampfireBlockEntity.java +index 7c48b26dc4baa3b4046840356132170c6e05a1d6..073ec046c1c09436dfca34045acc5df12ab82eda 100644 +--- a/src/main/java/net/minecraft/world/level/block/entity/CampfireBlockEntity.java ++++ b/src/main/java/net/minecraft/world/level/block/entity/CampfireBlockEntity.java +@@ -32,12 +32,14 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable { + private final NonNullList<ItemStack> items; + public final int[] cookingProgress; + public final int[] cookingTime; ++ public final boolean[] stopCooking; // Paper + + public CampfireBlockEntity(BlockPos pos, BlockState state) { + super(BlockEntityType.CAMPFIRE, pos, state); + this.items = NonNullList.withSize(4, ItemStack.EMPTY); + this.cookingProgress = new int[4]; + this.cookingTime = new int[4]; ++ this.stopCooking = new boolean[4]; // Paper + } + + public static void cookTick(Level world, BlockPos pos, BlockState state, CampfireBlockEntity campfire) { +@@ -48,7 +50,9 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable { + + if (!itemstack.isEmpty()) { + flag = true; ++ if (!campfire.stopCooking[i]) { // Paper + int j = campfire.cookingProgress[i]++; ++ } // Paper + + if (campfire.cookingProgress[i] >= campfire.cookingTime[i]) { + SimpleContainer inventorysubcontainer = new SimpleContainer(new ItemStack[]{itemstack}); +@@ -155,6 +159,16 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable { + System.arraycopy(aint, 0, this.cookingTime, 0, Math.min(this.cookingTime.length, aint.length)); + } + ++ // Paper start ++ if (nbt.contains("Paper.StopCooking", org.bukkit.craftbukkit.util.CraftMagicNumbers.NBT.TAG_BYTE_ARRAY)) { ++ byte[] abyte = nbt.getByteArray("Paper.StopCooking"); ++ boolean[] cookingState = new boolean[4]; ++ for (int index = 0; index < abyte.length; index++) { ++ cookingState[index] = abyte[index] == 1; ++ } ++ System.arraycopy(cookingState, 0, this.stopCooking, 0, Math.min(this.stopCooking.length, abyte.length)); ++ } ++ // Paper end + } + + @Override +@@ -163,6 +177,13 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable { + ContainerHelper.saveAllItems(nbt, this.items, true); + nbt.putIntArray("CookingTimes", this.cookingProgress); + nbt.putIntArray("CookingTotalTimes", this.cookingTime); ++ // Paper start ++ byte[] cookingState = new byte[4]; ++ for (int index = 0; index < cookingState.length; index++) { ++ cookingState[index] = (byte) (this.stopCooking[index] ? 1 : 0); ++ } ++ nbt.putByteArray("Paper.StopCooking", cookingState); ++ // Paper end + } + + @Override +diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCampfire.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCampfire.java +index 391ff41951f51a5f9225bf4a9e28c0a4d064d8c9..eafba0532920a3162575dbe656e07734605590f5 100644 +--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCampfire.java ++++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCampfire.java +@@ -47,4 +47,40 @@ public class CraftCampfire extends CraftBlockEntityState<CampfireBlockEntity> im + public void setCookTimeTotal(int index, int cookTimeTotal) { + getSnapshot().cookingTime[index] = cookTimeTotal; + } ++ ++ // Paper start ++ @Override ++ public void stopCooking() { ++ for (int i = 0; i < getSnapshot().stopCooking.length; ++i) ++ this.stopCooking(i); ++ } ++ ++ @Override ++ public void startCooking() { ++ for (int i = 0; i < getSnapshot().stopCooking.length; ++i) ++ this.startCooking(i); ++ } ++ ++ @Override ++ public boolean stopCooking(int index) { ++ org.apache.commons.lang.Validate.isTrue(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)"); ++ boolean previous = this.isCookingDisabled(index); ++ getSnapshot().stopCooking[index] = true; ++ return previous; ++ } ++ ++ @Override ++ public boolean startCooking(int index) { ++ org.apache.commons.lang.Validate.isTrue(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)"); ++ boolean previous = this.isCookingDisabled(index); ++ getSnapshot().stopCooking[index] = false; ++ return previous; ++ } ++ ++ @Override ++ public boolean isCookingDisabled(int index) { ++ org.apache.commons.lang.Validate.isTrue(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)"); ++ return getSnapshot().stopCooking[index]; ++ } ++ // Paper end + } |