Skip to content

Commit

Permalink
Fix minigun slot locking GUI behaviour
Browse files Browse the repository at this point in the history
If "pick block" was bound to a key instead of "middle button" default,
slot locking stopped working. Also updated info in the GUI about which
key/button does slot locking.

#1378
  • Loading branch information
desht committed Dec 2, 2024
1 parent ccc8cc9 commit 326fba6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package me.desht.pneumaticcraft.client.gui;

import me.desht.pneumaticcraft.client.util.ClientUtils;
import me.desht.pneumaticcraft.client.util.GuiUtils;
import me.desht.pneumaticcraft.common.block.entity.AbstractPneumaticCraftBlockEntity;
import me.desht.pneumaticcraft.common.inventory.MinigunMagazineMenu;
Expand Down Expand Up @@ -45,7 +46,7 @@ public void init() {

addInfoTab(GuiUtils.xlateAndSplit("gui.tooltip.item.pneumaticcraft.minigun"));
addAnimatedStat(xlate("pneumaticcraft.gui.tab.minigun.slotInfo.title"), new ItemStack(ModItems.GUN_AMMO.get()), 0xFF0080C0, true)
.setText(GuiUtils.xlateAndSplit("pneumaticcraft.gui.tab.minigun.slotInfo"));
.setText(GuiUtils.xlateAndSplit("pneumaticcraft.gui.tab.minigun.slotInfo", ClientUtils.translateKeyBind(Minecraft.getInstance().options.keyPickItem)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
Expand Down Expand Up @@ -239,7 +238,7 @@ public static List<FormattedCharSequence> wrapTextComponentList(List<Component>
}

public static List<Component> xlateAndSplit(String key, Object... params) {
return Arrays.stream(StringUtils.splitByWholeSeparator(I18n.get(key, params), TRANSLATION_LINE_BREAK))
return Arrays.stream(StringUtils.splitByWholeSeparator(Component.translatable(key, params).getString(), TRANSLATION_LINE_BREAK))
.map(Component::literal)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.SlotItemHandler;

import static me.desht.pneumaticcraft.common.item.minigun.MinigunItem.NOT_LOCKED;

public class MinigunMagazineMenu extends AbstractPneumaticCraftMenu<AbstractPneumaticCraftBlockEntity> {
private final MinigunItem.MagazineHandler gunInv;
private final InteractionHand hand;
Expand Down Expand Up @@ -66,16 +68,12 @@ public boolean stillValid(Player player) {

@Override
public void clicked(int slotId, int dragType, ClickType clickType, Player player) {
if (clickType == ClickType.CLONE && dragType == 2 && slotId >= 0 && slotId < MinigunItem.MAGAZINE_SIZE) {
// middle-click to lock a slot
if (clickType == ClickType.CLONE && slotId >= 0 && slotId < MinigunItem.MAGAZINE_SIZE) {
// middle-click (or whatever "pick block" is bound to) to lock a slot
ItemStack gunStack = player.getItemInHand(hand);
if (gunStack.getItem() instanceof MinigunItem) {
int slot = MinigunItem.getLockedSlot(gunStack);
if (slot == slotId) {
gunStack.remove(ModDataComponents.MINIGUN_LOCKED_SLOT);
} else {
gunStack.set(ModDataComponents.MINIGUN_LOCKED_SLOT, slotId);
}
gunStack.set(ModDataComponents.MINIGUN_LOCKED_SLOT, slot == slotId ? NOT_LOCKED : slotId);
if (player.level().isClientSide) {
player.playSound(SoundEvents.UI_BUTTON_CLICK.value(), 0.5f, 1.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class MinigunItem extends PressurizableItem implements
IChargeableContainerProvider, IFOVModifierItem,
IInventoryItem, IShiftScrollable {
public static final int MAGAZINE_SIZE = 4;
private static final int NOT_LOCKED = -1;
public static final int NOT_LOCKED = -1;

public MinigunItem() {
super(ModItems.toolProps().component(ModDataComponents.MINIGUN_LOCKED_SLOT, NOT_LOCKED),
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/pneumaticcraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@
"pneumaticcraft.gui.tab.liquidCompressor.fuel" : "Available Fuels",
"pneumaticcraft.gui.tab.liquidHopper.mode.empty" : "Empty out tank.",
"pneumaticcraft.gui.tab.liquidHopper.mode.leaveLiquid" : "Leave 1000mB in tank, to filter.",
"pneumaticcraft.gui.tab.minigun.slotInfo" : "The Minigun will normally draw ammo from the lowest-numbered slot which contains any ammo.\n\n§aMiddle-click§f a slot to lock that slot: when locked, the Minigun will draw ammo from that slot only. §aMiddle-click§f a locked slot to unlock it.\n\nLocking slots is useful if you're carrying multiple ammo types.",
"pneumaticcraft.gui.tab.minigun.slotInfo" : "The Minigun will normally draw ammo from the lowest-numbered slot which contains any ammo.\n\nPress §a%s§f on a slot to toggle locking that slot: when locked, the Minigun will draw ammo from that slot only.\n\nLocking slots is useful if you're carrying multiple ammo types.",
"pneumaticcraft.gui.tab.minigun.slotInfo.title" : "Ammo Management",
"pneumaticcraft.gui.tab.omnidirectionalHopper.mode.empty" : "Normal Hopper Operation.",
"pneumaticcraft.gui.tab.omnidirectionalHopper.mode.leaveItem" : "Leave one item per slot, to filter.",
Expand Down

0 comments on commit 326fba6

Please sign in to comment.