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 184215a2a8..06f41a17a9 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 @@ -35,7 +35,7 @@ import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler; -import io.github.thebusybiscuit.slimefun4.implementation.operations.MiningOperation; +import io.github.thebusybiscuit.slimefun4.implementation.operations.GEOMiningOperation; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; @@ -54,7 +54,7 @@ * * @see GEOResource */ -public class GEOMiner extends SlimefunItem implements RecipeDisplayItem, EnergyNetComponent, InventoryBlock, HologramOwner, MachineProcessHolder { +public class GEOMiner extends SlimefunItem implements RecipeDisplayItem, EnergyNetComponent, InventoryBlock, HologramOwner, MachineProcessHolder { private static final int[] BORDER = { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 26, 27, 35, 36, 44, 45, 53 }; private static final int[] OUTPUT_BORDER = { 19, 20, 21, 22, 23, 24, 25, 28, 34, 37, 43, 46, 47, 48, 49, 50, 51, 52 }; @@ -62,7 +62,7 @@ public class GEOMiner extends SlimefunItem implements RecipeDisplayItem, EnergyN private static final int PROCESSING_TIME = 14; - private final MachineProcessor processor = new MachineProcessor<>(this); + private final MachineProcessor processor = new MachineProcessor<>(this); private int energyConsumedPerTick = -1; private int energyCapacity = -1; @@ -78,7 +78,7 @@ public GEOMiner(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeTy } @Override - public @Nonnull MachineProcessor getMachineProcessor() { + public @Nonnull MachineProcessor getMachineProcessor() { return processor; } @@ -294,7 +294,7 @@ public boolean isSynchronized() { protected void tick(@Nonnull Block b) { BlockMenu inv = BlockStorage.getInventory(b); - MiningOperation operation = processor.getOperation(b); + GEOMiningOperation operation = processor.getOperation(b); if (operation != null) { if (!operation.isFinished()) { @@ -335,7 +335,7 @@ private void start(@Nonnull Block b, @Nonnull BlockMenu inv) { return; } - processor.startOperation(b, new MiningOperation(resource, b, PROCESSING_TIME)); + processor.startOperation(b, new GEOMiningOperation(resource, b, 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 new file mode 100644 index 0000000000..ee981eac83 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/GEOMiningOperation.java @@ -0,0 +1,46 @@ +package io.github.thebusybiscuit.slimefun4.implementation.operations; + +import java.util.OptionalInt; + +import javax.annotation.Nonnull; + +import org.bukkit.block.Block; + +import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; +import io.github.thebusybiscuit.slimefun4.api.geo.ResourceManager; +import io.github.thebusybiscuit.slimefun4.core.machines.MachineOperation; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOMiner; + +/** + * This {@link MachineOperation} represents a {@link GEOMiner} + * mining a {@link GEOResource}. + * + * @author iTwins + * + * @see GEOMiner + * + */ +public class GEOMiningOperation extends MiningOperation { + + private final GEOResource resource; + private final Block block; + + public GEOMiningOperation(@Nonnull GEOResource resource, @Nonnull Block block, 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 cancel() { + 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)); + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/MiningOperation.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/MiningOperation.java index a7dd33395c..83480ce63f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/MiningOperation.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/MiningOperation.java @@ -1,45 +1,32 @@ package io.github.thebusybiscuit.slimefun4.implementation.operations; -import java.util.OptionalInt; - import javax.annotation.Nonnull; import com.google.common.base.Preconditions; -import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; -import io.github.thebusybiscuit.slimefun4.api.geo.ResourceManager; import io.github.thebusybiscuit.slimefun4.core.machines.MachineOperation; -import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOMiner; /** - * This {@link MachineOperation} represents a {@link GEOMiner} - * mining a {@link GEOResource}. + * This {@link MachineOperation} represents an operation + * with no inputs, only a result. * * @author TheBusyBiscuit - * - * @see GEOMiner * */ public class MiningOperation implements MachineOperation { private final ItemStack result; - private final GEOResource resource; - private final Block block; private final int totalTicks; private int currentTicks = 0; - public MiningOperation(@Nonnull GEOResource resource, Block block, int totalTicks) { - Preconditions.checkArgument(resource != null, "The resource cannot be null"); + public MiningOperation(@Nonnull ItemStack result, int totalTicks) { + Preconditions.checkArgument(result != null, "The result cannot be null"); Preconditions.checkArgument(totalTicks >= 0, "The amount of total ticks must be a positive integer or zero, received: " + totalTicks); - this.resource = resource; - this.result = resource.getItem().clone(); - this.block = block; + this.result = result; this.totalTicks = totalTicks; } @@ -69,11 +56,4 @@ public int getTotalTicks() { return totalTicks; } - @Override - public void cancel() { - 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)); - } - }