diff --git a/.gitignore b/.gitignore index d85df03..bf396c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,18 @@ -# Ignore Gradle project-specific cache directory +# IntelliJ IDEA stuff +.idea/ + +# VSCode stuff +.vscode/ + +# Gradle project-specific cache directory .gradle/ -# Ignore Gradle build output directory +# Gradle build output directory build/ bin/ -# Ignore run directory +# Run directory run/ -# IntelliJ IDEA -.idea/ - # Remapped source file directory remappedSrc/ diff --git a/LICENSE b/LICENSE index 1f29746..e00a53f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Adam Macdonald +Copyright (c) 2024 Adam Macdonald Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/gradle.properties b/gradle.properties index f36efe4..7c39f68 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,9 +6,9 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20.2 -yarn_mappings=1.20.2+build.4 -loader_version=0.14.24 +minecraft_version=1.20.4 +yarn_mappings=1.20.4+build.3 +loader_version=0.15.6 # Mod Properties mod_version = 0.1.2 @@ -16,4 +16,4 @@ maven_group = io.github.twokilohertz.hotbarreplace archives_base_name = HotbarReplace # Dependencies -fabric_version=0.90.4+1.20.2 +fabric_version=0.95.1+1.20.4 diff --git a/src/main/java/io/github/twokilohertz/hotbarreplace/HotbarReplace.java b/src/main/java/io/github/twokilohertz/hotbarreplace/HotbarReplace.java index 4326721..2fd21e4 100644 --- a/src/main/java/io/github/twokilohertz/hotbarreplace/HotbarReplace.java +++ b/src/main/java/io/github/twokilohertz/hotbarreplace/HotbarReplace.java @@ -28,34 +28,44 @@ public class HotbarReplace implements ModInitializer { public static void tryReplaceSlot(ItemPlacementContext context, Item item) { // Return immediately if player is a spectator PlayerEntity player = context.getPlayer(); - if (player.isSpectator()) return; + if (player.isSpectator()) + return; // Creative inventories don't run out of anyway - if (player.getAbilities().creativeMode) return; + if (player.getAbilities().creativeMode) + return; // Get reference to player's current inventory PlayerInventory inventory = player.getInventory(); - if (inventory == null) return; + if (inventory == null) + return; // Return if the inventory is empty - if (inventory.isEmpty()) return; + if (inventory.isEmpty()) + return; // If current screen handler is null, return - if (player.currentScreenHandler == null) return; + if (player.currentScreenHandler == null) + return; // 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); + client.interactionManager.clickSlot(player.currentScreenHandler.syncId, i, GLFW.GLFW_MOUSE_BUTTON_1, + SlotActionType.PICKUP, player); /* - Wait 50 milliseconds (on another thread) before attempting to move the new stack - PlayerInventory.MAIN_SIZE added to the selected slot (hotbar slot) is the correct slot ID - */ + * Wait 50 milliseconds (on another thread) before attempting to move the new + * stack + * PlayerInventory.MAIN_SIZE added to the selected slot (hotbar slot) is the + * correct slot ID + */ scheduler.schedule(() -> { - client.interactionManager.clickSlot(player.currentScreenHandler.syncId, inventory.selectedSlot + PlayerInventory.MAIN_SIZE, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.PICKUP, player); + client.interactionManager.clickSlot(player.currentScreenHandler.syncId, + inventory.selectedSlot + PlayerInventory.MAIN_SIZE, GLFW.GLFW_MOUSE_BUTTON_1, + SlotActionType.PICKUP, player); }, 50, TimeUnit.MILLISECONDS); } diff --git a/src/main/java/io/github/twokilohertz/hotbarreplace/mixin/BlockItemMixin.java b/src/main/java/io/github/twokilohertz/hotbarreplace/mixin/BlockItemMixin.java index 09a5163..eb68df2 100644 --- a/src/main/java/io/github/twokilohertz/hotbarreplace/mixin/BlockItemMixin.java +++ b/src/main/java/io/github/twokilohertz/hotbarreplace/mixin/BlockItemMixin.java @@ -18,13 +18,16 @@ public class BlockItemMixin { private void BlockItem_place_head(ItemPlacementContext context, CallbackInfoReturnable info) { lastPlacedItem = context.getStack().getItem(); } + @Inject(at = @At("TAIL"), method = "Lnet/minecraft/item/BlockItem;place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;") private void mixin_BlockItem_place_tail(ItemPlacementContext context, CallbackInfoReturnable info) { // Early return if the block place action would fail - if (info.getReturnValue() != ActionResult.SUCCESS) return; + if (info.getReturnValue() != ActionResult.SUCCESS) + return; // Check if the stack is not empty, return if so - if (context.getStack().getCount() != 0) return; + if (context.getStack().getCount() != 0) + return; // Try to replace the hotbar slot HotbarReplace.tryReplaceSlot(context, lastPlacedItem); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5e54f91..566fed2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -2,7 +2,6 @@ "schemaVersion": 1, "id": "hotbarreplace", "version": "${version}", - "name": "HotbarReplace", "description": "Replace blocks in your hotbar when you run out with blocks from your inventory", "authors": [ @@ -13,10 +12,8 @@ "sources": "https://github.com/twokilohertz/HotbarReplace", "issues": "https://github.com/twokilohertz/HotbarReplace/issues" }, - "license": "MIT", "icon": "assets/hotbarreplace/icon.png", - "environment": "*", "entrypoints": { "main": [ @@ -26,11 +23,10 @@ "mixins": [ "hotbarreplace.mixins.json" ], - "depends": { - "fabricloader": ">=0.14.21", + "fabricloader": ">=0.15.6", "fabric-api": "*", "minecraft": "~1.20", "java": ">=17" } -} +} \ No newline at end of file diff --git a/src/main/resources/hotbarreplace.mixins.json b/src/main/resources/hotbarreplace.mixins.json index 737c26c..51b0654 100644 --- a/src/main/resources/hotbarreplace.mixins.json +++ b/src/main/resources/hotbarreplace.mixins.json @@ -3,12 +3,11 @@ "minVersion": "0.8", "package": "io.github.twokilohertz.hotbarreplace.mixin", "compatibilityLevel": "JAVA_17", - "mixins": [ - ], + "mixins": [], "client": [ "BlockItemMixin" ], "injectors": { "defaultRequire": 1 } -} +} \ No newline at end of file