diff --git a/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkControlV.java b/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkControlV.java index 177a240b..b6665076 100644 --- a/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkControlV.java +++ b/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkControlV.java @@ -3,6 +3,7 @@ import com.gmail.nossr50.mcMMO; import dev.sefiraat.sefilib.misc.ParticleUtils; import dev.sefiraat.sefilib.world.LocationUtils; +import io.github.bakedlibs.dough.blocks.BlockPosition; import io.github.sefiraat.networks.NetworkStorage; import io.github.sefiraat.networks.Networks; import io.github.sefiraat.networks.managers.SupportedPluginManager; @@ -31,6 +32,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; public class NetworkControlV extends NetworkDirectional { @@ -48,6 +51,8 @@ public class NetworkControlV extends NetworkDirectional { private static final int DOWN_SLOT = 32; private static final int REQUIRED_POWER = 100; + private final Set blockCache = new HashSet<>(); + public static final CustomItemStack TEMPLATE_BACKGROUND_STACK = new CustomItemStack( Material.BLUE_STAINED_GLASS_PANE, Theme.PASSIVE + "貼上符合範本的物品" ); @@ -65,6 +70,11 @@ protected void onTick(@Nullable BlockMenu blockMenu, @Nonnull Block block) { } } + @Override + protected void onUniqueTick() { + blockCache.clear(); + } + private void tryPasteBlock(@Nonnull BlockMenu blockMenu) { final NodeDefinition definition = NetworkStorage.getAllNetworkObjects().get(blockMenu.getLocation()); @@ -83,6 +93,12 @@ private void tryPasteBlock(@Nonnull BlockMenu blockMenu) { } final Block targetBlock = blockMenu.getBlock().getRelative(direction); + final BlockPosition targetPosition = new BlockPosition(targetBlock); + + if (this.blockCache.contains(targetPosition)) { + return; + } + final Material material = targetBlock.getType(); if (!material.isAir()) { @@ -121,6 +137,7 @@ private void tryPasteBlock(@Nonnull BlockMenu blockMenu) { return; } + this.blockCache.add(targetPosition); Bukkit.getScheduler().runTask(Networks.getInstance(), bukkitTask -> { targetBlock.setType(fetchedStack.getType(), true); if (SupportedPluginManager.getInstance().isMcMMO()) { diff --git a/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkControlX.java b/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkControlX.java index 9fcaabef..86b43d0a 100644 --- a/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkControlX.java +++ b/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkControlX.java @@ -2,6 +2,7 @@ import dev.sefiraat.sefilib.misc.ParticleUtils; import dev.sefiraat.sefilib.world.LocationUtils; +import io.github.bakedlibs.dough.blocks.BlockPosition; import io.github.sefiraat.networks.NetworkStorage; import io.github.sefiraat.networks.Networks; import io.github.sefiraat.networks.network.NodeDefinition; @@ -30,6 +31,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; public class NetworkControlX extends NetworkDirectional { @@ -47,6 +50,8 @@ public class NetworkControlX extends NetworkDirectional { private static final int DOWN_SLOT = 32; private static final int REQUIRED_POWER = 100; + private final Set blockCache = new HashSet<>(); + public static final CustomItemStack TEMPLATE_BACKGROUND_STACK = new CustomItemStack( Material.BLUE_STAINED_GLASS_PANE, Theme.PASSIVE + "剪下符合範本的物品。", @@ -66,6 +71,11 @@ protected void onTick(@Nullable BlockMenu blockMenu, @Nonnull Block block) { } } + @Override + protected void onUniqueTick() { + this.blockCache.clear(); + } + private void tryBreakBlock(@Nonnull BlockMenu blockMenu) { final NodeDefinition definition = NetworkStorage.getAllNetworkObjects().get(blockMenu.getLocation()); @@ -84,6 +94,12 @@ private void tryBreakBlock(@Nonnull BlockMenu blockMenu) { } final Block targetBlock = blockMenu.getBlock().getRelative(direction); + final BlockPosition targetPosition = new BlockPosition(targetBlock); + + if (this.blockCache.contains(targetPosition)) { + return; + } + final Material material = targetBlock.getType(); if (material.getHardness() < 0 || material.isAir()) { @@ -117,6 +133,7 @@ private void tryBreakBlock(@Nonnull BlockMenu blockMenu) { definition.getNode().getRoot().addItemStack(resultStack); if (resultStack.getAmount() == 0) { + this.blockCache.add(targetPosition); Bukkit.getScheduler().runTask(Networks.getInstance(), bukkitTask -> { final BlockStateSnapshotResult blockState = PaperLib.getBlockState(targetBlock, true); diff --git a/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkDirectional.java b/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkDirectional.java index 3d4efb21..e682c9ec 100644 --- a/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkDirectional.java +++ b/src/main/java/io/github/sefiraat/networks/slimefun/network/NetworkDirectional.java @@ -106,6 +106,9 @@ public void tick(Block block, SlimefunItem slimefunItem, Config config) { @Override public void uniqueTick() { tick = tick <= 1 ? tickRate.getValue() : tick - 1; + if (tick <= 1) { + onUniqueTick(); + } } } ); @@ -163,6 +166,8 @@ protected void onTick(@Nullable BlockMenu blockMenu, @Nonnull Block block) { updateGui(blockMenu); } + protected void onUniqueTick() {} + @Override public void postRegister() { new BlockMenuPreset(this.getId(), this.getItemName()) {