From e287b9fad0f9461ca85d91780eb4734fc3063e49 Mon Sep 17 00:00:00 2001 From: ClovisLd Date: Mon, 5 Jan 2026 16:37:54 +0100 Subject: [PATCH] add the ability for the player to change the upgradetime working direction by sneak right clicking on the side of a drawer with the upgrade in hand --- .../functionalstorage/item/UpgradeItem.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java b/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java index e42e9d86..6a2a607f 100644 --- a/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java +++ b/src/main/java/com/buuz135/functionalstorage/item/UpgradeItem.java @@ -23,6 +23,9 @@ import net.minecraft.world.level.Level; import org.apache.commons.lang3.text.WordUtils; import org.jetbrains.annotations.Nullable; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.sounds.SoundSource; import java.util.Arrays; import java.util.List; @@ -125,6 +128,39 @@ public void addTooltipDetails(@Nullable BasicItem.Key key, ItemStack stack, List } + @Override + public InteractionResult useOn(UseOnContext context) { + Player player = context.getPlayer(); + // Check if player is sneaking and if this is a Puller/Pusher/Collector + if (player != null && player.isShiftKeyDown() && isDirectionUpgrade(this)) { + + // Get the face of the block that was clicked + Direction clickedFace = context.getClickedFace(); + ItemStack stack = context.getItemInHand(); + + // Set the Direction Component (1.21 Data Component style) + stack.set(FSAttachments.DIRECTION, clickedFace); + + // Play a sound so the player knows it worked + context.getLevel().playSound(player, context.getClickedPos(), SoundEvents.UI_BUTTON_CLICK.value(), SoundSource.PLAYERS, 0.5f, 1f); + + // Show a message above the hotbar (Action Bar) confirming the new direction + if (context.getLevel().isClientSide) { + player.displayClientMessage( + Component.translatable("item.utility.direction").withStyle(ChatFormatting.YELLOW) + .append(" ") + .append(Component.translatable("direction.titanium." + clickedFace.getName().toLowerCase(Locale.ROOT)).withStyle(ChatFormatting.WHITE)), + true + ); + } + + // Return SUCCESS so the game doesn't try to place the item or open the block's GUI + return InteractionResult.SUCCESS; + } + + return super.useOn(context); + } + public static boolean isDirectionUpgrade(Item item) { return (item.equals(FunctionalStorage.PULLING_UPGRADE.get()) || item.equals(FunctionalStorage.PUSHING_UPGRADE.get()) || item.equals(FunctionalStorage.COLLECTOR_UPGRADE.get())); }