From e6bd2f889f6078374b49da318f09bbcc29571db7 Mon Sep 17 00:00:00 2001 From: AngelBottomless <35677394+aria1th@users.noreply.github.com> Date: Wed, 24 Aug 2022 17:55:37 +0900 Subject: [PATCH] 6.5.0 --- 1.19.1/gradle.properties | 2 +- 1.19/gradle.properties | 2 +- .../eatmyvenom/litematicin/utils/Breaker.java | 4 +++ .../litematicin/utils/InventoryUtils.java | 25 +++++++++++++------ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/1.19.1/gradle.properties b/1.19.1/gradle.properties index dca96fbe..9a75552b 100644 --- a/1.19.1/gradle.properties +++ b/1.19.1/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx2G minecraft_version_out =1.19.1 # Mod Properties - mod_version = 6.3.0 + mod_version = 6.5.0 maven_group = net.fabricmc archives_base_name = litematica-printer diff --git a/1.19/gradle.properties b/1.19/gradle.properties index b21c23ef..0df9db70 100644 --- a/1.19/gradle.properties +++ b/1.19/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx2G minecraft_version_out =1.19 # Mod Properties - mod_version = 6.3.0 + mod_version = 6.5.0 maven_group = net.fabricmc archives_base_name = litematica-printer diff --git a/src/main/java/io/github/eatmyvenom/litematicin/utils/Breaker.java b/src/main/java/io/github/eatmyvenom/litematicin/utils/Breaker.java index cdc33f64..1d8a5c13 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/utils/Breaker.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/utils/Breaker.java @@ -29,6 +29,10 @@ public boolean startBreakingBlock(BlockPos pos, MinecraftClient mc) { this.breakingBlock = true; this.pos = pos; // Check for best tool in inventory + if (mc.world.getBlockState(pos).getHardness(mc.world, pos) == 0) { + mc.interactionManager.attackBlock(pos, Direction.UP); + return false; + } int bestSlotId = getBestItemSlotIdToMineBlock(mc, pos); // If slot isn't selected, change if (bestSlotId != -1) { 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 c923c164..d5835f89 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java @@ -1,7 +1,8 @@ package io.github.eatmyvenom.litematicin.utils; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; import io.github.eatmyvenom.litematicin.LitematicaMixinMod; -import it.unimi.dsi.fastutil.ints.IntArraySet; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.client.MinecraftClient; @@ -11,6 +12,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.ToolItem; import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; +import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -25,7 +27,7 @@ public class InventoryUtils { public static Item handlingItem = null; public static Item previousItem = null; //only used for checks public static int trackedSelectedSlot = -1; - public static IntArraySet usedSlots = new IntArraySet(9); + public static BiMap usedSlots = HashBiMap.create(); public static void decrementCount() { if (lastCount > 0) { @@ -35,10 +37,9 @@ public static void decrementCount() { public static int getAvailableSlot() { for (int i = 0; i < 9; i++) { - if (usedSlots.contains(i)) { + if (usedSlots.containsKey(i)) { continue; } - usedSlots.add(i); return i; } return -1; @@ -109,11 +110,17 @@ synchronized public static boolean swapToItem(MinecraftClient client, ItemStack assert previousItem == stack.getItem() : "Handling item : " + handlingItem + " was not equal to " + stack.getItem(); MessageHolder.sendOrderMessage("Didn't require swap for item " + stack.getItem() + " previous handling item : " + previousItem); lastCount = player.getAbilities().creativeMode ? 65536 : getMainHandStack(player).getCount(); - usedSlots.add(player.getInventory().selectedSlot); + usedSlots.put(player.getInventory().selectedSlot, getMainHandStack(player).getItem()); return true; } + if (usedSlots.containsValue(stack.getItem())) { + player.getInventory().selectedSlot = usedSlots.inverse().get(stack.getItem()); + trackedSelectedSlot = player.getInventory().selectedSlot; + client.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(player.getInventory().selectedSlot)); + return !player.getInventory().getMainHandStack().isEmpty(); + } if (survivalSwap(client, player, stack)) { - usedSlots.add(player.getInventory().selectedSlot); + usedSlots.put(player.getInventory().selectedSlot, stack.getItem()); MessageHolder.sendOrderMessage("Swapped to item " + stack.getItem()); handlingItem = stack.getItem(); previousItem = handlingItem; @@ -137,9 +144,10 @@ private static boolean creativeSwap(MinecraftClient client, ClientPlayerEntity p int selectedSlot = getAvailableSlot(); player.getInventory().selectedSlot = selectedSlot; + trackedSelectedSlot = selectedSlot; player.playerScreenHandler.getSlot(36 + selectedSlot).setStack(stack); client.interactionManager.clickCreativeStack(getMainHandStack(player), 36 + selectedSlot); - usedSlots.add(player.getInventory().selectedSlot); + usedSlots.put(player.getInventory().selectedSlot, stack.getItem()); lastCount = 65536; handlingItem = stack.getItem(); previousItem = handlingItem; @@ -166,7 +174,7 @@ private static boolean survivalSwap(MinecraftClient client, ClientPlayerEntity p trackedSelectedSlot = slot; MessageHolder.sendOrderMessage("Selected Slot " + slot); lastCount = client.player.getAbilities().creativeMode ? 65536 : client.player.getInventory().getStack(slot).getCount(); - //client.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(slot)); + client.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(slot)); } else { int selectedSlot = getAvailableSlot(); if (selectedSlot == -1) { @@ -177,6 +185,7 @@ private static boolean survivalSwap(MinecraftClient client, ClientPlayerEntity p MessageHolder.sendOrderMessage("Slot at " + slot + " is swapped with " + selectedSlot); client.interactionManager.clickSlot(player.playerScreenHandler.syncId, slot, selectedSlot, SlotActionType.SWAP, player); player.getInventory().selectedSlot = selectedSlot; + trackedSelectedSlot = selectedSlot; } try {