Skip to content

Commit

Permalink
Safety features
Browse files Browse the repository at this point in the history
Investigated and found that some packets are being dropped server side.
  • Loading branch information
aria1th authored Aug 4, 2022
1 parent 93b8f82 commit 2b1468c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +54,7 @@ public class Printer {
public static int worldTopY = 256;
private static final LinkedHashMap<Long, String> causeMap = new LinkedHashMap<>();
private static final Long2LongOpenHashMap referenceSet = new Long2LongOpenHashMap();
private static final HashSet<Item> itemSet = new HashSet<>();


// TODO: This must be moved to another class and not be static.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 2b1468c

Please sign in to comment.