Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
22bfa12981 | |||
9d44d319d1 | |||
d8373f5469 |
@ -29,10 +29,10 @@ jobs:
|
|||||||
- name: Build with Gradle Wrapper
|
- name: Build with Gradle Wrapper
|
||||||
run: ./gradlew build
|
run: ./gradlew build
|
||||||
|
|
||||||
- name: Upload build artifacts
|
# - name: Upload build artifacts
|
||||||
uses: actions/upload-artifact@v4
|
# uses: actions/upload-artifact@v4
|
||||||
with:
|
# with:
|
||||||
name: JARs
|
# name: JARs
|
||||||
path: build/libs
|
# path: build/libs
|
||||||
retention-days: 30
|
# retention-days: 30
|
||||||
compression-level: 9
|
# compression-level: 9
|
||||||
|
@ -8,7 +8,7 @@ yarn_mappings=1.21.5+build.1
|
|||||||
loader_version=0.16.13
|
loader_version=0.16.13
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.1.4
|
mod_version = 0.1.5
|
||||||
maven_group = xyz.twokilohertz
|
maven_group = xyz.twokilohertz
|
||||||
archives_base_name = HotbarReplace
|
archives_base_name = HotbarReplace
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public class HotbarReplace implements ClientModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
LOGGER.info("HotbarReplace v0.1.4 initialised");
|
LOGGER.info("HotbarReplace v0.1.5 initialised");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tryReplaceSlot(PlayerEntity player, Hand hand, Item item) {
|
public static void tryReplaceSlot(PlayerEntity player, Hand hand, Item item) {
|
||||||
@ -50,19 +50,16 @@ public class HotbarReplace implements ClientModInitializer {
|
|||||||
// I honestly do not know Minecraft internals enough to be sure that there won't
|
// I honestly do not know Minecraft internals enough to be sure that there won't
|
||||||
// be de-sync issues.
|
// be de-sync issues.
|
||||||
|
|
||||||
int current_fps = client.getCurrentFps();
|
final int click_delay_ms = 50;
|
||||||
int click_delay = Math.round(1.0f / (float) current_fps) * 1000;
|
|
||||||
|
|
||||||
client.interactionManager.clickSlot(player.currentScreenHandler.syncId, i, GLFW.GLFW_MOUSE_BUTTON_1,
|
client.interactionManager.clickSlot(player.currentScreenHandler.syncId, i, GLFW.GLFW_MOUSE_BUTTON_1,
|
||||||
SlotActionType.PICKUP, player);
|
SlotActionType.PICKUP, player);
|
||||||
|
|
||||||
int slot = (hand == Hand.OFF_HAND ? 9 : inventory.getSelectedSlot());
|
int slot = (hand == Hand.OFF_HAND ? 9 : inventory.getSelectedSlot());
|
||||||
|
|
||||||
scheduler.schedule(() -> {
|
scheduler.schedule(() -> client.interactionManager.clickSlot(player.currentScreenHandler.syncId,
|
||||||
client.interactionManager.clickSlot(player.currentScreenHandler.syncId,
|
slot + PlayerInventory.MAIN_SIZE, GLFW.GLFW_MOUSE_BUTTON_1,
|
||||||
slot + PlayerInventory.MAIN_SIZE, GLFW.GLFW_MOUSE_BUTTON_1,
|
SlotActionType.PICKUP, player), click_delay_ms, TimeUnit.MILLISECONDS);
|
||||||
SlotActionType.PICKUP, player);
|
|
||||||
}, click_delay, TimeUnit.MILLISECONDS);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -22,28 +22,54 @@ public class ItemStackMixin {
|
|||||||
@Inject(at = @At("HEAD"), method = "use")
|
@Inject(at = @At("HEAD"), method = "use")
|
||||||
private void ItemStack_use_HEAD(World world, PlayerEntity player, Hand hand,
|
private void ItemStack_use_HEAD(World world, PlayerEntity player, Hand hand,
|
||||||
CallbackInfoReturnable<ActionResult> info) {
|
CallbackInfoReturnable<ActionResult> info) {
|
||||||
lastUsedItem = player.getStackInHand(hand).getItem();
|
if (!world.isClient())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Item item = player.getStackInHand(hand).getItem();
|
||||||
|
if (item == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastUsedItem = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "useOnBlock")
|
@Inject(at = @At("HEAD"), method = "useOnBlock")
|
||||||
private void ItemStack_useOnBlock_HEAD(ItemUsageContext context,
|
private void ItemStack_useOnBlock_HEAD(ItemUsageContext context,
|
||||||
CallbackInfoReturnable<ActionResult> info) {
|
CallbackInfoReturnable<ActionResult> info) {
|
||||||
lastUsedItem = context.getPlayer().getStackInHand(context.getHand()).getItem();
|
if (!context.getWorld().isClient())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Item item = context.getPlayer().getStackInHand(context.getHand()).getItem();
|
||||||
|
if (item == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastUsedItem = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "useOnEntity")
|
@Inject(at = @At("HEAD"), method = "useOnEntity")
|
||||||
private void ItemStack_useOnEntity_HEAD(PlayerEntity player, LivingEntity entity, Hand hand,
|
private void ItemStack_useOnEntity_HEAD(PlayerEntity player, LivingEntity entity, Hand hand,
|
||||||
CallbackInfoReturnable<ActionResult> info) {
|
CallbackInfoReturnable<ActionResult> info) {
|
||||||
lastUsedItem = player.getStackInHand(hand).getItem();
|
if (!player.getWorld().isClient())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Item item = player.getStackInHand(hand).getItem();
|
||||||
|
if (item == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastUsedItem = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "use")
|
@Inject(at = @At("TAIL"), method = "use")
|
||||||
private void ItemStack_use_TAIL(World world, PlayerEntity player, Hand hand,
|
private void ItemStack_use_TAIL(World world, PlayerEntity player, Hand hand,
|
||||||
CallbackInfoReturnable<ActionResult> info) {
|
CallbackInfoReturnable<ActionResult> info) {
|
||||||
|
if (!world.isClient())
|
||||||
|
return;
|
||||||
|
|
||||||
if (info.getReturnValue() != ActionResult.SUCCESS)
|
if (info.getReturnValue() != ActionResult.SUCCESS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (player.getStackInHand(hand).getCount() != 0)
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
|
|
||||||
|
if (stack.getCount() > 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
HotbarReplace.tryReplaceSlot(player, hand, lastUsedItem);
|
HotbarReplace.tryReplaceSlot(player, hand, lastUsedItem);
|
||||||
@ -51,13 +77,17 @@ public class ItemStackMixin {
|
|||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "useOnBlock")
|
@Inject(at = @At("TAIL"), method = "useOnBlock")
|
||||||
private void ItemStack_useOnBlock_TAIL(ItemUsageContext context, CallbackInfoReturnable<ActionResult> info) {
|
private void ItemStack_useOnBlock_TAIL(ItemUsageContext context, CallbackInfoReturnable<ActionResult> info) {
|
||||||
|
if (!context.getWorld().isClient())
|
||||||
|
return;
|
||||||
|
|
||||||
if (info.getReturnValue() != ActionResult.SUCCESS)
|
if (info.getReturnValue() != ActionResult.SUCCESS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PlayerEntity player = context.getPlayer();
|
PlayerEntity player = context.getPlayer();
|
||||||
Hand hand = context.getHand();
|
Hand hand = context.getHand();
|
||||||
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
|
|
||||||
if (player.getStackInHand(hand).getCount() != 0)
|
if (stack.getCount() != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
HotbarReplace.tryReplaceSlot(player, hand, lastUsedItem);
|
HotbarReplace.tryReplaceSlot(player, hand, lastUsedItem);
|
||||||
@ -69,9 +99,38 @@ public class ItemStackMixin {
|
|||||||
if (info.getReturnValue() != ActionResult.SUCCESS)
|
if (info.getReturnValue() != ActionResult.SUCCESS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (player.getStackInHand(hand).getCount() != 0)
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
|
|
||||||
|
if (stack.getCount() > 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
HotbarReplace.tryReplaceSlot(player, hand, lastUsedItem);
|
HotbarReplace.tryReplaceSlot(player, hand, lastUsedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(at = @At("HEAD"), method = "Lnet/minecraft/item/ItemStack;finishUsing(Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;)Lnet/minecraft/item/ItemStack;")
|
||||||
|
private void ItemStack_finishUsing_HEAD(World world, LivingEntity user,
|
||||||
|
CallbackInfoReturnable<ItemStack> info) {
|
||||||
|
if (!world.isClient())
|
||||||
|
return;
|
||||||
|
|
||||||
|
ItemStack stack = (ItemStack) (Object) this;
|
||||||
|
// ItemStack stack = info.getReturnValue(); -- only applicable when injecting at TAIL
|
||||||
|
|
||||||
|
if (lastUsedItem != stack.getItem())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Food items disappear into thin (minecraft:)air before their stack size reaches 0
|
||||||
|
if (stack.getCount() > 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!user.isPlayer())
|
||||||
|
return;
|
||||||
|
|
||||||
|
PlayerEntity player = (PlayerEntity) user;
|
||||||
|
|
||||||
|
if (!player.isMainPlayer())
|
||||||
|
return;
|
||||||
|
|
||||||
|
HotbarReplace.tryReplaceSlot(player, player.getActiveHand(), lastUsedItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"id": "hotbarreplace",
|
"id": "hotbarreplace",
|
||||||
"version": "0.1.4",
|
"version": "0.1.5",
|
||||||
"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": [
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"client": [
|
"client": [
|
||||||
"ItemStackMixin"
|
"ItemStackMixin"
|
||||||
],
|
],
|
||||||
|
"server": [],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user