Items from armour slots no longer moved to hotbar, fixes #1

This commit is contained in:
Adam Macdonald 2023-03-29 19:23:22 +01:00
parent d119e650e1
commit 533dc47607
2 changed files with 7 additions and 9 deletions

View File

@ -11,7 +11,7 @@ yarn_mappings=1.19.3+build.5
loader_version=0.14.17
# Mod Properties
mod_version = 0.1.1
mod_version = 0.1.2
maven_group = io.github.twokilohertz.hotbarreplace
archives_base_name = HotbarReplace

View File

@ -6,7 +6,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.SlotActionType;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
@ -23,7 +22,7 @@ public class HotbarReplace implements ModInitializer {
@Override
public void onInitialize() {
LOGGER.info("HotbarReplace v0.1.1 initialised");
LOGGER.info("HotbarReplace v0.1.2 initialised");
}
public static void tryReplaceSlot(ItemPlacementContext context, Item item) {
@ -41,13 +40,12 @@ public class HotbarReplace implements ModInitializer {
// Return if the inventory is empty
if (inventory.isEmpty()) return;
// Attempt to find a stack of matching items
for (int i = 0; i < inventory.main.size(); i++) {
if (i == inventory.selectedSlot) continue;
// If current screen handler is null, return
if (player.currentScreenHandler == null) return;
ItemStack stack = inventory.main.get(i);
if (stack.isOf(item)) {
// Attempt to find a stack of matching items in the player's inventory
for (int i = 0; i < player.currentScreenHandler.slots.size(); i++) {
if (player.currentScreenHandler.slots.get(i).getStack().isOf(item)) {
// Simulate moving the stack from one slot to another
if (client != null) {
client.interactionManager.clickSlot(player.currentScreenHandler.syncId, i, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.PICKUP, player);