Skip to content

Commit

Permalink
Add keybind for Tool Settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Oct 19, 2024
1 parent 5af1a42 commit d695f8e
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.1 2024-10-08T16:36:37.283985 Languages: en_us for mod: justdirethings
96bc43e5eceb21c7648659daa43d1b5415e229bc assets/justdirethings/lang/en_us.json
// 1.21.1 2024-10-18T20:02:46.3102567 Languages: en_us for mod: justdirethings
c7f1cc2b04789bf34333113ee3c1fcd58eb116b2 assets/justdirethings/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
"justdirethings.jumpboost.detailtext": "Jump Higher",
"justdirethings.key.category": "Just Dire Things",
"justdirethings.key.toggle_tool": "Toggle Tool Abilities",
"justdirethings.key.toolUI": "Open Tool Settings UI",
"justdirethings.lavaimmunity.detailtext": "No Damage from Lava or Fire",
"justdirethings.lavaimmunity.flavortext": "Fancy a swim?",
"justdirethings.lavarepair.detailtext": "Drop item in Lava to repair it",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
public class KeyBindings {
private static final Logger LOGGER = LoggerFactory.getLogger(KeyBindings.class);
private static final KeyConflictContextGadget CONFLICT_CONTEXT_GADGET = new KeyConflictContextGadget();
private static final KeyConflictContextConfigScreen CONFLICT_CONTEXT_CONFIG = new KeyConflictContextConfigScreen();

private static final List<KeyMapping> keyMappings = new ArrayList<>();

public static KeyMapping toggleTool = createBinding("toggle_tool", GLFW.GLFW_KEY_V);
public static KeyMapping toolUI = createBindingGUI("toolUI", -1);
/*public static KeyMapping undo = createBinding("undo", GLFW.GLFW_KEY_U);
public static KeyMapping anchor = createBinding("anchor", GLFW.GLFW_KEY_H);
public static KeyMapping range = createBinding("range", GLFW.GLFW_KEY_R);*/
Expand All @@ -40,6 +42,12 @@ private static KeyMapping createBinding(String name, int key) {
return keyBinding;
}

private static KeyMapping createBindingGUI(String name, int key) {
KeyMapping keyBinding = new KeyMapping(getKey(name), CONFLICT_CONTEXT_CONFIG, InputConstants.Type.KEYSYM.getOrCreate(key), getKey("category"));
keyMappings.add(keyBinding);
return keyBinding;
}

@SubscribeEvent
public static void registerKeyMappings(RegisterKeyMappingsEvent event) {
LOGGER.debug("Registering {} keybinding for {}", keyMappings.size(), JustDireThings.MODID);
Expand Down Expand Up @@ -69,4 +77,17 @@ public boolean conflicts(IKeyConflictContext other) {
return other == this || other == KeyConflictContext.IN_GAME;
}
}

public static class KeyConflictContextConfigScreen implements IKeyConflictContext {
@Override
public boolean isActive() {
Player player = Minecraft.getInstance().player;
return !KeyConflictContext.GUI.isActive() && player != null;
}

@Override
public boolean conflicts(IKeyConflictContext other) {
return other == this || other == KeyConflictContext.IN_GAME;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.direwolf20.justdirethings.common.items.interfaces.ToggleableTool;
import com.direwolf20.justdirethings.common.network.data.LeftClickPayload;
import com.direwolf20.justdirethings.common.network.data.ToggleToolPayload;
import com.direwolf20.justdirethings.common.network.data.ToolSettingsGUIPayload;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -41,6 +42,10 @@ public static void handleEventInput(ClientTickEvent.Post event) {
if (mc.player == null)
return;

if (KeyBindings.toolUI.consumeClick()) {
PacketDistributor.sendToServer(new ToolSettingsGUIPayload());
}

KeyMapping keyMapping = KeyBindings.toggleTool;
ItemStack portalGun = PortalGunV2.getPortalGunv2(mc.player);
if (!portalGun.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ToolSettingScreen extends AbstractContainerScreen<ToolSettingContai

protected final ToolSettingContainer container;
Player player;
protected ItemStack tool;
protected ItemStack tool = ItemStack.EMPTY;
private EnumSet<Ability> abilities = EnumSet.noneOf(Ability.class);
int buttonsStartX = getGuiLeft() + 5;
int buttonsStartY = getGuiTop() + 15;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void registerNetworking(final RegisterPayloadHandlersEvent event)
registrar.playToServer(InventoryHolderMoveItemsPayload.TYPE, InventoryHolderMoveItemsPayload.STREAM_CODEC, InventoryHolderMoveItemsPacket.get()::handle);
registrar.playToServer(ExperienceHolderPayload.TYPE, ExperienceHolderPayload.STREAM_CODEC, ExperienceHolderPacket.get()::handle);
registrar.playToServer(ExperienceHolderSettingsPayload.TYPE, ExperienceHolderSettingsPayload.STREAM_CODEC, ExperienceHolderSettingsPacket.get()::handle);
registrar.playToServer(ToolSettingsGUIPayload.TYPE, ToolSettingsGUIPayload.STREAM_CODEC, ToolSettingsGUIPacket.get()::handle);

//Going to Client
registrar.playToClient(ClientSoundPayload.TYPE, ClientSoundPayload.STREAM_CODEC, ClientSoundPacket.get()::handle);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.direwolf20.justdirethings.common.network.data;

import com.direwolf20.justdirethings.JustDireThings;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;

public record ToolSettingsGUIPayload(

) implements CustomPacketPayload {
public static final ToolSettingsGUIPayload INSTANCE = new ToolSettingsGUIPayload();
public static final Type<ToolSettingsGUIPayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(JustDireThings.MODID, "tool_settings_gui"));

@Override
public Type<ToolSettingsGUIPayload> type() {
return TYPE;
}

public static final StreamCodec<ByteBuf, ToolSettingsGUIPayload> STREAM_CODEC = StreamCodec.unit(INSTANCE);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.direwolf20.justdirethings.common.network.handler;

import com.direwolf20.justdirethings.common.containers.ToolSettingContainer;
import com.direwolf20.justdirethings.common.network.data.ToolSettingsGUIPayload;
import net.minecraft.network.chat.Component;
import net.minecraft.world.SimpleMenuProvider;
import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.network.handling.IPayloadContext;

public class ToolSettingsGUIPacket {
public static final ToolSettingsGUIPacket INSTANCE = new ToolSettingsGUIPacket();

public static ToolSettingsGUIPacket get() {
return INSTANCE;
}

public void handle(final ToolSettingsGUIPayload payload, final IPayloadContext context) {
context.enqueueWork(() -> {
Player sender = context.player();
sender.openMenu(new SimpleMenuProvider(
(windowId, playerInventory, playerEntity) -> new ToolSettingContainer(windowId, playerInventory, sender), Component.translatable("")));

});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ protected void addTranslations() {
//Keys
add("justdirethings.key.category", "Just Dire Things");
add("justdirethings.key.toggle_tool", "Toggle Tool Abilities");
add("justdirethings.key.toolUI", "Open Tool Settings UI");

//Abilities
add(Ability.MOBSCANNER.getLocalization(), "Mob Scanner");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
{
"type": "patchouli:text",
"text": "Shift-Click the tool when it's in your hand to configure it. From here, you can toggle on or off specific upgrades by clicking on them.$(br2)Right click the upgrade to change some settings (if they have any) or assign a hotkey. If the ability is passive, the hotkey will toggle its activation. If the ability is active, the hotkey will trigger it."
"text": "Shift-Click the tool when it's in your hand to configure it (there is also a hotkey for this screen). From here, you can toggle on or off specific upgrades by clicking on them.$(br2)Right click the upgrade to change some settings (if they have any) or assign a hotkey. If the ability is passive, the hotkey will toggle its activation. If the ability is active, the hotkey will trigger it."
},
{
"type": "patchouli:text",
Expand Down

0 comments on commit d695f8e

Please sign in to comment.