Skip to content

Commit 7f31095

Browse files
authored
Add more Campfire API (#5779)
1 parent d8747c1 commit 7f31095

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: LemonCaramel <admin@caramel.moe>
3+
Date: Fri, 16 Jul 2021 00:38:52 +0900
4+
Subject: [PATCH] Add more Campfire API
5+
6+
7+
diff --git a/src/main/java/org/bukkit/block/Campfire.java b/src/main/java/org/bukkit/block/Campfire.java
8+
index f8a344cabb7b5a6d1c5409798a0a98b023bcd756..9c3952459ed216f727b3654b2ed536f17f320402 100644
9+
--- a/src/main/java/org/bukkit/block/Campfire.java
10+
+++ b/src/main/java/org/bukkit/block/Campfire.java
11+
@@ -69,4 +69,40 @@ public interface Campfire extends TileState {
12+
* @param cookTimeTotal Cook time total
13+
*/
14+
void setCookTimeTotal(int index, int cookTimeTotal);
15+
+
16+
+ // Paper start
17+
+ /**
18+
+ * Disable cooking in all slots.
19+
+ */
20+
+ void stopCooking();
21+
+
22+
+ /**
23+
+ * Re-enable cooking in all slots.
24+
+ */
25+
+ void startCooking();
26+
+
27+
+ /**
28+
+ * Disable cooking in the specified slot index.
29+
+ *
30+
+ * @param index item slot index
31+
+ * @return whether the slot had cooking enabled before this call
32+
+ */
33+
+ boolean stopCooking(int index);
34+
+
35+
+ /**
36+
+ * Re-enable cooking in the specified slot index.
37+
+ *
38+
+ * @param index item slot index
39+
+ * @return whether the slot couldn't cook before this call
40+
+ */
41+
+ boolean startCooking(int index);
42+
+
43+
+ /**
44+
+ * State of slot index.
45+
+ *
46+
+ * @param index item slot index
47+
+ * @return {@code true} if the specified slot index cannot cook
48+
+ */
49+
+ boolean isCookingDisabled(int index);
50+
+ // Paper end
51+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: LemonCaramel <admin@caramel.moe>
3+
Date: Fri, 16 Jul 2021 00:39:03 +0900
4+
Subject: [PATCH] Add more Campfire API
5+
6+
7+
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
8+
index 7c48b26dc4baa3b4046840356132170c6e05a1d6..073ec046c1c09436dfca34045acc5df12ab82eda 100644
9+
--- a/src/main/java/net/minecraft/world/level/block/entity/CampfireBlockEntity.java
10+
+++ b/src/main/java/net/minecraft/world/level/block/entity/CampfireBlockEntity.java
11+
@@ -32,12 +32,14 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable {
12+
private final NonNullList<ItemStack> items;
13+
public final int[] cookingProgress;
14+
public final int[] cookingTime;
15+
+ public final boolean[] stopCooking; // Paper
16+
17+
public CampfireBlockEntity(BlockPos pos, BlockState state) {
18+
super(BlockEntityType.CAMPFIRE, pos, state);
19+
this.items = NonNullList.withSize(4, ItemStack.EMPTY);
20+
this.cookingProgress = new int[4];
21+
this.cookingTime = new int[4];
22+
+ this.stopCooking = new boolean[4]; // Paper
23+
}
24+
25+
public static void cookTick(Level world, BlockPos pos, BlockState state, CampfireBlockEntity campfire) {
26+
@@ -48,7 +50,9 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable {
27+
28+
if (!itemstack.isEmpty()) {
29+
flag = true;
30+
+ if (!campfire.stopCooking[i]) { // Paper
31+
int j = campfire.cookingProgress[i]++;
32+
+ } // Paper
33+
34+
if (campfire.cookingProgress[i] >= campfire.cookingTime[i]) {
35+
SimpleContainer inventorysubcontainer = new SimpleContainer(new ItemStack[]{itemstack});
36+
@@ -155,6 +159,16 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable {
37+
System.arraycopy(aint, 0, this.cookingTime, 0, Math.min(this.cookingTime.length, aint.length));
38+
}
39+
40+
+ // Paper start
41+
+ if (nbt.contains("Paper.StopCooking", org.bukkit.craftbukkit.util.CraftMagicNumbers.NBT.TAG_BYTE_ARRAY)) {
42+
+ byte[] abyte = nbt.getByteArray("Paper.StopCooking");
43+
+ boolean[] cookingState = new boolean[4];
44+
+ for (int index = 0; index < abyte.length; index++) {
45+
+ cookingState[index] = abyte[index] == 1;
46+
+ }
47+
+ System.arraycopy(cookingState, 0, this.stopCooking, 0, Math.min(this.stopCooking.length, abyte.length));
48+
+ }
49+
+ // Paper end
50+
}
51+
52+
@Override
53+
@@ -163,6 +177,13 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable {
54+
ContainerHelper.saveAllItems(nbt, this.items, true);
55+
nbt.putIntArray("CookingTimes", this.cookingProgress);
56+
nbt.putIntArray("CookingTotalTimes", this.cookingTime);
57+
+ // Paper start
58+
+ byte[] cookingState = new byte[4];
59+
+ for (int index = 0; index < cookingState.length; index++) {
60+
+ cookingState[index] = (byte) (this.stopCooking[index] ? 1 : 0);
61+
+ }
62+
+ nbt.putByteArray("Paper.StopCooking", cookingState);
63+
+ // Paper end
64+
}
65+
66+
@Override
67+
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCampfire.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCampfire.java
68+
index 391ff41951f51a5f9225bf4a9e28c0a4d064d8c9..eafba0532920a3162575dbe656e07734605590f5 100644
69+
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCampfire.java
70+
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCampfire.java
71+
@@ -47,4 +47,40 @@ public class CraftCampfire extends CraftBlockEntityState<CampfireBlockEntity> im
72+
public void setCookTimeTotal(int index, int cookTimeTotal) {
73+
getSnapshot().cookingTime[index] = cookTimeTotal;
74+
}
75+
+
76+
+ // Paper start
77+
+ @Override
78+
+ public void stopCooking() {
79+
+ for (int i = 0; i < getSnapshot().stopCooking.length; ++i)
80+
+ this.stopCooking(i);
81+
+ }
82+
+
83+
+ @Override
84+
+ public void startCooking() {
85+
+ for (int i = 0; i < getSnapshot().stopCooking.length; ++i)
86+
+ this.startCooking(i);
87+
+ }
88+
+
89+
+ @Override
90+
+ public boolean stopCooking(int index) {
91+
+ org.apache.commons.lang.Validate.isTrue(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)");
92+
+ boolean previous = this.isCookingDisabled(index);
93+
+ getSnapshot().stopCooking[index] = true;
94+
+ return previous;
95+
+ }
96+
+
97+
+ @Override
98+
+ public boolean startCooking(int index) {
99+
+ org.apache.commons.lang.Validate.isTrue(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)");
100+
+ boolean previous = this.isCookingDisabled(index);
101+
+ getSnapshot().stopCooking[index] = false;
102+
+ return previous;
103+
+ }
104+
+
105+
+ @Override
106+
+ public boolean isCookingDisabled(int index) {
107+
+ org.apache.commons.lang.Validate.isTrue(-1 < index && index < 4, "Slot index must be between 0 (incl) to 3 (incl)");
108+
+ return getSnapshot().stopCooking[index];
109+
+ }
110+
+ // Paper end
111+
}

0 commit comments

Comments
 (0)