From 2b1468c047c9f0d783f1edf8d3890392d4c5ff7b Mon Sep 17 00:00:00 2001 From: AngelBottomless <35677394+aria1th@users.noreply.github.com> Date: Thu, 4 Aug 2022 23:15:08 +0900 Subject: [PATCH] Safety features Investigated and found that some packets are being dropped server side. --- .../eatmyvenom/litematicin/LitematicaMixinMod.java | 2 ++ .../eatmyvenom/litematicin/utils/InventoryUtils.java | 5 +++++ .../github/eatmyvenom/litematicin/utils/Printer.java | 10 +++++----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java b/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java index bfffa2e2..b74e4a62 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java @@ -23,6 +23,7 @@ public class LitematicaMixinMod implements ModInitializer { public static final ConfigInteger EASY_PLACE_MODE_RANGE_Y = new ConfigInteger("easyPlaceModePrinterRangeY", 3, 0, 1024, "Y Range for EasyPlace"); public static final ConfigInteger EASY_PLACE_MODE_RANGE_Z = new ConfigInteger("easyPlaceModePrinterRangeZ", 3, 0, 1024, "Z Range for EasyPlace"); public static final ConfigInteger PRINTER_MAX_BLOCKS = new ConfigInteger("easyPlaceModePrinterMaxBlocks", 3, 1, 1000000, "Max block interactions per cycle"); + public static final ConfigInteger PRINTER_MAX_ITEM_CHANGES = new ConfigInteger("easyPlaceModePrinterMaxItemChanges", 3, 1, 1000000, "Max item categories per cycle"); public static final ConfigBoolean PRINTER_BREAK_BLOCKS = new ConfigBoolean("printerBreakBlocks", false, "Automatically breaks blocks."); public static final ConfigDouble EASY_PLACE_MODE_DELAY = new ConfigDouble("easyPlaceModeDelay", 0.2, 0.0, 1.0, "Delay between printing blocks.\n Recommended to set value over 0.05(50ms)."); public static final ConfigBoolean EASY_PLACE_MODE_HOTBAR_ONLY = new ConfigBoolean("easyPlaceModeHotbarOnly", false, "Only place blocks from your hotbar."); @@ -54,6 +55,7 @@ public class LitematicaMixinMod implements ModInitializer { EASY_PLACE_MODE_RANGE_Y, EASY_PLACE_MODE_RANGE_Z, PRINTER_MAX_BLOCKS, + PRINTER_MAX_ITEM_CHANGES, PRINTER_BREAK_BLOCKS, EASY_PLACE_MODE_DELAY, EASY_PLACE_MODE_HOTBAR_ONLY, diff --git a/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java b/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java index ce4633ff..c5fe8910 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java @@ -112,6 +112,11 @@ private static boolean survivalSwap(MinecraftClient client, ClientPlayerEntity p int selectedSlot = player.getInventory().selectedSlot; client.interactionManager.clickSlot(player.playerScreenHandler.syncId, slot, selectedSlot, SlotActionType.SWAP, player); } + try { + assert player.getMainHandStack().isItemEqual(stack); + } catch (Exception e) { + MessageHolder.sendMessageUncheckedUnique(player, stack.toString() + " does not match with " + player.getMainHandStack().toString() + "!"); + } return true; } 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 cd410f79..6119697a 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java @@ -26,10 +26,7 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.fluid.LavaFluid; import net.minecraft.fluid.WaterFluid; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; +import net.minecraft.item.*; import net.minecraft.state.property.Properties; import net.minecraft.tag.BlockTags; import net.minecraft.util.ActionResult; @@ -57,6 +54,7 @@ public class Printer { public static int worldTopY = 256; private static final LinkedHashMap causeMap = new LinkedHashMap<>(); private static final Long2LongOpenHashMap referenceSet = new Long2LongOpenHashMap(); + private static final HashSet itemSet = new HashSet<>(); // TODO: This must be moved to another class and not be static. @@ -134,6 +132,7 @@ public static boolean doSchematicWorldPickBlock(MinecraftClient mc, BlockState p return false; } if (!stack.isEmpty()) { + itemSet.add(stack.getItem()); return io.github.eatmyvenom.litematicin.utils.InventoryUtils.swapToItem(mc, stack); } return false; @@ -237,6 +236,7 @@ private static String internalGetReason(Long pos, LongOpenHashSet set, int count @Environment(EnvType.CLIENT) public static ActionResult doPrinterAction(MinecraftClient mc) { + itemSet.clear(); if (!DEBUG_MESSAGE.getBooleanValue()) { causeMap.clear(); //reduce ram usage } @@ -392,7 +392,7 @@ public static ActionResult doPrinterAction(MinecraftClient mc) { for (int y = fromY; y <= toY; y++) { for (int x = fromX; x <= toX; x++) { for (int z = fromZ; z <= toZ; z++) { - if (interact >= maxInteract) { + if (interact >= maxInteract || itemSet.size() >= PRINTER_MAX_ITEM_CHANGES.getIntegerValue()) { lastPlaced = new Date().getTime(); return ActionResult.SUCCESS; }