9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-21 07:59:16 +00:00

Update SprinklerBlock.java

This commit is contained in:
XiaoMoMi
2024-10-03 22:16:14 +08:00
parent 99aa349565
commit a1d5bd7f67

View File

@@ -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.pot.PotConfig;
import net.momirealms.customcrops.api.core.mechanic.sprinkler.SprinklerConfig; import net.momirealms.customcrops.api.core.mechanic.sprinkler.SprinklerConfig;
import net.momirealms.customcrops.api.core.world.CustomCropsBlockState; 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.CustomCropsWorld;
import net.momirealms.customcrops.api.core.world.Pos3; import net.momirealms.customcrops.api.core.world.Pos3;
import net.momirealms.customcrops.api.core.wrapper.WrappedBreakEvent; import net.momirealms.customcrops.api.core.wrapper.WrappedBreakEvent;
@@ -315,24 +316,28 @@ public class SprinklerBlock extends AbstractCustomCropsBlock {
} }
for (Pos3 pos3 : pos3s) { for (Pos3 pos3 : pos3s) {
Optional<CustomCropsBlockState> optionalState = world.getBlockState(pos3); Optional<CustomCropsChunk> optionalChunk = world.getLoadedChunk(pos3.toChunkPos());
if (optionalState.isPresent()) { if (optionalChunk.isPresent()) {
CustomCropsBlockState anotherState = optionalState.get(); CustomCropsChunk chunk = optionalChunk.get();
if (anotherState.type() instanceof PotBlock potBlock) { Optional<CustomCropsBlockState> optionalState = chunk.getBlockState(pos3);
PotConfig potConfig = potBlock.config(anotherState); if (optionalState.isPresent()) {
if (!potConfig.disablePluginMechanism()) { CustomCropsBlockState anotherState = optionalState.get();
if (config.potWhitelist().contains(potConfig.id())) { if (anotherState.type() instanceof PotBlock potBlock) {
if (potBlock.addWater(anotherState, potConfig, config.wateringAmount())) { PotConfig potConfig = potBlock.config(anotherState);
BukkitCustomCropsPlugin.getInstance().getScheduler().sync().run( if (!potConfig.disablePluginMechanism()) {
() -> potBlock.updateBlockAppearance( if (config.potWhitelist().contains(potConfig.id())) {
pos3.toLocation(world.bukkitWorld()), if (potBlock.addWater(anotherState, potConfig, config.wateringAmount())) {
potConfig, BukkitCustomCropsPlugin.getInstance().getScheduler().sync().run(
true, () -> potBlock.updateBlockAppearance(
potBlock.fertilizers(anotherState) pos3.toLocation(world.bukkitWorld()),
), potConfig,
bukkitWorld, true,
pos3.chunkX(), pos3.chunkZ() potBlock.fertilizers(anotherState)
); ),
bukkitWorld,
pos3.chunkX(), pos3.chunkZ()
);
}
} }
} }
} }