Paper/patches/server/0256-Implement-furnace-cook-speed-multiplier-API.patch
Jake Potrebic 8657cd91d7
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10164)
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:
63c208dd Remove no longer used import
70be76c7 PR-958: Further clarify deprecation of TAG_CONTAINER_ARRAY
ae21f4ac PR-955: Add methods to place structures with block/entity transformers
e3d960f2 SPIGOT-7547: Remark that Damageable#setAbsorptionAmount() is capped to a specific value
b125516c Fix typo in RecipeChoice.ExactChoice docs
309497c1 Add EntityMountEvent and EntityDismount Event
2fd45ae3 Improve ItemFactory#enchantItem consistency
2b198268 PR-933: Define native persistent data types for lists

CraftBukkit Changes:
771182f70 PR-1327: Add methods to place structures with block/entity transformers
e41ad4c82 SPIGOT-7567: SpawnReason for SNOWMAN is reported as BUILD_IRONGOLEM
76931e8bd Add EntityMountEvent and EntityDismount Event
9b29b21c7 PR-1183: Better handle lambda expression and renaming of classes in Commodore
1462ebe85 Reformat Commodore.java
9fde4c037 PR-1324: Improve ItemFactory#enchantItem consistency
4e419c774 PR-1295: Define native persistent data types for lists
dd8cca388 SPIGOT-7562: Fix Score#getScore and Score#isScoreSet
690278200 Only fetch an online UUID in online mode
1da8d9a53 Fire PreLogin events even in offline mode
2e88514ad PR-1325: Use CraftBlockType and CraftItemType instead of CraftMagicNumbers to convert between minecraft and bukkit block / item representation

Spigot Changes:
864e4acc Restore accidentally removed package-info.java
f91a10d5 Remove obsolete EntityMountEvent and EntityDismountEvent
828f0593 SPIGOT-7558: Deprecate silenceable lightning API as sound is now client-side and cannot be removed
cdc4e035 Remove obsolete patch fetching correct mode UUIDs
49e36b8e Merge related BungeeCord patches
6e87b9ab Remove obsolete firing of PreLogin events in offline mode
5c76b183 Remove redundant patch dealing with exceptions in the crash reporter
3a2219d1 Remove redundant patch logging cause of unexpected exception
2024-01-14 10:46:04 +01:00

132 lines
8.1 KiB
Diff

From 0000000000000000000000000000000000000000 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>
Fixed an issue where a furnace's cook-speed multiplier rounds down
to the nearest Integer when updating its current cook time.
Modified by: Eric Su <ericsu@alumni.usc.edu>
diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
index 7a13042631bea761952490cfd14dc20147405161..939a192dd66d5fb8da5beada7c22eeca5a7589cd 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
@@ -78,11 +78,13 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
protected NonNullList<ItemStack> items;
public int litTime;
int litDuration;
+ public double cookSpeedMultiplier = 1.0; // Paper - cook speed multiplier API
public int cookingProgress;
public int cookingTotalTime;
protected final ContainerData dataAccess;
public final Object2IntOpenHashMap<ResourceLocation> recipesUsed;
private final RecipeManager.CachedCheck<Container, ? extends AbstractCookingRecipe> quickCheck;
+ public final RecipeType<? extends AbstractCookingRecipe> recipeType; // Paper
protected AbstractFurnaceBlockEntity(BlockEntityType<?> blockEntityType, BlockPos pos, BlockState state, RecipeType<? extends AbstractCookingRecipe> recipeType) {
super(blockEntityType, pos, state);
@@ -129,6 +131,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
};
this.recipesUsed = new Object2IntOpenHashMap();
this.quickCheck = RecipeManager.createCheck((RecipeType<AbstractCookingRecipe>) recipeType); // CraftBukkit - decompile error // Eclipse fail
+ this.recipeType = recipeType; // Paper
}
public static Map<Item, Integer> getFuel() {
@@ -281,6 +284,11 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
this.recipesUsed.put(new ResourceLocation(s), nbttagcompound1.getInt(s));
}
+ // Paper start - cook speed API
+ if (nbt.contains("Paper.CookSpeedMultiplier")) {
+ this.cookSpeedMultiplier = nbt.getDouble("Paper.CookSpeedMultiplier");
+ }
+ // Paper end
}
@Override
@@ -289,6 +297,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
nbt.putShort("BurnTime", (short) this.litTime);
nbt.putShort("CookTime", (short) this.cookingProgress);
nbt.putShort("CookTimeTotal", (short) this.cookingTotalTime);
+ nbt.putDouble("Paper.CookSpeedMultiplier", this.cookSpeedMultiplier); // Paper - cook speed multiplier API
ContainerHelper.saveAllItems(nbt, this.items);
CompoundTag nbttagcompound1 = new CompoundTag();
@@ -360,7 +369,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
CraftItemStack source = CraftItemStack.asCraftMirror(blockEntity.items.get(0));
CookingRecipe<?> recipe = (CookingRecipe<?>) recipeholder.toBukkitRecipe();
- FurnaceStartSmeltEvent event = new FurnaceStartSmeltEvent(CraftBlock.at(world, pos), source, recipe);
+ FurnaceStartSmeltEvent event = new FurnaceStartSmeltEvent(CraftBlock.at(world, pos), source, recipe, AbstractFurnaceBlockEntity.getTotalCookTime(world, blockEntity.recipeType, blockEntity, blockEntity.cookSpeedMultiplier)); // Paper - cook speed multiplier API
world.getCraftServer().getPluginManager().callEvent(event);
blockEntity.cookingTotalTime = event.getTotalCookTime();
@@ -368,9 +377,9 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
// CraftBukkit end
++blockEntity.cookingProgress;
- if (blockEntity.cookingProgress == blockEntity.cookingTotalTime) {
+ if (blockEntity.cookingProgress >= blockEntity.cookingTotalTime) { // Paper - cook speed multiplier API
blockEntity.cookingProgress = 0;
- blockEntity.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(world, blockEntity);
+ blockEntity.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(world, blockEntity.recipeType, blockEntity, blockEntity.cookSpeedMultiplier); // Paper
if (AbstractFurnaceBlockEntity.burn(blockEntity.level, blockEntity.worldPosition, world.registryAccess(), recipeholder, blockEntity.items, i)) { // CraftBukkit
blockEntity.setRecipeUsed(recipeholder);
}
@@ -470,11 +479,12 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
}
}
- private static int getTotalCookTime(Level world, AbstractFurnaceBlockEntity furnace) {
- if (world == null) return 200; // CraftBukkit - SPIGOT-4302
- return (Integer) furnace.quickCheck.getRecipeFor(furnace, world).map((recipeholder) -> {
- return ((AbstractCookingRecipe) recipeholder.value()).getCookingTime();
- }).orElse(200);
+ // Paper start
+ public static int getTotalCookTime(@Nullable Level world, RecipeType<? extends AbstractCookingRecipe> recipeType, AbstractFurnaceBlockEntity furnace, double cookSpeedMultiplier) {
+ /* Scale the recipe's cooking time to the current cookSpeedMultiplier */
+ int cookTime = world != null ? furnace.quickCheck.getRecipeFor(furnace, world).map(holder -> holder.value().getCookingTime()).orElse(200) : (net.minecraft.server.MinecraftServer.getServer().getRecipeManager().getRecipeFor(recipeType, furnace, world /* passing a null level here is safe. world is only used for map extending recipes which won't happen here */).map(holder -> holder.value().getCookingTime()).orElse(200));
+ return (int) Math.ceil (cookTime / cookSpeedMultiplier);
+ // Paper end
}
public static boolean isFuel(ItemStack stack) {
@@ -544,7 +554,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
}
if (slot == 0 && !flag) {
- this.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(this.level, this);
+ this.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(this.level, this.recipeType, this, this.cookSpeedMultiplier); // Paper
this.cookingProgress = 0;
this.setChanged();
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
index 2f25a502c5c7223101f2d8c125977e2c614cd899..f98cf44e929d326037e1089dafe4f82c6f6d8647 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
@@ -85,4 +85,20 @@ public abstract class CraftFurnace<T extends AbstractFurnaceBlockEntity> extends
@Override
public abstract CraftFurnace<T> copy();
+
+ // 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");
+ T snapshot = this.getSnapshot();
+ snapshot.cookSpeedMultiplier = multiplier;
+ snapshot.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(this.isPlaced() ? this.world.getHandle() : null, snapshot.recipeType, snapshot, snapshot.cookSpeedMultiplier); // Update the snapshot's current total cook time to scale with the newly set multiplier
+ }
+ // Paper end
}