Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from Sefiraat:master #32

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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<BlockPosition> blockCache = new HashSet<>();

public static final CustomItemStack TEMPLATE_BACKGROUND_STACK = new CustomItemStack(
Material.BLUE_STAINED_GLASS_PANE, Theme.PASSIVE + "Paste items matching template"
);
Expand All @@ -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());

Expand All @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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<BlockPosition> blockCache = new HashSet<>();

public static final CustomItemStack TEMPLATE_BACKGROUND_STACK = new CustomItemStack(
Material.BLUE_STAINED_GLASS_PANE,
Theme.PASSIVE + "Cut items matching template.",
Expand All @@ -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());

Expand All @@ -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()) {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
);
Expand Down Expand Up @@ -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()) {
Expand Down