Compare commits
14 Commits
v0.1.0
...
v0.1.2_1.1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f6257060f0 | ||
![]() |
818c061195 | ||
![]() |
8a55f94d37 | ||
![]() |
533dc47607 | ||
![]() |
d119e650e1 | ||
![]() |
bad438ad38 | ||
![]() |
809870f4a9 | ||
![]() |
cbdb5f141c | ||
![]() |
5ee5d2632a | ||
![]() |
7cd6b9858c | ||
![]() |
216e0f9dfb | ||
![]() |
3a2bf3ed93 | ||
![]() |
0990b53056 | ||
![]() |
a5442206d1 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -3,9 +3,13 @@
|
|||||||
|
|
||||||
# Ignore Gradle build output directory
|
# Ignore Gradle build output directory
|
||||||
build/
|
build/
|
||||||
|
bin/
|
||||||
|
|
||||||
# Ignore run directory
|
# Ignore run directory
|
||||||
run/
|
run/
|
||||||
|
|
||||||
# IntelliJ IDEA
|
# IntelliJ IDEA
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
# Gradle wrapper binaries
|
||||||
|
gradle/wrapper/
|
||||||
|
30
LICENSE
30
LICENSE
@@ -1,15 +1,21 @@
|
|||||||
HotbarReplace Minecraft Mod
|
MIT License
|
||||||
Copyright (C) 2023 Adam Macdonald
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
Copyright (c) 2023 Adam Macdonald
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
in the Software without restriction, including without limitation the rights
|
||||||
GNU General Public License for more details.
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
The above copyright notice and this permission notice shall be included in all
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
## HotbarReplace
|
||||||
|
|
||||||
|
HotbarReplace is a Minecraft mod for the Fabric modding framework which replaces blocks in your hotbar with blocks of the same type from your inventory.
|
||||||
|
|
||||||
|
### Known issues/Improvements
|
||||||
|
|
||||||
|
* Make the mod more resilient to network delay and packet loss (don't hardcode a 50 ms delay)
|
@@ -6,14 +6,14 @@ org.gradle.parallel=true
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/develop
|
# check these on https://fabricmc.net/develop
|
||||||
minecraft_version=1.19.3
|
minecraft_version=1.19.4
|
||||||
yarn_mappings=1.19.3+build.5
|
yarn_mappings=1.19.4+build.2
|
||||||
loader_version=0.14.17
|
loader_version=0.14.21
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.1.0
|
mod_version = 0.1.2
|
||||||
maven_group = io.github.twokilohertz
|
maven_group = io.github.twokilohertz.hotbarreplace
|
||||||
archives_base_name = HotbarReplace
|
archives_base_name = HotbarReplace
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.76.0+1.19.3
|
fabric_version=0.83.0+1.19.4
|
||||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
7
gradlew
vendored
7
gradlew
vendored
@@ -85,9 +85,6 @@ done
|
|||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
|
|
||||||
@@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
# Collect all arguments for the java command;
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package io.github.twokilohertz;
|
package io.github.twokilohertz.hotbarreplace;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
@@ -6,13 +6,11 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.screen.slot.SlotActionType;
|
import net.minecraft.screen.slot.SlotActionType;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -24,7 +22,7 @@ public class HotbarReplace implements ModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
LOGGER.info("HotbarReplace initialised");
|
LOGGER.info("HotbarReplace v0.1.2 initialised");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tryReplaceSlot(ItemPlacementContext context, Item item) {
|
public static void tryReplaceSlot(ItemPlacementContext context, Item item) {
|
||||||
@@ -42,21 +40,22 @@ public class HotbarReplace implements ModInitializer {
|
|||||||
// Return if the inventory is empty
|
// Return if the inventory is empty
|
||||||
if (inventory.isEmpty()) return;
|
if (inventory.isEmpty()) return;
|
||||||
|
|
||||||
// Attempt to find a stack of matching items
|
// If current screen handler is null, return
|
||||||
for (int i = 0; i < inventory.main.size(); i++) {
|
if (player.currentScreenHandler == null) return;
|
||||||
if (i == inventory.selectedSlot) continue;
|
|
||||||
|
|
||||||
ItemStack stack = inventory.main.get(i);
|
// Attempt to find a stack of matching items in the player's inventory
|
||||||
|
for (int i = 0; i < player.currentScreenHandler.slots.size(); i++) {
|
||||||
if (stack.isOf(item)) {
|
if (player.currentScreenHandler.slots.get(i).getStack().isOf(item)) {
|
||||||
// Simulate moving the stack from one slot to another
|
// Simulate moving the stack from one slot to another
|
||||||
if (client != null) {
|
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 seconds (on another thread) before attempting to move the new stack
|
/*
|
||||||
// The magic number 36 is the offset to get the hotbar slotId
|
Wait 50 seconds (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(() -> {
|
scheduler.schedule(() -> {
|
||||||
client.interactionManager.clickSlot(player.currentScreenHandler.syncId, inventory.selectedSlot + 36, 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);
|
}, 50, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package io.github.twokilohertz.mixin;
|
package io.github.twokilohertz.hotbarreplace.mixin;
|
||||||
|
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
@@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import io.github.twokilohertz.HotbarReplace;
|
import io.github.twokilohertz.hotbarreplace.HotbarReplace;
|
||||||
|
|
||||||
@Mixin(BlockItem.class)
|
@Mixin(BlockItem.class)
|
||||||
public class BlockItemMixin {
|
public class BlockItemMixin {
|
Binary file not shown.
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -9,17 +9,18 @@
|
|||||||
"Adam Macdonald"
|
"Adam Macdonald"
|
||||||
],
|
],
|
||||||
"contact": {
|
"contact": {
|
||||||
"homepage": "https://twokilohertz.github.io/",
|
"homepage": "https://github.com/twokilohertz/HotbarReplace",
|
||||||
"sources": "https://twokilohertz.github.io/"
|
"sources": "https://github.com/twokilohertz/HotbarReplace",
|
||||||
|
"issues": "https://github.com/twokilohertz/HotbarReplace/issues"
|
||||||
},
|
},
|
||||||
|
|
||||||
"license": "GPLv3",
|
"license": "MIT",
|
||||||
"icon": "assets/hotbarreplace/icon.png",
|
"icon": "assets/hotbarreplace/icon.png",
|
||||||
|
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"main": [
|
"main": [
|
||||||
"io.github.twokilohertz.HotbarReplace"
|
"io.github.twokilohertz.hotbarreplace.HotbarReplace"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
@@ -27,9 +28,9 @@
|
|||||||
],
|
],
|
||||||
|
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.14.17",
|
"fabricloader": ">=0.14.21",
|
||||||
"fabric-api": "*",
|
"fabric-api": "*",
|
||||||
"minecraft": "~1.19.3",
|
"minecraft": "~1.19.4",
|
||||||
"java": ">=17"
|
"java": ">=17"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "io.github.twokilohertz.mixin",
|
"package": "io.github.twokilohertz.hotbarreplace.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user