Skip to content

Commit

Permalink
reorganized files
Browse files Browse the repository at this point in the history
  • Loading branch information
dynmie committed Jul 1, 2024
1 parent a46c401 commit 0650aa0
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 185 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.dynmie.highway.highwaytools.block;

import me.dynmie.highway.highwaytools.blueprint.BlueprintTask;
import me.dynmie.highway.highwaytools.interaction.Inventory;
import me.dynmie.highway.highwaytools.handler.InventoryHandler;
import me.dynmie.highway.modules.HighwayTools;
import me.dynmie.highway.utils.HighwayUtils;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import me.dynmie.highway.utils.BlockUtils;
import me.dynmie.highway.utils.LocationUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -26,9 +26,11 @@ public class BlockTaskManager {
private final Set<BlockTask> sortedTasks = new ConcurrentSkipListSet<>(getBlockTaskComparator());

private final HighwayTools tools;
private final InventoryHandler inventoryHandler;

public BlockTaskManager(HighwayTools tools) {
public BlockTaskManager(HighwayTools tools, InventoryHandler inventoryHandler) {
this.tools = tools;
this.inventoryHandler = inventoryHandler;
}

public void updateTasks() {
Expand Down Expand Up @@ -59,7 +61,7 @@ public void generateTask(BlockPos pos, BlueprintTask blueprintTask) {
Block currentBlock = blockState.getBlock();

// padding
if (HighwayUtils.isBehind(tools.getStartPosition(), pos, tools.getDirection())) {
if (LocationUtils.isBehind(tools.getStartPosition(), pos, tools.getDirection())) {
return;
}

Expand All @@ -77,8 +79,8 @@ public void generateTask(BlockPos pos, BlueprintTask blueprintTask) {
}

// place
if (blockState.isReplaceable() && !HighwayUtils.isTypeAir(blueprintTask.getTargetBlock())) {
if (!BlockUtils.canPlace(pos)) {
if (blockState.isReplaceable() && !BlockUtils.isTypeAir(blueprintTask.getTargetBlock())) {
if (!meteordevelopment.meteorclient.utils.world.BlockUtils.canPlace(pos)) {
BlockTask task = new BlockTask(pos, TaskState.DONE, blueprintTask);
addTask(task);
return;
Expand All @@ -97,7 +99,7 @@ public void generateTask(BlockPos pos, BlueprintTask blueprintTask) {
}

//
if (blockState.isAir() && HighwayUtils.isTypeAir(blueprintTask.getTargetBlock())) {
if (blockState.isAir() && BlockUtils.isTypeAir(blueprintTask.getTargetBlock())) {
BlockTask task = new BlockTask(pos, TaskState.DONE, blueprintTask);
addTask(task);
return;
Expand All @@ -120,8 +122,8 @@ public void generateTask(BlockPos pos, BlueprintTask blueprintTask) {
}

public void runTasks() {
if (Inventory.getWaitTicks() > 1) {
Inventory.decreaseWaitTicks(1);
if (inventoryHandler.getWaitTicks() > 1) {
inventoryHandler.decreaseWaitTicks(1);
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package me.dynmie.highway.highwaytools.block;

import me.dynmie.highway.highwaytools.interaction.Break;
import me.dynmie.highway.highwaytools.interaction.Liquid;
import me.dynmie.highway.highwaytools.interaction.Place;
import me.dynmie.highway.highwaytools.handler.BreakHandler;
import me.dynmie.highway.highwaytools.handler.InventoryHandler;
import me.dynmie.highway.highwaytools.handler.LiquidHandler;
import me.dynmie.highway.highwaytools.handler.PlaceHandler;
import me.dynmie.highway.modules.HighwayTools;
import me.dynmie.highway.utils.HighwayUtils;
import me.dynmie.highway.utils.BlockUtils;
import me.dynmie.highway.utils.LiquidUtils;
import meteordevelopment.meteorclient.utils.player.Rotations;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -23,9 +24,17 @@ public class TaskExecutor {
private static final MinecraftClient mc = MinecraftClient.getInstance();

private final HighwayTools tools;
private final BreakHandler breakHandler;
private final InventoryHandler inventoryHandler;
private final LiquidHandler liquidHandler;
private final PlaceHandler placeHandler;

public TaskExecutor(HighwayTools tools) {
public TaskExecutor(HighwayTools tools, BreakHandler breakHandler, InventoryHandler inventoryHandler, LiquidHandler liquidHandler, PlaceHandler placeHandler) {
this.tools = tools;
this.breakHandler = breakHandler;
this.inventoryHandler = inventoryHandler;
this.liquidHandler = liquidHandler;
this.placeHandler = placeHandler;
}

public void doTask(BlockTask task, boolean check) {
Expand All @@ -48,14 +57,14 @@ private void doBreaking(BlockTask task, boolean check) {
BlockState state = mc.world.getBlockState(task.getBlockPos());
Block block = state.getBlock();

if (HighwayUtils.isTypeAir(block)) {
if (BlockUtils.isTypeAir(block)) {
task.updateState(TaskState.BROKEN);
return;
}

// check liquid
if (Liquid.isLiquid(state)) {
Liquid.updateTask(task);
if (LiquidUtils.isLiquid(state)) {
liquidHandler.updateTask(task);
return;
}

Expand All @@ -70,13 +79,13 @@ private void doBroken(BlockTask task) {
if (mc.world == null) return;
Block block = mc.world.getBlockState(task.getBlockPos()).getBlock();

if (!HighwayUtils.isTypeAir(block)) {
if (!BlockUtils.isTypeAir(block)) {
task.updateState(TaskState.BREAK);
return;
}

Block targetBlock = task.getBlueprintTask().getTargetBlock();
if (HighwayUtils.isTypeAir(targetBlock)) {
if (BlockUtils.isTypeAir(targetBlock)) {
BlockSoundGroup soundGroup = targetBlock.getDefaultState().getSoundGroup();
mc.player.playSound(soundGroup.getBreakSound(), soundGroup.getVolume(), soundGroup.getPitch());
task.updateState(TaskState.DONE);
Expand All @@ -93,14 +102,14 @@ private void doPlaced(BlockTask task) {
Block currentBlock = state.getBlock();
Block targetBlock = task.getBlueprintTask().getTargetBlock();

if ((HighwayUtils.blockEqualsAndAirCheck(currentBlock, targetBlock) || task.getBlueprintTask().isFiller()) && !state.isReplaceable()) {
if ((BlockUtils.blockEqualsAndAirCheck(currentBlock, targetBlock) || task.getBlueprintTask().isFiller()) && !state.isReplaceable()) {
tools.setBlocksPlaced(tools.getBlocksPlaced() + 1);

if (tools.getAdaptivePlaceDelay().get() && Place.getExtraPlaceDelay() > 0) {
if (Place.getExtraPlaceDelay() == 1) {
Place.setExtraPlaceDelay(0);
if (tools.getAdaptivePlaceDelay().get() && placeHandler.getExtraPlaceDelay() > 0) {
if (placeHandler.getExtraPlaceDelay() == 1) {
placeHandler.setExtraPlaceDelay(0);
} else {
Place.setExtraPlaceDelay(Place.getExtraPlaceDelay() / 2);
placeHandler.setExtraPlaceDelay(placeHandler.getExtraPlaceDelay() / 2);
}
}

Expand All @@ -109,7 +118,7 @@ private void doPlaced(BlockTask task) {
}

// break if target block is not the current block and target block is air
if (HighwayUtils.blockEqualsAndAirCheck(currentBlock, targetBlock) && HighwayUtils.isTypeAir(targetBlock)) {
if (BlockUtils.blockEqualsAndAirCheck(currentBlock, targetBlock) && BlockUtils.isTypeAir(targetBlock)) {
task.updateState(TaskState.BREAK);
return;
}
Expand Down Expand Up @@ -166,37 +175,37 @@ private void doBreak(BlockTask task, boolean check) {
// }

if (targetBlock == fillerBlock) {
if (HighwayUtils.blockEqualsAndAirCheck(currentBlock, targetBlock)) {
if (BlockUtils.blockEqualsAndAirCheck(currentBlock, targetBlock)) {
task.updateState(TaskState.DONE);
return;
}
}

if (targetBlock == mainBlock) {
if (HighwayUtils.blockEqualsAndAirCheck(currentBlock, targetBlock)) {
if (BlockUtils.blockEqualsAndAirCheck(currentBlock, targetBlock)) {
task.updateState(TaskState.DONE);
return;
}
}


if (HighwayUtils.isTypeAir(currentBlock)) {
if (HighwayUtils.isTypeAir(targetBlock)) {
if (BlockUtils.isTypeAir(currentBlock)) {
if (BlockUtils.isTypeAir(targetBlock)) {
task.updateState(TaskState.BROKEN);
} else {
task.updateState(TaskState.PLACE);
}
return;
}

if (Liquid.isLiquid(state)) {
Liquid.updateTask(task);
if (LiquidUtils.isLiquid(state)) {
liquidHandler.updateTask(task);
return;
}

if (check) return;
if (!mc.player.isOnGround()) return;
if (Liquid.handleLiquid(tools, task)) return;
if (liquidHandler.handleLiquid(task)) return;

mineBlock(task);
}
Expand All @@ -208,7 +217,7 @@ private void doPlace(BlockTask task, boolean check) {
Block targetBlock = task.getBlueprintTask().getTargetBlock();

// LIQUID
if (task.getTaskState() == TaskState.LIQUID && !Liquid.isLiquid(state)) {
if (task.getTaskState() == TaskState.LIQUID && !LiquidUtils.isLiquid(state)) {
task.updateState(TaskState.DONE);
return;
}
Expand All @@ -223,9 +232,9 @@ private void doPlace(BlockTask task, boolean check) {
return;
}

if (HighwayUtils.isTypeAir(targetBlock)) {
if (!Liquid.isLiquid(state)) {
if (!HighwayUtils.isTypeAir(block)) {
if (BlockUtils.isTypeAir(targetBlock)) {
if (!LiquidUtils.isLiquid(state)) {
if (!BlockUtils.isTypeAir(block)) {
task.updateState(TaskState.BREAK);
} else {
task.updateState(TaskState.BROKEN);
Expand All @@ -243,7 +252,7 @@ private void doPlace(BlockTask task, boolean check) {

if (check) return;

if (!BlockUtils.canPlace(task.getBlockPos(), true)) {
if (!meteordevelopment.meteorclient.utils.world.BlockUtils.canPlace(task.getBlockPos(), true)) {
return;
}

Expand All @@ -263,7 +272,7 @@ private void doPendingPlace(BlockTask task) {
Block block = state.getBlock();
Block targetBlock = task.getBlueprintTask().getTargetBlock();

if (task.getTaskState() == TaskState.LIQUID && !Liquid.isLiquid(state)) {
if (task.getTaskState() == TaskState.LIQUID && !LiquidUtils.isLiquid(state)) {
task.updateState(TaskState.DONE);
return;
}
Expand All @@ -278,9 +287,9 @@ private void doPendingPlace(BlockTask task) {
return;
}

if (HighwayUtils.isTypeAir(targetBlock)) {
if (!Liquid.isLiquid(state)) {
if (!HighwayUtils.isTypeAir(block)) {
if (BlockUtils.isTypeAir(targetBlock)) {
if (!LiquidUtils.isLiquid(state)) {
if (!BlockUtils.isTypeAir(block)) {
task.updateState(TaskState.BREAK);
} else {
task.updateState(TaskState.BROKEN);
Expand All @@ -301,19 +310,19 @@ private void mineBlock(BlockTask task) {
Rotations.rotate(Rotations.getYaw(pos), Rotations.getPitch(pos), () -> {});
}

Break.mine(task);
breakHandler.mine(task);
}

private void placeBlock(BlockTask task) {
Place.place(task);
placeHandler.place(task);
}

private boolean place(BlockTask task, int slot) {
if (tools.getRotation().get().place && tools.getRotateCamera().get() && mc.player != null) {
mc.player.setPitch((float) Rotations.getPitch(task.getBlockPos()));
mc.player.setYaw((float) Rotations.getYaw(task.getBlockPos()));
}
return BlockUtils.place(task.getBlockPos(), Hand.MAIN_HAND, slot, tools.getRotation().get().place, 0, true, true, false);
return meteordevelopment.meteorclient.utils.world.BlockUtils.place(task.getBlockPos(), Hand.MAIN_HAND, slot, tools.getRotation().get().place, 0, true, true, false);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package me.dynmie.highway.highwaytools.interaction;
package me.dynmie.highway.highwaytools.handler;

import me.dynmie.highway.highwaytools.block.BlockTask;
import me.dynmie.highway.highwaytools.block.TaskState;
import me.dynmie.highway.modules.HighwayTools;
import me.dynmie.highway.utils.InventoryUtils;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
Expand All @@ -18,20 +16,26 @@
/**
* @author dynmie
*/
public class Break {
public class BreakHandler {

private static final MinecraftClient mc = MinecraftClient.getInstance();

public static void mine(BlockTask task) {
private final HighwayTools tools;
private final InventoryHandler inventoryHandler;

public BreakHandler(HighwayTools tools, InventoryHandler inventoryHandler) {
this.tools = tools;
this.inventoryHandler = inventoryHandler;
}

public void mine(BlockTask task) {
Objects.requireNonNull(mc.player, "player should not be null");
Objects.requireNonNull(mc.world, "world should not be null");

HighwayTools tools = Modules.get().get(HighwayTools.class);

BlockPos pos = task.getBlockPos();
BlockState blockState = mc.world.getBlockState(pos);

mc.player.getInventory().selectedSlot = InventoryUtils.prepareToolInHotbar(blockState, tools.getPreferSilkTouch().get());
mc.player.getInventory().selectedSlot = inventoryHandler.prepareToolInHotbar(blockState);

int ticksNeeded = calcTicksToBreakBlock(pos, blockState);

Expand All @@ -44,7 +48,7 @@ public static void mine(BlockTask task) {
task.incrementMinedTicks();
}

private static void mineNormally(BlockTask task, int ticksRequired) {
private void mineNormally(BlockTask task, int ticksRequired) {
Objects.requireNonNull(mc.interactionManager, "interactionManager should not be null");

TaskState state = task.getTaskState();
Expand All @@ -60,7 +64,7 @@ private static void mineNormally(BlockTask task, int ticksRequired) {
sendStopPacket(pos, direction);
swingHand();

if (!Modules.get().get(HighwayTools.class).getAvoidMineGhostBlocks().get()) {
if (!tools.getAvoidMineGhostBlocks().get()) {
mc.interactionManager.breakBlock(pos);
}
} else {
Expand All @@ -69,12 +73,12 @@ private static void mineNormally(BlockTask task, int ticksRequired) {
}
}

private static void swingHand() {
private void swingHand() {
if (mc.player == null) return;
mc.player.swingHand(Hand.MAIN_HAND);
}

private static void sendStopPacket(BlockPos pos, Direction direction) {
private void sendStopPacket(BlockPos pos, Direction direction) {
if (mc.getNetworkHandler() == null) return;

mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(
Expand All @@ -84,7 +88,7 @@ private static void sendStopPacket(BlockPos pos, Direction direction) {
));
}

private static void sendStartPacket(BlockPos pos, Direction direction) {
private void sendStartPacket(BlockPos pos, Direction direction) {
if (mc.getNetworkHandler() == null) return;

mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(
Expand All @@ -94,7 +98,7 @@ private static void sendStartPacket(BlockPos pos, Direction direction) {
));
}

private static void sendAbortPacket(BlockPos pos, Direction direction) {
private void sendAbortPacket(BlockPos pos, Direction direction) {
if (mc.getNetworkHandler() == null) return;

mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(
Expand Down
Loading

0 comments on commit 0650aa0

Please sign in to comment.