diff --git a/gradle.properties b/gradle.properties index df88b7bf..c0aa43dd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx2G minecraft_version_out =1.19 # Mod Properties - mod_version = 6.6.0 + mod_version = 6.8.0 maven_group = net.fabricmc archives_base_name = litematica-printer diff --git a/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java b/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java index 010aa3f7..e5f147ab 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java @@ -13,6 +13,7 @@ public class LitematicaMixinMod implements ModInitializer { public static final ConfigBoolean USE_INVENTORY_CACHE = new ConfigBoolean("printerUseInventoryCache", true, "Uses Inventory cache instead of litematica's inventory utils."); public static final ConfigBoolean VERIFY_INVENTORY = new ConfigBoolean("verifierFindInventoryContents", true, "Schematic verifier will show blocks with inventory as wrong state."); public static final ConfigBoolean PRINTER_OFF = new ConfigBoolean("printerOff", false, "Disables printer."); + public static final ConfigBoolean PRINTER_ONLY_FAKE_ROTATION_MODE = new ConfigBoolean("easyPlaceMode++", false, "Disables printer and only make fake rotation work."); public static final ConfigBoolean INVENTORY_OPERATIONS = new ConfigBoolean("printerAllowInventoryOperations", false, "Printer will try to fill filters when screen is open and stop other actions"); public static final ConfigBoolean INVENTORY_OPERATIONS_CLOSE_SCREEN = new ConfigBoolean("inventoryCloseScreenAfterDone", false, "Screen will be closed after inventory filling operations"); public static final ConfigInteger INVENTORY_OPERATIONS_WAIT = new ConfigInteger("printerInventoryScreenWait", 200, 0, 8000, "Time(ms) to wait screen to be opened and synced"); @@ -60,6 +61,7 @@ public class LitematicaMixinMod implements ModInitializer { VERIFY_INVENTORY, USE_INVENTORY_CACHE, PRINTER_OFF, + PRINTER_ONLY_FAKE_ROTATION_MODE, DISABLE_SYNC, DEBUG_MESSAGE, DEBUG_EXTRA_MESSAGE, diff --git a/src/main/java/io/github/eatmyvenom/litematicin/mixin/Litematica/WorldUtilsMixin.java b/src/main/java/io/github/eatmyvenom/litematicin/mixin/Litematica/WorldUtilsMixin.java index 7b72f703..caba3dce 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/mixin/Litematica/WorldUtilsMixin.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/mixin/Litematica/WorldUtilsMixin.java @@ -12,6 +12,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import static io.github.eatmyvenom.litematicin.LitematicaMixinMod.PRINTER_ONLY_FAKE_ROTATION_MODE; + @Mixin(value = WorldUtils.class, remap = false, priority = 1010) public class WorldUtilsMixin { private static boolean hasSent = false; @@ -29,26 +31,31 @@ private static void onDoEasyPlaceAction(MinecraftClient mc, CallbackInfoReturnab if (mc.player == null) { return; } - if (LitematicaMixinMod.PRINTER_OFF.getBooleanValue()) { - return; + if (PRINTER_ONLY_FAKE_ROTATION_MODE.getBooleanValue()) { + cir.setReturnValue(Printer.doEasyPlaceFakeRotation(mc)); } - ActionResult defaultResult = ActionResult.SUCCESS; - try { - defaultResult = Printer.doPrinterAction(mc); - } catch (NullPointerException e) { - //in case of NPE, print log instead - MessageHolder.sendMessageUncheckedUnique(mc.player, e.getMessage()); - if (!hasSent && mc.player != null) { - mc.player.sendMessage(Text.of("Null pointer exception has occured, please upload log at https://github.com/aria1th/litematica-printer/issues")); - hasSent = true; + else { + if (LitematicaMixinMod.PRINTER_OFF.getBooleanValue()) { + return; } - } catch (AssertionError e) { - MessageHolder.sendOrderMessage("Order error happened " + e.getMessage()); - MessageHolder.sendMessageUncheckedUnique(mc.player, "Order Error Happened " + e.getMessage()); - cir.setReturnValue(ActionResult.FAIL); - return; + ActionResult defaultResult = ActionResult.SUCCESS; + try { + defaultResult = Printer.doPrinterAction(mc); + } catch (NullPointerException e) { + //in case of NPE, print log instead + MessageHolder.sendMessageUncheckedUnique(mc.player, e.getMessage()); + if (!hasSent && mc.player != null) { + mc.player.sendMessage(Text.of("Null pointer exception has occured, please upload log at https://github.com/aria1th/litematica-printer/issues")); + hasSent = true; + } + } catch (AssertionError e) { + MessageHolder.sendOrderMessage("Order error happened " + e.getMessage()); + MessageHolder.sendMessageUncheckedUnique(mc.player, "Order Error Happened " + e.getMessage()); + cir.setReturnValue(ActionResult.FAIL); + return; + } + cir.setReturnValue(defaultResult); + //return defaultResult; } - cir.setReturnValue(defaultResult); - //return defaultResult; } } diff --git a/src/main/java/io/github/eatmyvenom/litematicin/utils/FakeAccurateBlockPlacement.java b/src/main/java/io/github/eatmyvenom/litematicin/utils/FakeAccurateBlockPlacement.java index 8ce8dae4..23d76171 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/utils/FakeAccurateBlockPlacement.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/utils/FakeAccurateBlockPlacement.java @@ -101,10 +101,29 @@ public static void tick(ClientPlayNetworkHandler clientPlayNetworkHandler, Clien previousFakePitch = playerEntity.getPitch(); previousFakeYaw = playerEntity.getYaw(); } + if (requestedTicks == 0 && PRINTER_ONLY_FAKE_ROTATION_MODE.getBooleanValue()){ + placeFromQueue(); + } requestedTicks = requestedTicks - 1; blockPlacedInTick = 0; } - + public static void placeFromQueue() { + if (requestedTicks != 0) { + return; + } + PosWithBlock obj = waitingQueue.poll(); + if (obj != null) { + MessageHolder.sendOrderMessage("found block to place"); + if (canPlace(obj.blockState, obj.pos)) { + placeBlock(obj.pos, obj.blockState); + return; + } + else { + MessageHolder.sendOrderMessage("found block to place but can't place"); + } + } + waitingQueue.clear(); + } public static boolean emptyWaitingQueue() { if (requestedTicks != 0) { return false; @@ -274,6 +293,7 @@ private static Direction[] listClosest(Direction first, Direction second, Direct synchronized public static boolean request(BlockState blockState, BlockPos blockPos) { // instant if (!canPlace(blockState, blockPos) || blockState.isAir() || MaterialCache.getInstance().getRequiredBuildItemForState(blockState, SchematicWorldHandler.getSchematicWorld(), blockPos).getItem() == Items.AIR) { + MessageHolder.sendOrderMessage("Cannot place "+ blockState.toString() + " at " + blockPos.toShortString()); return false; } if (blockState.isOf(Blocks.GRINDSTONE)) { @@ -368,6 +388,7 @@ synchronized public static boolean request(BlockState blockState, BlockPos block } else { //delay if (isHandling() && (lookRefdir != fakeDirection || fp != fakePitch || fy != fakeYaw || !canPlaceWallMounted(blockState))) { + MessageHolder.sendOrderMessage("Cannot handle "+ blockState + " at " + blockPos.toShortString()); return false; } if (requestedTicks == 0 && fakeDirection == lookRefdir && fp == fakePitch && fy == fakeYaw) { @@ -377,7 +398,13 @@ synchronized public static boolean request(BlockState blockState, BlockPos block if (waitingQueue.isEmpty()) { request(fy, fp, lookRefdir, LitematicaMixinMod.FAKE_ROTATION_TICKS.getIntegerValue(), false); pickFirst(blockState, blockPos); - waitingQueue.offer(new PosWithBlock(blockPos, blockState)); + boolean offered = waitingQueue.offer(new PosWithBlock(blockPos, blockState)); + if (offered){ + MessageHolder.sendOrderMessage("Offered "+ blockState + " at " + blockPos.toShortString()); + } + else { + MessageHolder.sendOrderMessage("Cannot offer "+ blockState + " at " + blockPos.toShortString()); + } return false; } } diff --git a/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java b/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java index 6c2c5333..29372a2d 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java @@ -168,7 +168,34 @@ synchronized public static boolean doSchematicWorldPickBlock(MinecraftClient mc, } return false; } - + public static ActionResult doEasyPlaceFakeRotation(MinecraftClient mc) { //force normal easyplace action, ignore condition checks + RayTraceWrapper traceWrapper = RayTraceUtils.getGenericTrace(mc.world, mc.player, 6); + FakeAccurateBlockPlacement.requestedTicks = Math.max(-2, FakeAccurateBlockPlacement.requestedTicks); + if (traceWrapper == null) { + return ActionResult.PASS; + } + BlockHitResult trace = traceWrapper.getBlockHitResult(); + if (trace == null) { + return ActionResult.PASS; + } + World world = SchematicWorldHandler.getSchematicWorld(); + World clientWorld = mc.world; + BlockPos blockPos = trace.getBlockPos(); + if (isPositionCached(blockPos, false)){ + return ActionResult.PASS; + } + BlockState schematicState = world.getBlockState(blockPos); + BlockState clientState = clientWorld.getBlockState(blockPos); + if (schematicState.getBlock().getName().equals(clientState.getBlock().getName()) || schematicState.isAir()) { + return ActionResult.FAIL; + } + if (FakeAccurateBlockPlacement.canHandleOther(schematicState.getBlock().asItem()) && canPickBlock(mc, schematicState, blockPos)) { + MessageHolder.sendOrderMessage("Requested " + schematicState + " at " +blockPos.toShortString()); + FakeAccurateBlockPlacement.request(schematicState, blockPos); + return ActionResult.SUCCESS; + } + return ActionResult.FAIL; + } public static ActionResult doEasyPlaceNormally(MinecraftClient mc) { //force normal easyplace action, ignore condition checks RayTraceWrapper traceWrapper = RayTraceUtils.getGenericTrace(mc.world, mc.player, 6); if (traceWrapper == null) {