From dc2cdadc3ca7e7e4ba2cc2919e3be496af20812d Mon Sep 17 00:00:00 2001 From: iTwins Date: Thu, 7 Sep 2023 02:29:15 +0200 Subject: [PATCH] pass BlockPosition to onCancel --- .../slimefun4/core/machines/MachineOperation.java | 3 ++- .../slimefun4/core/machines/MachineProcessor.java | 2 +- .../implementation/items/geo/GEOMiner.java | 2 +- .../operations/GEOMiningOperation.java | 13 +++++-------- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineOperation.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineOperation.java index ff211b4594..3da6569b6c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineOperation.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineOperation.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.core.machines; +import io.github.bakedlibs.dough.blocks.BlockPosition; import io.github.thebusybiscuit.slimefun4.core.attributes.MachineProcessHolder; /** @@ -61,6 +62,6 @@ default boolean isFinished() { * This method is called when a {@link MachineOperation} is interrupted before finishing. * Implement to specify behaviour that should happen in this case. */ - default void onCancel() {} + default void onCancel(BlockPosition position) {} } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineProcessor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineProcessor.java index f8064c5c78..c1e69b39c8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineProcessor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineProcessor.java @@ -231,7 +231,7 @@ public boolean endOperation(@Nonnull BlockPosition pos) { Event event = new AsyncMachineOperationFinishEvent(pos, this, operation); Bukkit.getPluginManager().callEvent(event); } else { - operation.onCancel(); + operation.onCancel(pos); } return true; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java index 951f56ac45..d0f8c21b62 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java @@ -335,7 +335,7 @@ private void start(@Nonnull Block b, @Nonnull BlockMenu inv) { return; } - processor.startOperation(b, new GEOMiningOperation(resource, b, PROCESSING_TIME)); + processor.startOperation(b, new GEOMiningOperation(resource, PROCESSING_TIME)); Slimefun.getGPSNetwork().getResourceManager().setSupplies(resource, b.getWorld(), b.getX() >> 4, b.getZ() >> 4, supplies - 1); updateHologram(b, "&7Mining: &r" + resource.getName()); return; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/GEOMiningOperation.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/GEOMiningOperation.java index 912e05e5b2..372f9f502c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/GEOMiningOperation.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/GEOMiningOperation.java @@ -4,8 +4,7 @@ import javax.annotation.Nonnull; -import org.bukkit.block.Block; - +import io.github.bakedlibs.dough.blocks.BlockPosition; import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; import io.github.thebusybiscuit.slimefun4.api.geo.ResourceManager; import io.github.thebusybiscuit.slimefun4.core.machines.MachineOperation; @@ -23,12 +22,10 @@ public class GEOMiningOperation extends MiningOperation { private final GEOResource resource; - private final Block block; - public GEOMiningOperation(@Nonnull GEOResource resource, @Nonnull Block block, int totalTicks) { + public GEOMiningOperation(@Nonnull GEOResource resource, int totalTicks) { super(resource.getItem().clone(), totalTicks); this.resource = resource; - this.block = block; } /** @@ -36,10 +33,10 @@ public GEOMiningOperation(@Nonnull GEOResource resource, @Nonnull Block block, i * when the {@link GEOMiningOperation} gets cancelled */ @Override - public void onCancel() { + public void onCancel(@Nonnull BlockPosition position) { ResourceManager resourceManager = Slimefun.getGPSNetwork().getResourceManager(); - OptionalInt supplies = resourceManager.getSupplies(resource, block.getWorld(), block.getX() >> 4, block.getZ() >> 4); - supplies.ifPresent(s -> resourceManager.setSupplies(resource, block.getWorld(), block.getX() >> 4, block.getZ() >> 4, s + 1)); + OptionalInt supplies = resourceManager.getSupplies(resource, position.getWorld(), position.getChunkX(), position.getChunkZ()); + supplies.ifPresent(s -> resourceManager.setSupplies(resource, position.getWorld(), position.getChunkX(), position.getChunkZ(), s + 1)); } }