Skip to content

Commit

Permalink
6.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aria1th authored Aug 24, 2022
1 parent 8c8e5db commit e6bd2f8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion 1.19.1/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion 1.19/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<Integer, Item> usedSlots = HashBiMap.create();

public static void decrementCount() {
if (lastCount > 0) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit e6bd2f8

Please sign in to comment.