mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Add more Campfire API
This commit is contained in:
parent
8e42edf892
commit
c5e4146598
2 changed files with 90 additions and 2 deletions
|
@ -15,7 +15,28 @@
|
|||
public class CampfireBlockEntity extends BlockEntity implements Clearable {
|
||||
|
||||
private static final int BURN_COOL_SPEED = 2;
|
||||
@@ -58,12 +66,36 @@
|
||||
@@ -38,12 +46,14 @@
|
||||
private final NonNullList<ItemStack> items;
|
||||
public final int[] cookingProgress;
|
||||
public final int[] cookingTime;
|
||||
+ public final boolean[] stopCooking; // Paper - Add more Campfire API
|
||||
|
||||
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 - Add more Campfire API
|
||||
}
|
||||
|
||||
public static void cookTick(ServerLevel world, BlockPos pos, BlockState state, CampfireBlockEntity blockEntity, RecipeManager.CachedCheck<SingleRecipeInput, CampfireCookingRecipe> recipeMatchGetter) {
|
||||
@@ -54,16 +64,42 @@
|
||||
|
||||
if (!itemstack.isEmpty()) {
|
||||
flag = true;
|
||||
+ if (!blockEntity.stopCooking[i]) { // Paper - Add more Campfire API
|
||||
int j = blockEntity.cookingProgress[i]++;
|
||||
+ } // Paper - Add more Campfire API
|
||||
|
||||
if (blockEntity.cookingProgress[i] >= blockEntity.cookingTime[i]) {
|
||||
SingleRecipeInput singlerecipeinput = new SingleRecipeInput(itemstack);
|
||||
|
@ -54,7 +75,38 @@
|
|||
blockEntity.items.set(i, ItemStack.EMPTY);
|
||||
world.sendBlockUpdated(pos, state, state, 3);
|
||||
world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(state));
|
||||
@@ -177,7 +209,11 @@
|
||||
@@ -143,6 +179,16 @@
|
||||
System.arraycopy(aint, 0, this.cookingTime, 0, Math.min(this.cookingTime.length, aint.length));
|
||||
}
|
||||
|
||||
+ // Paper start - Add more Campfire API
|
||||
+ 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 - Add more Campfire API
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,6 +197,13 @@
|
||||
ContainerHelper.saveAllItems(nbt, this.items, true, registries);
|
||||
nbt.putIntArray("CookingTimes", this.cookingProgress);
|
||||
nbt.putIntArray("CookingTotalTimes", this.cookingTime);
|
||||
+ // Paper start - Add more Campfire API
|
||||
+ 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 - Add more Campfire API
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,7 +230,11 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,4 +62,40 @@ public class CraftCampfire extends CraftBlockEntityState<CampfireBlockEntity> im
|
|||
public CraftCampfire copy(Location location) {
|
||||
return new CraftCampfire(this, location);
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue