mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-07 19:30:34 +01:00
c0936a71bd
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: 01aa02eb PR-858: Add LivingEntity#playHurtAnimation() 9421320f PR-884: Refinements to new ban API for improved compatibility and correctness 37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API 4eeb174b All smithing inventories are now the new smithing inventory f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop e7a807fa PR-879: Add Player#sendHealthUpdate() 692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml 2d033390 SPIGOT-7403: Add direct API for waxed signs 16a08373 PR-876: Add missing Raider API and 'no action ticks' CraftBukkit Changes: b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation() 95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities 0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness 0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit 648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API 31fe848d6 All smithing inventories are now the new smithing inventory 9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table 9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop 3be9ac171 PR-1220: Add Player#sendHealthUpdate() c1279f775 PR-1209: Clean up various patches c432e4397 Fix Raider#setCelebrating() implementation 504d96665 SPIGOT-7403: Add direct API for waxed signs c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks' 85b89c3dd Increase outdated build delay Spigot Changes: 9ebce8af Rebuild patches 64b565e6 Rebuild patches
130 lines
8.0 KiB
Diff
130 lines
8.0 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 d56a64b058d8848e405e33d9884a61ea952a8f71..40dc29288a13ae9c1f8b0434922fdb5c7d02daa9 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
|
|
@@ -77,11 +77,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);
|
|
@@ -128,6 +130,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() {
|
|
@@ -280,6 +283,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
|
|
@@ -288,6 +296,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();
|
|
|
|
@@ -359,7 +368,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
|
|
CraftItemStack source = CraftItemStack.asCraftMirror(blockEntity.items.get(0));
|
|
CookingRecipe<?> recipe = (CookingRecipe<?>) irecipe.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();
|
|
@@ -367,9 +376,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(), irecipe, blockEntity.items, i)) { // CraftBukkit
|
|
blockEntity.setRecipeUsed(irecipe);
|
|
}
|
|
@@ -469,9 +478,13 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
|
|
}
|
|
}
|
|
|
|
- private static int getTotalCookTime(Level world, AbstractFurnaceBlockEntity furnace) {
|
|
- return (world != null) ? (Integer) furnace.quickCheck.getRecipeFor(furnace, world).map(AbstractCookingRecipe::getCookingTime).orElse(200) : 200; // CraftBukkit - SPIGOT-4302
|
|
+ // 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(AbstractCookingRecipe::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(AbstractCookingRecipe::getCookingTime).orElse(200));
|
|
+ return (int) Math.ceil (cookTime / cookSpeedMultiplier);
|
|
}
|
|
+ // Paper end
|
|
|
|
public static boolean isFuel(ItemStack stack) {
|
|
return AbstractFurnaceBlockEntity.getFuel().containsKey(stack.getItem());
|
|
@@ -540,7 +553,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 facf95a44b5d3a63fda156c6afc8cabe50b21d32..3da4616c904d47bbecae0d4cb6970496fbec9a8b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
|
|
@@ -78,4 +78,20 @@ public abstract class CraftFurnace<T extends AbstractFurnaceBlockEntity> extends
|
|
|
|
return recipesUsed.build();
|
|
}
|
|
+
|
|
+ // 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
|
|
}
|