Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) 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: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
130 Zeilen
8.3 KiB
Diff
130 Zeilen
8.3 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
|
|
|
|
Fixed an issue where a furnace's cook-speed multiplier rounds down
|
|
to the nearest Integer when updating its current cook time.
|
|
|
|
Co-authored-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..9801b777bc6ab7de91d82b29a142459292ee8605 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 - cook speed multiplier API
|
|
|
|
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 - cook speed multiplier API
|
|
}
|
|
|
|
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 multiplier API
|
|
+ if (nbt.contains("Paper.CookSpeedMultiplier")) {
|
|
+ this.cookSpeedMultiplier = nbt.getDouble("Paper.CookSpeedMultiplier");
|
|
+ }
|
|
+ // Paper end - cook speed multiplier API
|
|
}
|
|
|
|
@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 - cook speed multiplier API
|
|
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 - cook speed multiplier API
|
|
+ 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 - cook speed multiplier API
|
|
}
|
|
|
|
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 - cook speed multiplier API
|
|
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
|
|
}
|