Compare commits
2 Commits
v0.1.2_1.2
...
v0.1.2_1.2
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d701906701 | ||
![]() |
a4d23cb3f5 |
18
.gitignore
vendored
18
.gitignore
vendored
@@ -1,18 +1,18 @@
|
|||||||
# Ignore Gradle project-specific cache directory
|
# IntelliJ IDEA stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# VSCode stuff
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# Gradle project-specific cache directory
|
||||||
.gradle/
|
.gradle/
|
||||||
|
|
||||||
# Ignore Gradle build output directory
|
# Gradle build output directory
|
||||||
build/
|
build/
|
||||||
bin/
|
bin/
|
||||||
|
|
||||||
# Ignore run directory
|
# Run directory
|
||||||
run/
|
run/
|
||||||
|
|
||||||
# IntelliJ IDEA
|
|
||||||
.idea/
|
|
||||||
|
|
||||||
# Gradle wrapper binaries
|
|
||||||
gradle/wrapper/
|
|
||||||
|
|
||||||
# Remapped source file directory
|
# Remapped source file directory
|
||||||
remappedSrc/
|
remappedSrc/
|
||||||
|
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@@ -6,9 +6,9 @@ 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.20.2
|
minecraft_version=1.20.4
|
||||||
yarn_mappings=1.20.2+build.4
|
yarn_mappings=1.20.4+build.3
|
||||||
loader_version=0.14.24
|
loader_version=0.15.6
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.1.2
|
mod_version = 0.1.2
|
||||||
@@ -16,4 +16,4 @@ maven_group = io.github.twokilohertz.hotbarreplace
|
|||||||
archives_base_name = HotbarReplace
|
archives_base_name = HotbarReplace
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.90.4+1.20.2
|
fabric_version=0.95.1+1.20.4
|
||||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
17
gradlew
vendored
Normal file → Executable file
17
gradlew
vendored
Normal file → Executable file
@@ -83,7 +83,8 @@ done
|
|||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||||
|
|
||||||
# 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
|
||||||
@@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
@@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@@ -201,11 +202,11 @@ fi
|
|||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# 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"'
|
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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
# and any embedded shellness will be escaped.
|
||||||
# double quotes to make sure that they get re-expanded; and
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
@@ -28,34 +28,44 @@ public class HotbarReplace implements ModInitializer {
|
|||||||
public static void tryReplaceSlot(ItemPlacementContext context, Item item) {
|
public static void tryReplaceSlot(ItemPlacementContext context, Item item) {
|
||||||
// Return immediately if player is a spectator
|
// Return immediately if player is a spectator
|
||||||
PlayerEntity player = context.getPlayer();
|
PlayerEntity player = context.getPlayer();
|
||||||
if (player.isSpectator()) return;
|
if (player.isSpectator())
|
||||||
|
return;
|
||||||
|
|
||||||
// Creative inventories don't run out of anyway
|
// 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
|
// Get reference to player's current inventory
|
||||||
PlayerInventory inventory = player.getInventory();
|
PlayerInventory inventory = player.getInventory();
|
||||||
if (inventory == null) return;
|
if (inventory == null)
|
||||||
|
return;
|
||||||
|
|
||||||
// Return if the inventory is empty
|
// Return if the inventory is empty
|
||||||
if (inventory.isEmpty()) return;
|
if (inventory.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
// If current screen handler is null, 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
|
// Attempt to find a stack of matching items in the player's inventory
|
||||||
for (int i = 0; i < player.currentScreenHandler.slots.size(); i++) {
|
for (int i = 0; i < player.currentScreenHandler.slots.size(); i++) {
|
||||||
if (player.currentScreenHandler.slots.get(i).getStack().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 milliseconds (on another thread) before attempting to move the new stack
|
* Wait 50 milliseconds (on another thread) before attempting to move the new
|
||||||
PlayerInventory.MAIN_SIZE added to the selected slot (hotbar slot) is the correct slot ID
|
* 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 + 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);
|
}, 50, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,13 +18,16 @@ public class BlockItemMixin {
|
|||||||
private void BlockItem_place_head(ItemPlacementContext context, CallbackInfoReturnable<ActionResult> info) {
|
private void BlockItem_place_head(ItemPlacementContext context, CallbackInfoReturnable<ActionResult> info) {
|
||||||
lastPlacedItem = context.getStack().getItem();
|
lastPlacedItem = context.getStack().getItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "Lnet/minecraft/item/BlockItem;place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;")
|
@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<ActionResult> info) {
|
private void mixin_BlockItem_place_tail(ItemPlacementContext context, CallbackInfoReturnable<ActionResult> info) {
|
||||||
// Early return if the block place action would fail
|
// 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
|
// 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
|
// Try to replace the hotbar slot
|
||||||
HotbarReplace.tryReplaceSlot(context, lastPlacedItem);
|
HotbarReplace.tryReplaceSlot(context, lastPlacedItem);
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"id": "hotbarreplace",
|
"id": "hotbarreplace",
|
||||||
"version": "${version}",
|
"version": "${version}",
|
||||||
|
|
||||||
"name": "HotbarReplace",
|
"name": "HotbarReplace",
|
||||||
"description": "Replace blocks in your hotbar when you run out with blocks from your inventory",
|
"description": "Replace blocks in your hotbar when you run out with blocks from your inventory",
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -13,10 +12,8 @@
|
|||||||
"sources": "https://github.com/twokilohertz/HotbarReplace",
|
"sources": "https://github.com/twokilohertz/HotbarReplace",
|
||||||
"issues": "https://github.com/twokilohertz/HotbarReplace/issues"
|
"issues": "https://github.com/twokilohertz/HotbarReplace/issues"
|
||||||
},
|
},
|
||||||
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"icon": "assets/hotbarreplace/icon.png",
|
"icon": "assets/hotbarreplace/icon.png",
|
||||||
|
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"main": [
|
"main": [
|
||||||
@@ -26,9 +23,8 @@
|
|||||||
"mixins": [
|
"mixins": [
|
||||||
"hotbarreplace.mixins.json"
|
"hotbarreplace.mixins.json"
|
||||||
],
|
],
|
||||||
|
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.14.21",
|
"fabricloader": ">=0.15.6",
|
||||||
"fabric-api": "*",
|
"fabric-api": "*",
|
||||||
"minecraft": "~1.20",
|
"minecraft": "~1.20",
|
||||||
"java": ">=17"
|
"java": ">=17"
|
||||||
|
@@ -3,8 +3,7 @@
|
|||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "io.github.twokilohertz.hotbarreplace.mixin",
|
"package": "io.github.twokilohertz.hotbarreplace.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [],
|
||||||
],
|
|
||||||
"client": [
|
"client": [
|
||||||
"BlockItemMixin"
|
"BlockItemMixin"
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user