PaperMC/patches/server/0763-Add-more-Campfire-API.patch
Jake Potrebic 03a4e7ac75
Updated Upstream (Bukkit/CraftBukkit) (#8832)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
37262de8 PR-812: Add Registry#match(String)
d6b40162 SPIGOT-4569: Add more BlockData API
f9691891 PR-809: Throw a more clear error for BlockIterators with zero direction, add Vector#isZero()
91e79e19 PR-804: Added methods to get translation keys for materials, itemstacks and more
426b00d3 PR-795: Add new BiomeParameterPoint passed to BiomeProvider#getBiome
0e91ea52 SPIGOT-7224: Add events for brewing stands and campfires starting their actions

CraftBukkit Changes:
a50301aa5 Fix issues with fluid tag conversion and fluid #isTagged
6aeb5e4c3 SPIGOT-4569: Implement more BlockData API
7dbf862c2 PR-1131: Added methods to get translation keys for materials, itemstacks and more
7167588b1 PR-1117: Add new BiomeParameterPoint passed to BiomeProvider#getBiome
7c44152eb SPIGOT-7224: Add events for brewing stands and campfires starting their actions
2023-02-15 14:10:14 -08:00

112 lines
5.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: LemonCaramel <admin@caramel.moe>
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 0f7e765263a09a3f8b021bbac8d062c72ab3bdc0..01d8f1c985223eec83beb4a84a710d1bf8d70849 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
@@ -41,6 +41,7 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable {
public final int[] cookingProgress;
public final int[] cookingTime;
private final RecipeManager.CachedCheck<Container, CampfireCookingRecipe> quickCheck;
+ public final boolean[] stopCooking; // Paper
public CampfireBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityType.CAMPFIRE, pos, state);
@@ -48,6 +49,7 @@ public class CampfireBlockEntity extends BlockEntity implements Clearable {
this.cookingProgress = new int[4];
this.cookingTime = new int[4];
this.quickCheck = RecipeManager.createCheck(RecipeType.CAMPFIRE_COOKING);
+ this.stopCooking = new boolean[4]; // Paper
}
public static void cookTick(Level world, BlockPos pos, BlockState state, CampfireBlockEntity campfire) {
@@ -58,7 +60,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});
@@ -167,6 +171,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
@@ -175,6 +189,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
}