29 Commits

Author SHA1 Message Date
Adam Macdonald
3774b51f62 Update README 2024-07-21 13:48:45 +01:00
Adam Macdonald
dbd31e73d5 Fix version field in fabric.mod.json 2024-07-21 13:45:57 +01:00
Adam Macdonald
f3631bdedc Build correctly for 1.21 2024-07-21 13:41:04 +01:00
Adam Macdonald
737656c28d Upgrade Gradle wrapper 2024-07-20 10:19:32 +01:00
Adam Macdonald
47792bf8b9 Add demo GIF to the project's README 2024-01-24 15:24:15 +00:00
Adam Macdonald
d701906701 Update for Minecraft 1.20.4 2024-01-24 14:55:23 +00:00
Adam Macdonald
a4d23cb3f5 Bump Gradle to 8.5 2024-01-24 14:38:25 +00:00
Adam Macdonald
a2c9a3a000 Fix small typo in comment 2023-10-26 15:21:12 +01:00
Adam Macdonald
116b98edf0 Bump versions 2023-10-26 15:20:49 +01:00
Adam Macdonald
f7d3b293e7 Update .gitignore 2023-10-26 15:20:25 +01:00
Adam Macdonald
e402bd0749 Update Gradle wrapper scripts 2023-10-26 15:11:04 +01:00
Adam Macdonald
11dd1cf701 Rename logo.png -> icon.png 2023-06-08 01:54:20 +01:00
Adam Macdonald
1d18ffbe27 Update to Minecraft 1.20 2023-06-07 21:49:26 +01:00
Adam Macdonald
d7e5e2846f No more Gradle wrapper binaries :) 2023-05-31 16:59:14 +01:00
Adam Macdonald
e9bc7e34d5 Improve logo 2023-05-31 16:58:04 +01:00
Adam Macdonald
f6257060f0 Update to 1.19.4 and bump Fabric API version
Update for 1.19.4 and bump the API and mappings ahead of the 1.20
release! :)
2023-05-31 16:51:46 +01:00
Adam Macdonald
818c061195 Update to Gradle 8.1.1 2023-05-31 16:47:39 +01:00
Adam Macdonald
8a55f94d37 Update README 2023-03-29 19:30:50 +01:00
Adam Macdonald
533dc47607 Items from armour slots no longer moved to hotbar, fixes #1 2023-03-29 19:23:22 +01:00
Adam Macdonald
d119e650e1 Change license specification in mod json config 2023-03-27 21:37:14 +01:00
Adam Macdonald
bad438ad38 Change license to MIT license 2023-03-27 21:24:43 +01:00
Adam Macdonald
809870f4a9 Correct all package names & bump version to 0.1.1 2023-03-24 02:35:17 +00:00
Adam Macdonald
cbdb5f141c Don't hardcode a magic number for the hotbar slot ID offset 2023-03-24 02:28:34 +00:00
Adam Macdonald
5ee5d2632a Java source paths are correct now 2023-03-24 02:26:39 +00:00
Adam Macdonald
7cd6b9858c Update README 2023-03-24 01:20:50 +00:00
Adam Macdonald
216e0f9dfb Add README 2023-03-24 01:20:15 +00:00
Adam Macdonald
3a2bf3ed93 Update mod icon 2023-03-23 23:57:29 +00:00
Adam Macdonald
0990b53056 Update homepage, sources & issue tracker links 2023-03-23 23:19:58 +00:00
Adam Macdonald
a5442206d1 Remove unneeded import 2023-03-23 23:17:55 +00:00
19 changed files with 197 additions and 169 deletions

20
.gitignore vendored
View File

@@ -1,11 +1,21 @@
# Ignore Gradle project-specific cache directory # IntelliJ IDEA stuff
.idea/
# VSCode stuff
.vscode/
# Dolphin stuff
.directory
# Gradle project-specific cache directory
.gradle/ .gradle/
# Ignore Gradle build output directory # Gradle build output directory
build/ build/
bin/
# Ignore run directory # Run directory
run/ run/
# IntelliJ IDEA # Remapped source file directory
.idea/ remappedSrc/

30
LICENSE
View File

@@ -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) 2024 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.

11
README.md Normal file
View File

@@ -0,0 +1,11 @@
## 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 upon running out while placing, see demo GIF below to see how it works!
### Known issues/Improvements
* Make the mod more resilient to network delay and packet loss (don't hardcode a 50 ms delay)
### Demo GIF
![HotbarReplace Demo GIF](./docs/hotbarreplace-demo.gif)

View File

@@ -1,38 +1,37 @@
// https://github.com/FabricMC/fabric-example-mod/blob/9b028bdcd43190d4f848d5898b89177de6776535/build.gradle#L1
plugins { plugins {
id 'fabric-loom' version '1.1-SNAPSHOT' id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish' id 'maven-publish'
} }
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
archivesBaseName = project.archives_base_name
version = project.mod_version version = project.mod_version
group = project.maven_group group = project.maven_group
base {
archivesName = project.archives_base_name
}
repositories { repositories {
// Add repositories to retrieve artifacts from in here. // ...
// You should only use this when depending on other mods because }
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html loom {
// for more information about repositories. splitEnvironmentSourceSets()
mods {
"hotbarreplace" {
sourceSet sourceSets.main
// sourceSet sourceSets.client
}
}
} }
dependencies { dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}" minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
} }
processResources { processResources {
@@ -44,36 +43,31 @@ processResources {
} }
tasks.withType(JavaCompile).configureEach { tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17. it.options.release = 21
it.options.release = 17
} }
java { java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar() withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
} }
jar { jar {
from("LICENSE") { from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"} rename { "${it}_${project.base.archivesName.get()}"}
} }
} }
// configure the maven publication
publishing { publishing {
publications { publications {
mavenJava(MavenPublication) { create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java from components.java
} }
} }
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories { repositories {
// Add repositories to publish to here. // ...
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
} }
} }

BIN
docs/hotbarreplace-demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 MiB

View File

@@ -1,19 +1,16 @@
# https://github.com/FabricMC/fabric-example-mod/blob/9b028bdcd43190d4f848d5898b89177de6776535/gradle.properties#L1 # Done to increase the memory available to Gradle
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true org.gradle.parallel=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop minecraft_version=1.21
minecraft_version=1.19.3 yarn_mappings=1.21+build.9
yarn_mappings=1.19.3+build.5 loader_version=0.15.11
loader_version=0.14.17
# Mod Properties # Mod Properties
mod_version = 0.1.0 mod_version = 0.1.2
maven_group = io.github.twokilohertz maven_group = xyz.twokilohertz
archives_base_name = HotbarReplace archives_base_name = HotbarReplace
# Dependencies # Dependencies
fabric_version=0.76.0+1.19.3 fabric_version=0.100.7+1.21

Binary file not shown.

View File

@@ -1,6 +1,7 @@
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.9-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

34
gradlew vendored Normal file → Executable file
View File

@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# SPDX-License-Identifier: Apache-2.0
#
############################################################################## ##############################################################################
# #
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@@ -83,10 +85,9 @@ 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 -P "${APP_HOME:-./}" > /dev/null && printf '%s
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. ' "$PWD" ) || exit
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
@@ -133,18 +134,21 @@ location of your Java installation."
fi fi
else else
JAVACMD=java JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi fi
fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 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 +156,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
@@ -197,11 +201,15 @@ if "$cygwin" || "$msys" ; then
done done
fi fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
# shell script including quotes and variable substitutions, so put them in DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded. # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \

22
gradlew.bat vendored
View File

@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute if %ERRORLEVEL% equ 0 goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail

View File

@@ -1,14 +1,3 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/8.0.2/userguide/multi_project_builds.html
*/
// https://github.com/FabricMC/fabric-example-mod/blob/9b028bdcd43190d4f848d5898b89177de6776535/settings.gradle#L1
pluginManagement { pluginManagement {
repositories { repositories {
maven { maven {

View File

@@ -1,62 +1,71 @@
package io.github.twokilohertz; package xyz.twokilohertz;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity; 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;
public class HotbarReplace implements ModInitializer { public class HotbarReplace implements ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("hotbarreplace"); public static final Logger LOGGER = LoggerFactory.getLogger("hotbarreplace");
private static final MinecraftClient client = MinecraftClient.getInstance(); private static final MinecraftClient client = MinecraftClient.getInstance();
private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
@Override @Override
public void onInitialize() { public void onInitializeClient() {
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) {
// 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 blocks 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;
// 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)
if (i == inventory.selectedSlot) continue; return;
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 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(() -> { 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);
} }

View File

@@ -1,4 +1,4 @@
package io.github.twokilohertz.mixin; package xyz.twokilohertz.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 xyz.twokilohertz.HotbarReplace;
@Mixin(BlockItem.class) @Mixin(BlockItem.class)
public class BlockItemMixin { public class BlockItemMixin {
@@ -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);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -0,0 +1,35 @@
{
"schemaVersion": 1,
"id": "hotbarreplace",
"version": "0.1.2",
"name": "HotbarReplace",
"description": "Replace blocks in your hotbar when you run out with blocks from your inventory",
"authors": [
"Adam Macdonald"
],
"contact": {
"homepage": "https://github.com/twokilohertz/HotbarReplace",
"sources": "https://github.com/twokilohertz/HotbarReplace",
"issues": "https://github.com/twokilohertz/HotbarReplace/issues"
},
"license": "MIT",
"icon": "assets/hotbarreplace/icon.png",
"environment": "client",
"entrypoints": {
"client": [
"xyz.twokilohertz.HotbarReplace"
]
},
"mixins": [
{
"config": "hotbarreplace.mixins.json",
"environment": "client"
}
],
"depends": {
"fabricloader": ">=0.15.11",
"minecraft": "~1.21",
"java": ">=21",
"fabric-api": "*"
}
}

View File

@@ -0,0 +1,12 @@
{
"required": true,
"package": "xyz.twokilohertz.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [
"BlockItemMixin"
],
"injectors": {
"defaultRequire": 1
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

View File

@@ -1,35 +0,0 @@
{
"schemaVersion": 1,
"id": "hotbarreplace",
"version": "${version}",
"name": "HotbarReplace",
"description": "Replace blocks in your hotbar when you run out with blocks from your inventory",
"authors": [
"Adam Macdonald"
],
"contact": {
"homepage": "https://twokilohertz.github.io/",
"sources": "https://twokilohertz.github.io/"
},
"license": "GPLv3",
"icon": "assets/hotbarreplace/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"io.github.twokilohertz.HotbarReplace"
]
},
"mixins": [
"hotbarreplace.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.17",
"fabric-api": "*",
"minecraft": "~1.19.3",
"java": ">=17"
}
}

View File

@@ -1,14 +0,0 @@
{
"required": true,
"minVersion": "0.8",
"package": "io.github.twokilohertz.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"BlockItemMixin"
],
"injectors": {
"defaultRequire": 1
}
}