Skip to content

Commit

Permalink
pass BlockPosition to onCancel
Browse files Browse the repository at this point in the history
  • Loading branch information
iTwins committed Sep 7, 2023
1 parent c06e316 commit dc2cdad
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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) {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,23 +22,21 @@
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;
}

/**
* This returns the {@link GEOResource} back to the chunk
* 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));
}

}

0 comments on commit dc2cdad

Please sign in to comment.