From 249afad3731283651d5ff8929d51abc26074e504 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Sat, 12 Jun 2021 22:09:48 -0700 Subject: [PATCH] patches --- .../Add-ItemStackRecipeChoice-Draft-API.patch | 0 ...nt-furnace-cook-speed-multiplier-API.patch | 0 ...currency-Improvements-to-Permissions.patch | 0 ...nt-furnace-cook-speed-multiplier-API.patch | 64 ++++++++++--------- 4 files changed, 34 insertions(+), 30 deletions(-) rename patches/{api-unmapped => api}/Add-ItemStackRecipeChoice-Draft-API.patch (100%) rename patches/{api-unmapped => api}/Implement-furnace-cook-speed-multiplier-API.patch (100%) rename patches/{api-unmapped => api}/Performance-Concurrency-Improvements-to-Permissions.patch (100%) rename patches/{server-remapped => server}/Implement-furnace-cook-speed-multiplier-API.patch (52%) diff --git a/patches/api-unmapped/Add-ItemStackRecipeChoice-Draft-API.patch b/patches/api/Add-ItemStackRecipeChoice-Draft-API.patch similarity index 100% rename from patches/api-unmapped/Add-ItemStackRecipeChoice-Draft-API.patch rename to patches/api/Add-ItemStackRecipeChoice-Draft-API.patch diff --git a/patches/api-unmapped/Implement-furnace-cook-speed-multiplier-API.patch b/patches/api/Implement-furnace-cook-speed-multiplier-API.patch similarity index 100% rename from patches/api-unmapped/Implement-furnace-cook-speed-multiplier-API.patch rename to patches/api/Implement-furnace-cook-speed-multiplier-API.patch diff --git a/patches/api-unmapped/Performance-Concurrency-Improvements-to-Permissions.patch b/patches/api/Performance-Concurrency-Improvements-to-Permissions.patch similarity index 100% rename from patches/api-unmapped/Performance-Concurrency-Improvements-to-Permissions.patch rename to patches/api/Performance-Concurrency-Improvements-to-Permissions.patch diff --git a/patches/server-remapped/Implement-furnace-cook-speed-multiplier-API.patch b/patches/server/Implement-furnace-cook-speed-multiplier-API.patch similarity index 52% rename from patches/server-remapped/Implement-furnace-cook-speed-multiplier-API.patch rename to patches/server/Implement-furnace-cook-speed-multiplier-API.patch index f6367e4afb..c1705faa6c 100644 --- a/patches/server-remapped/Implement-furnace-cook-speed-multiplier-API.patch +++ b/patches/server/Implement-furnace-cook-speed-multiplier-API.patch @@ -14,18 +14,10 @@ diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnac index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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 -@@ -0,0 +0,0 @@ import net.minecraft.world.level.block.Blocks; - import net.minecraft.world.level.block.state.BlockState; - import net.minecraft.world.phys.Vec3; - // CraftBukkit start -+import java.util.List; - import org.bukkit.craftbukkit.block.CraftBlock; - import org.bukkit.craftbukkit.entity.CraftHumanEntity; - import org.bukkit.craftbukkit.inventory.CraftItemStack; @@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit protected NonNullList items; public int litTime; - private int litDuration; + int litDuration; + public double cookSpeedMultiplier = 1.0; // Paper - cook speed multiplier API public int cookingProgress; public int cookingTotalTime; @@ -35,46 +27,58 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } + // Paper start - cook speed API -+ if (tag.contains("Paper.CookSpeedMultiplier")) { -+ this.cookSpeedMultiplier = tag.getDouble("Paper.CookSpeedMultiplier"); ++ if (nbt.contains("Paper.CookSpeedMultiplier")) { ++ this.cookSpeedMultiplier = nbt.getDouble("Paper.CookSpeedMultiplier"); + } + // Paper end } @Override @@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit - tag.putShort("BurnTime", (short) this.litTime); - tag.putShort("CookTime", (short) this.cookingProgress); - tag.putShort("CookTimeTotal", (short) this.cookingTotalTime); -+ tag.putDouble("Paper.CookSpeedMultiplier", this.cookSpeedMultiplier); // Paper - cook speed multiplier API - ContainerHelper.saveAllItems(tag, this.items); + 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(); @@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit - if (this.isLit() && this.canBurn(irecipe)) { - ++this.cookingProgress; -- if (this.cookingProgress == this.cookingTotalTime) { -+ if (this.cookingProgress >= this.cookingTotalTime) { // Paper - cook speed multiplier API - this.cookingProgress = 0; - this.cookingTotalTime = this.getTotalCookTime(); - this.burn(irecipe); + if (blockEntity.isLit() && AbstractFurnaceBlockEntity.canBurn(irecipe, blockEntity.items, i)) { + ++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.recipeType, blockEntity); ++ blockEntity.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(world, blockEntity.recipeType, blockEntity, blockEntity.cookSpeedMultiplier); + if (AbstractFurnaceBlockEntity.burn(blockEntity.level, blockEntity.worldPosition, irecipe, blockEntity.items, i)) { // CraftBukkit + blockEntity.setRecipeUsed(irecipe); + } @@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit } } -- protected int getTotalCookTime() { -- return (this.hasLevel()) ? (Integer) this.level.getRecipeManager().getRecipeFor((RecipeType) this.recipeType, this, this.level).map(AbstractCookingRecipe::getCookingTime).orElse(200) : 200; // CraftBukkit - SPIGOT-4302 // Eclipse fail +- private static int getTotalCookTime(Level world, RecipeType recipeType, Container inventory) { +- return (world != null) ? (Integer) world.getRecipeManager().getRecipeFor((RecipeType) recipeType, inventory, world).map(AbstractCookingRecipe::getCookingTime).orElse(200) : 200; // CraftBukkit - SPIGOT-4302 // Eclipse fail + // Paper begin - Expose this function so CraftFurnace can correctly scale the total cooking time to a new multiplier -+ public int getTotalCookTime() { ++ public static int getTotalCookTime(Level world, RecipeType recipeType, Container inventory, final double cookSpeedMultiplier) { + /* Scale the recipe's cooking time to the current cookSpeedMultiplier */ -+ int cookTime = (this.hasLevel()) ? (Integer) this.level.getRecipeManager().getRecipeFor((RecipeType) this.recipeType, this, this.level).map(AbstractCookingRecipe::getCookingTime).orElse(200) : 200; // CraftBukkit - SPIGOT-4302 // Eclipse fail -+ return (int) Math.ceil (cookTime / this.cookSpeedMultiplier); ++ int cookTime = world != null ? world.getRecipeManager().getRecipeFor((RecipeType) recipeType, inventory, world).map(AbstractCookingRecipe::getCookingTime).orElse(200) : 200; // CraftBukkit - SPIGOT-4302 // Eclipse fail ++ return (int) Math.ceil (cookTime / cookSpeedMultiplier); } + // Paper end public static boolean isFuel(ItemStack stack) { - return getFuel().containsKey(stack.getItem()); + return AbstractFurnaceBlockEntity.getFuel().containsKey(stack.getItem()); +@@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit + } + + if (slot == 0 && !flag) { +- this.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(this.level, this.recipeType, this); ++ this.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(this.level, this.recipeType, this, this.cookSpeedMultiplier); + 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java @@ -96,7 +100,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + com.google.common.base.Preconditions.checkArgument(multiplier <= 200, "Furnace speed multiplier cannot more than 200"); + T snapshot = this.getSnapshot(); + snapshot.cookSpeedMultiplier = multiplier; -+ snapshot.cookingTotalTime = snapshot.getTotalCookTime(); // Update the snapshot's current total cook time to scale with the newly set multiplier ++ snapshot.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(this.world.getHandle(), snapshot.getCurrentRecipe().getType(), ((CraftInventoryFurnace) this.getInventory()).getInventory(), snapshot.cookSpeedMultiplier); // Update the snapshot's current total cook time to scale with the newly set multiplier + } + // Paper end }