From a1d5bd7f67beb19a53282d3f8bdc9a45a77414ea Mon Sep 17 00:00:00 2001 From: XiaoMoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Thu, 3 Oct 2024 22:16:14 +0800 Subject: [PATCH] Update SprinklerBlock.java --- .../api/core/block/SprinklerBlock.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/SprinklerBlock.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/SprinklerBlock.java index 03a7701..be92902 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/SprinklerBlock.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/SprinklerBlock.java @@ -27,6 +27,7 @@ import net.momirealms.customcrops.api.core.*; import net.momirealms.customcrops.api.core.mechanic.pot.PotConfig; import net.momirealms.customcrops.api.core.mechanic.sprinkler.SprinklerConfig; import net.momirealms.customcrops.api.core.world.CustomCropsBlockState; +import net.momirealms.customcrops.api.core.world.CustomCropsChunk; import net.momirealms.customcrops.api.core.world.CustomCropsWorld; import net.momirealms.customcrops.api.core.world.Pos3; import net.momirealms.customcrops.api.core.wrapper.WrappedBreakEvent; @@ -315,24 +316,28 @@ public class SprinklerBlock extends AbstractCustomCropsBlock { } for (Pos3 pos3 : pos3s) { - Optional optionalState = world.getBlockState(pos3); - if (optionalState.isPresent()) { - CustomCropsBlockState anotherState = optionalState.get(); - if (anotherState.type() instanceof PotBlock potBlock) { - PotConfig potConfig = potBlock.config(anotherState); - if (!potConfig.disablePluginMechanism()) { - if (config.potWhitelist().contains(potConfig.id())) { - if (potBlock.addWater(anotherState, potConfig, config.wateringAmount())) { - BukkitCustomCropsPlugin.getInstance().getScheduler().sync().run( - () -> potBlock.updateBlockAppearance( - pos3.toLocation(world.bukkitWorld()), - potConfig, - true, - potBlock.fertilizers(anotherState) - ), - bukkitWorld, - pos3.chunkX(), pos3.chunkZ() - ); + Optional optionalChunk = world.getLoadedChunk(pos3.toChunkPos()); + if (optionalChunk.isPresent()) { + CustomCropsChunk chunk = optionalChunk.get(); + Optional optionalState = chunk.getBlockState(pos3); + if (optionalState.isPresent()) { + CustomCropsBlockState anotherState = optionalState.get(); + if (anotherState.type() instanceof PotBlock potBlock) { + PotConfig potConfig = potBlock.config(anotherState); + if (!potConfig.disablePluginMechanism()) { + if (config.potWhitelist().contains(potConfig.id())) { + if (potBlock.addWater(anotherState, potConfig, config.wateringAmount())) { + BukkitCustomCropsPlugin.getInstance().getScheduler().sync().run( + () -> potBlock.updateBlockAppearance( + pos3.toLocation(world.bukkitWorld()), + potConfig, + true, + potBlock.fertilizers(anotherState) + ), + bukkitWorld, + pos3.chunkX(), pos3.chunkZ() + ); + } } } }