Fluid Flowing ifLoaded patch

This commit is contained in:
Bjarne Koll 2024-10-23 13:13:00 +02:00
parent de0ed829eb
commit 292fb8b8e7
9 changed files with 120 additions and 104 deletions

View file

@ -19,10 +19,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public double cookSpeedMultiplier = 1.0; // Paper - cook speed multiplier API
public int cookingProgress;
public int cookingTotalTime;
@Nullable
@@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
protected final ContainerData dataAccess;
public final Object2IntOpenHashMap<ResourceLocation> recipesUsed;
public final Reference2IntOpenHashMap<ResourceKey<Recipe<?>>> recipesUsed;
private final RecipeManager.CachedCheck<SingleRecipeInput, ? extends AbstractCookingRecipe> quickCheck;
+ public final RecipeType<? extends AbstractCookingRecipe> recipeType; // Paper - cook speed multiplier API
@ -30,14 +28,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
super(blockEntityType, pos, state);
@@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
};
this.recipesUsed = new Object2IntOpenHashMap();
this.recipesUsed = new Reference2IntOpenHashMap();
this.quickCheck = RecipeManager.createCheck((RecipeType<AbstractCookingRecipe>) recipeType); // CraftBukkit - decompile error // Eclipse fail
+ this.recipeType = recipeType; // Paper - cook speed multiplier API
}
public static void invalidateCache() {
// CraftBukkit start - add fields and methods
@@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
this.recipesUsed.put(ResourceLocation.parse(s), nbttagcompound1.getInt(s));
this.recipesUsed.put(ResourceKey.create(Registries.RECIPE, ResourceLocation.parse(s)), nbttagcompound1.getInt(s));
}
+ // Paper start - cook speed multiplier API
@ -53,7 +51,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
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, registryLookup);
ContainerHelper.saveAllItems(nbt, this.items, registries);
CompoundTag nbttagcompound1 = new CompoundTag();
@@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
@ -61,7 +59,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
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
+ FurnaceStartSmeltEvent event = new FurnaceStartSmeltEvent(CraftBlock.at(world, pos), source, recipe, AbstractFurnaceBlockEntity.getTotalCookTime(world, blockEntity, blockEntity.recipeType, blockEntity.cookSpeedMultiplier)); // Paper - cook speed multiplier API
world.getCraftServer().getPluginManager().callEvent(event);
blockEntity.cookingTotalTime = event.getTotalCookTime();
@ -73,39 +71,44 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ 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.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(world, blockEntity, blockEntity.recipeType, blockEntity.cookSpeedMultiplier); // Paper - cook speed multiplier API
if (AbstractFurnaceBlockEntity.burn(blockEntity.level, blockEntity.worldPosition, world.registryAccess(), recipeholder, singlerecipeinput, blockEntity.items, i)) { // CraftBukkit
blockEntity.setRecipeUsed(recipeholder);
}
@@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
}
return fuelRegistry.burnDuration(stack);
}
- private static int getTotalCookTime(Level world, AbstractFurnaceBlockEntity furnace) {
- private static int getTotalCookTime(ServerLevel world, AbstractFurnaceBlockEntity furnace) {
- if (world == null) return 200; // CraftBukkit - SPIGOT-4302
+ public static int getTotalCookTime(@Nullable Level world, RecipeType<? extends AbstractCookingRecipe> recipeType, AbstractFurnaceBlockEntity furnace, double cookSpeedMultiplier) { // Paper - cook speed multiplier API
+ private static int getTotalCookTime(@Nullable ServerLevel world, AbstractFurnaceBlockEntity furnace, RecipeType<? extends AbstractCookingRecipe> recipeType, double cookSpeedMultiplier) { // Paper - cook speed multiplier API
SingleRecipeInput singlerecipeinput = new SingleRecipeInput(furnace.getItem(0));
- return (Integer) furnace.quickCheck.getRecipeFor(singlerecipeinput, world).map((recipeholder) -> {
- return ((AbstractCookingRecipe) recipeholder.value()).getCookingTime();
- return ((AbstractCookingRecipe) recipeholder.value()).cookingTime();
- }).orElse(200);
+ // Paper start - cook speed multiplier API
+ /* Scale the recipe's cooking time to the current cookSpeedMultiplier */
+ int cookTime = world != null ? furnace.quickCheck.getRecipeFor(singlerecipeinput, world).map(holder -> holder.value().getCookingTime()).orElse(200) : (net.minecraft.server.MinecraftServer.getServer().getRecipeManager().getRecipeFor(recipeType, singlerecipeinput, 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));
+ int cookTime = world != null ? furnace.quickCheck.getRecipeFor(singlerecipeinput, world).map(holder -> holder.value().cookingTime()).orElse(200) : (net.minecraft.server.MinecraftServer.getServer().getRecipeManager().getRecipeFor(recipeType, singlerecipeinput, 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().cookingTime()).orElse(200));
+ return (int) Math.ceil (cookTime / cookSpeedMultiplier);
+ // Paper end - cook speed multiplier API
}
public static boolean isFuel(ItemStack stack) {
@Override
@@ -0,0 +0,0 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
this.items.set(slot, stack);
stack.limitSize(this.getMaxStackSize(stack));
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
if (world instanceof ServerLevel) {
ServerLevel worldserver = (ServerLevel) world;
- this.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(worldserver, this);
+ this.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(worldserver, this, this.recipeType, this.cookSpeedMultiplier); // Paper - cook speed multiplier API
this.cookingProgress = 0;
this.setChanged();
}
}
-
}
@Override
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

View file

@ -0,0 +1,88 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 10 Sep 2018 23:36:16 -0400
Subject: [PATCH] Prevent chunk loading from Fluid Flowing
diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
+++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
Direction enumdirection = (Direction) entry.getKey();
FluidState fluid1 = (FluidState) entry.getValue();
BlockPos blockposition1 = pos.relative(enumdirection);
+ final BlockState blockStateIfLoaded = world.getBlockStateIfLoaded(blockposition1); // Paper - Prevent chunk loading from fluid flowing
+ if (blockStateIfLoaded == null) continue; // Paper - Prevent chunk loading from fluid flowing
// CraftBukkit start
org.bukkit.block.Block source = CraftBlock.at(world, pos);
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
continue;
}
// CraftBukkit end
- this.spreadTo(world, blockposition1, world.getBlockState(blockposition1), enumdirection, fluid1);
+ this.spreadTo(world, blockposition1, blockStateIfLoaded, enumdirection, fluid1); // Paper - Prevent chunk loading from fluid flowing
}
}
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
while (iterator.hasNext()) {
Direction enumdirection = (Direction) iterator.next();
BlockPos.MutableBlockPos blockposition_mutableblockposition1 = blockposition_mutableblockposition.setWithOffset(pos, enumdirection);
- BlockState iblockdata1 = world.getBlockState(blockposition_mutableblockposition1);
+ BlockState iblockdata1 = world.getBlockStateIfLoaded(blockposition_mutableblockposition1); // Paper - Prevent chunk loading from fluid flowing
+ if (iblockdata1 == null) continue; // Paper - Prevent chunk loading from fluid flowing
FluidState fluid = iblockdata1.getFluidState();
if (fluid.getType().isSame(this) && FlowingFluid.canPassThroughWall(enumdirection, world, pos, state, blockposition_mutableblockposition1, iblockdata1)) {
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
if (enumdirection1 != direction) {
BlockPos blockposition1 = pos.relative(enumdirection1);
- BlockState iblockdata1 = spreadCache.getBlockState(blockposition1);
+ BlockState iblockdata1 = spreadCache.getBlockStateIfLoaded(blockposition1); // Paper - Prevent chunk loading from fluid flowing
+ if (iblockdata1 == null) continue; // Paper - Prevent chunk loading from fluid flowing
FluidState fluid = iblockdata1.getFluidState();
if (this.canPassThrough(world, this.getFlowing(), pos, state, enumdirection1, blockposition1, iblockdata1, fluid)) {
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
while (iterator.hasNext()) {
Direction enumdirection = (Direction) iterator.next();
BlockPos blockposition1 = pos.relative(enumdirection);
- BlockState iblockdata1 = world.getBlockState(blockposition1);
+ BlockState iblockdata1 = world.getBlockStateIfLoaded(blockposition1); // Paper - Prevent chunk loading from fluid flowing
+ if (iblockdata1 == null) continue; // Paper - Prevent chunk loading from fluid flowing
FluidState fluid = iblockdata1.getFluidState();
if (this.canMaybePassThrough(world, pos, state, enumdirection, blockposition1, iblockdata1, fluid)) {
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
public BlockState getBlockState(BlockPos pos) {
return this.getBlockState(pos, this.getCacheKey(pos));
}
+ // Paper start - Prevent chunk loading from fluid flowing
+ public @javax.annotation.Nullable BlockState getBlockStateIfLoaded(BlockPos pos) {
+ return this.getBlockState(pos, this.getCacheKey(pos), false);
+ }
+ // Paper end - Prevent chunk loading from fluid flowing
private BlockState getBlockState(BlockPos pos, short packed) {
- return (BlockState) this.stateCache.computeIfAbsent(packed, (short1) -> {
- return this.level.getBlockState(pos);
- });
+ // Paper start - Prevent chunk loading from fluid flowing
+ return getBlockState(pos, packed, true);
+ }
+ private @javax.annotation.Nullable BlockState getBlockState(BlockPos pos, short packed, boolean load) {
+ BlockState blockState = this.stateCache.get(packed);
+ if (blockState == null) {
+ blockState = load ? level.getBlockState(pos) : level.getBlockStateIfLoaded(pos);
+ if (blockState != null) {
+ this.stateCache.put(packed, blockState);
+ }
+ }
+ return blockState;
+ // Paper end - Prevent chunk loading from fluid flowing
}
public boolean isHole(BlockPos pos) {

View file

@ -1,75 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 10 Sep 2018 23:36:16 -0400
Subject: [PATCH] Prevent chunk loading from Fluid Flowing
diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
+++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
Direction enumdirection = (Direction) entry.getKey();
FluidState fluid1 = (FluidState) entry.getValue();
BlockPos blockposition1 = pos.relative(enumdirection);
- BlockState iblockdata1 = world.getBlockState(blockposition1);
+ BlockState iblockdata1 = world.getBlockStateIfLoaded(blockposition1); // Paper - Prevent chunk loading from fluid flowing
+ if (iblockdata1 == null) continue; // Paper - Prevent chunk loading from fluid flowing
if (this.canSpreadTo(world, pos, blockState, enumdirection, blockposition1, iblockdata1, world.getFluidState(blockposition1), fluid1.getType())) {
// CraftBukkit start
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
while (iterator.hasNext()) {
Direction enumdirection = (Direction) iterator.next();
BlockPos blockposition1 = pos.relative(enumdirection);
- BlockState iblockdata1 = world.getBlockState(blockposition1);
+ BlockState iblockdata1 = world.getBlockStateIfLoaded(blockposition1); // Paper - Prevent chunk loading from fluid flowing
+ if (iblockdata1 == null) continue; // Paper - Prevent chunk loading from fluid flowing
FluidState fluid = iblockdata1.getFluidState();
if (fluid.getType().isSame(this) && this.canPassThroughWall(enumdirection, world, pos, state, blockposition1, iblockdata1)) {
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
if (enumdirection1 != direction) {
BlockPos blockposition2 = pos.relative(enumdirection1);
short short0 = FlowingFluid.getCacheKey(fromPos, blockposition2);
- Pair<BlockState, FluidState> pair = (Pair) stateCache.computeIfAbsent(short0, (short1) -> {
- BlockState iblockdata1 = world.getBlockState(blockposition2);
+ // Paper start - Prevent chunk loading from fluid flowing
+ Pair<BlockState, FluidState> pair = stateCache.get(short0);
+ if (pair == null) {
+ BlockState iblockdatax = world.getBlockStateIfLoaded(blockposition2);
+ if (iblockdatax == null) {
+ continue;
+ }
- return Pair.of(iblockdata1, iblockdata1.getFluidState());
- });
+ pair = Pair.of(iblockdatax, iblockdatax.getFluidState());
+ stateCache.put(short0, pair);
+ }
+ // Paper end - Prevent chunk loading from fluid flowing
BlockState iblockdata1 = (BlockState) pair.getFirst();
FluidState fluid = (FluidState) pair.getSecond();
@@ -0,0 +0,0 @@ public abstract class FlowingFluid extends Fluid {
Direction enumdirection = (Direction) iterator.next();
BlockPos blockposition1 = pos.relative(enumdirection);
short short0 = FlowingFluid.getCacheKey(pos, blockposition1);
- Pair<BlockState, FluidState> pair = (Pair) short2objectmap.computeIfAbsent(short0, (short1) -> {
- BlockState iblockdata1 = world.getBlockState(blockposition1);
-
- return Pair.of(iblockdata1, iblockdata1.getFluidState());
- });
+ // Paper start - Prevent chunk loading from fluid flowing
+ Pair pair = (Pair) short2objectmap.get(short0);
+ if (pair == null) {
+ BlockState iblockdatax = world.getBlockStateIfLoaded(blockposition1);
+ if (iblockdatax == null) continue;
+
+ pair = Pair.of(iblockdatax, iblockdatax.getFluidState());
+ short2objectmap.put(short0, pair);
+ }
+ // Paper end - Prevent chunk loading from fluid flowing
BlockState iblockdata1 = (BlockState) pair.getFirst();
FluidState fluid = (FluidState) pair.getSecond();
FluidState fluid1 = this.getNewLiquid(world, blockposition1, iblockdata1);