diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java index 0f5a26c..6e30708 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java @@ -5,6 +5,8 @@ import land.chipmunk.chipmunkmod.data.BlockArea; import land.chipmunk.chipmunkmod.listeners.Listener; import land.chipmunk.chipmunkmod.listeners.ListenerManager; import land.chipmunk.chipmunkmod.util.MathUtilities; +import net.minecraft.block.Block; +import net.minecraft.block.CommandBlock; import net.minecraft.block.entity.CommandBlockBlockEntity; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; @@ -30,6 +32,8 @@ public class CommandCore { private Timer timer; + private boolean shouldRefill = false; + public boolean runFillCommand = true; public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance()); @@ -51,9 +55,22 @@ public class CommandCore { } }; + final TimerTask refillTask = new TimerTask() { + @Override + public void run() { + if (!shouldRefill) return; + + refill(); + + shouldRefill = false; + } + }; + timer = new Timer(); timer.schedule(task, 50, 50); + + timer.schedule(refillTask, 50, 550); } private void tick () { @@ -62,12 +79,44 @@ public class CommandCore { if (networkHandler == null) cleanup(); reloadRelativeArea(); + + check(); } public void reloadRelativeArea () { noPos = ChipmunkMod.CONFIG.core.relativeArea; } + public void check () { + final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); + + if (networkHandler == null || withPos == null) return; + + for (int x = withPos.start.getX(); x <= withPos.end.getX(); x++) { + for (int y = withPos.start.getY(); y <= withPos.end.getY(); y++) { + for (int z = withPos.start.getZ(); z <= withPos.end.getZ(); z++) { + try { + final BlockPos pos = new BlockPos(x, y, z); + + final ClientWorld world = client.world; + + if (world == null) return; + + final Block block = world.getBlockState(pos).getBlock(); + + if (block instanceof CommandBlock) continue; + + shouldRefill = true; + + return; + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + } + public void move (Vec3d position) { final ClientWorld world = client.world; diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java index efac249..a4f01f7 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java @@ -8,8 +8,6 @@ import land.chipmunk.chipmunkmod.song.Song; import land.chipmunk.chipmunkmod.song.SongLoaderException; import land.chipmunk.chipmunkmod.song.SongLoaderThread; import land.chipmunk.chipmunkmod.util.MathUtilities; - - import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;