Update to forge 41.0.64

Removed config option to disable pos shortcuts, instead they are now set to unbound by default
This commit is contained in:
Marcel Konrad
2022-07-08 23:27:17 +02:00
parent 913b27e016
commit 53ec08c9a6
11 changed files with 19 additions and 89 deletions

View File

@@ -14,9 +14,9 @@ import exopandora.worldhandler.usercontent.UsercontentLoader;
import exopandora.worldhandler.util.AdvancementHelper;
import exopandora.worldhandler.util.CommandHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.ClientRegistry;
import net.minecraftforge.client.event.RegisterClientCommandsEvent;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@@ -50,9 +50,9 @@ public class WorldHandler
Config.setupDirectories(WorldHandler.USERCONTENT_PATH);
modLoadingContext.registerConfig(Type.CLIENT, Config.CLIENT_SPEC, Main.MODID + "/" + Main.MODID + ".toml");
UsercontentLoader.load(WorldHandler.USERCONTENT_PATH);
modEventBus.register(Config.class);
modEventBus.addListener(WorldHandler.this::clientSetup);
modEventBus.addListener(WorldHandler.this::registerClientReloadListeners);
modEventBus.addListener(WorldHandler.this::registerKeyMappingsEvent);
modEventBus.addListener(Content::createRegistry);
modEventBus.addListener(Category::createRegistry);
modEventBus.addListener(Content::register);
@@ -68,9 +68,14 @@ public class WorldHandler
MinecraftForge.EVENT_BUS.addListener(KeyHandler::keyInputEvent);
MinecraftForge.EVENT_BUS.addListener(ClientEventHandler::renderLevelLastEvent);
MinecraftForge.EVENT_BUS.addListener(ClientEventHandler::clientTickEvent);
ClientRegistry.registerKeyBinding(KeyHandler.KEY_WORLD_HANDLER);
KeyHandler.updatePosKeys();
}
@SubscribeEvent
public void registerKeyMappingsEvent(RegisterKeyMappingsEvent event)
{
event.register(KeyHandler.KEY_WORLD_HANDLER);
event.register(KeyHandler.KEY_WORLD_HANDLER_POS1);
event.register(KeyHandler.KEY_WORLD_HANDLER_POS2);
}
@SubscribeEvent

View File

@@ -7,11 +7,7 @@ import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
import exopandora.worldhandler.event.KeyHandler;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.config.ModConfig.Type;
import net.minecraftforge.fml.event.config.ModConfigEvent.Reloading;
public class Config
{
@@ -89,15 +85,6 @@ public class Config
}
}
@SubscribeEvent
public static void configReload(Reloading event)
{
if(event.getConfig().getType().equals(Type.CLIENT))
{
KeyHandler.updatePosKeys();
}
}
public static void setupDirectories(Path path)
{
try

View File

@@ -1,6 +1,5 @@
package exopandora.worldhandler.config;
import exopandora.worldhandler.event.KeyHandler;
import exopandora.worldhandler.util.BlockPlacingMode;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
@@ -11,7 +10,6 @@ public class ConfigCategorySettings
{
private final BooleanValue commandSyntax;
private final BooleanValue shortcuts;
private final BooleanValue shortcutKeys;
private final BooleanValue tooltips;
private final BooleanValue watch;
private final BooleanValue smoothWatch;
@@ -37,10 +35,6 @@ public class ConfigCategorySettings
.translation("gui.worldhandler.config.settings.shortcuts")
.comment("Whether or not to display a row of quick access buttons at the top")
.define("shortcuts", false);
this.shortcutKeys = builder
.translation("gui.worldhandler.config.settings.key_shortcuts")
.comment("Whether or not to enable button keys for pos1 and pos2")
.define("key_shortcuts", false);
this.tooltips = builder
.translation("gui.worldhandler.config.settings.tooltips")
.comment("Whether or not to display tooltips for buttons")
@@ -115,23 +109,6 @@ public class ConfigCategorySettings
Config.set(this.shortcuts, enabled);
}
public boolean shortcutKeys()
{
return this.shortcutKeys.get();
}
public void setShortcutKeys(boolean enabled)
{
boolean previous = this.shortcutKeys();
Config.set(this.shortcutKeys, enabled);
if(previous != enabled)
{
KeyHandler.updatePosKeys();
}
}
public boolean tooltips()
{
return this.tooltips.get();

View File

@@ -1,65 +1,37 @@
package exopandora.worldhandler.event;
import org.apache.commons.lang3.ArrayUtils;
import org.lwjgl.glfw.GLFW;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.util.ActionHelper;
import exopandora.worldhandler.util.BlockHelper;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.ClientRegistry;
import net.minecraftforge.client.event.InputEvent.KeyInputEvent;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class KeyHandler
{
public static final KeyMapping KEY_WORLD_HANDLER = new KeyMapping("key.worldhandler", GLFW.GLFW_KEY_V, "key.categories.worldhandler");
public static final KeyMapping KEY_WORLD_HANDLER_POS1 = new KeyMapping("key.worldhandler.pos1", GLFW.GLFW_KEY_O, "key.categories.worldhandler");
public static final KeyMapping KEY_WORLD_HANDLER_POS2 = new KeyMapping("key.worldhandler.pos2", GLFW.GLFW_KEY_P, "key.categories.worldhandler");
public static final KeyMapping KEY_WORLD_HANDLER_POS1 = new KeyMapping("key.worldhandler.pos1", GLFW.GLFW_KEY_UNKNOWN, "key.categories.worldhandler");
public static final KeyMapping KEY_WORLD_HANDLER_POS2 = new KeyMapping("key.worldhandler.pos2", GLFW.GLFW_KEY_UNKNOWN, "key.categories.worldhandler");
@SubscribeEvent
public static void keyInputEvent(KeyInputEvent event)
public static void keyInputEvent(InputEvent.Key event)
{
if(Minecraft.getInstance() != null && Minecraft.getInstance().screen == null)
{
if(KEY_WORLD_HANDLER.isDown())
if(KEY_WORLD_HANDLER.consumeClick())
{
ActionHelper.displayGui();
}
else if(Config.getSettings().shortcutKeys() && KEY_WORLD_HANDLER_POS1.isDown())
else if(KEY_WORLD_HANDLER_POS1.consumeClick())
{
BlockHelper.pos1().set(BlockHelper.getFocusedBlockPos());
}
else if(Config.getSettings().shortcutKeys() && KEY_WORLD_HANDLER_POS2.isDown())
else if(KEY_WORLD_HANDLER_POS2.consumeClick())
{
BlockHelper.pos2().set(BlockHelper.getFocusedBlockPos());
}
}
}
public static void updatePosKeys()
{
boolean isRegistered = KeyHandler.arePosKeysRegistered();
if(Config.getSettings().shortcutKeys() && !isRegistered)
{
ClientRegistry.registerKeyBinding(KEY_WORLD_HANDLER_POS1);
ClientRegistry.registerKeyBinding(KEY_WORLD_HANDLER_POS2);
}
else if(!Config.getSettings().shortcutKeys() && isRegistered)
{
KeyHandler.removePosKeys();
}
}
public static boolean arePosKeysRegistered()
{
return ArrayUtils.contains(Minecraft.getInstance().options.keyMappings, KEY_WORLD_HANDLER_POS1) || ArrayUtils.contains(Minecraft.getInstance().options.keyMappings, KEY_WORLD_HANDLER_POS2);
}
public static void removePosKeys()
{
Minecraft.getInstance().options.keyMappings = ArrayUtils.removeElements(Minecraft.getInstance().options.keyMappings, KEY_WORLD_HANDLER_POS1, KEY_WORLD_HANDLER_POS2);
}
}

View File

@@ -29,7 +29,6 @@ public class ContentSettings extends ContentChild
{
SETTINGS.add(new BooleanSetting("command_syntax", Config.CLIENT.getSettings()::commandSyntax, Config.CLIENT.getSettings()::setCommandSyntax));
SETTINGS.add(new BooleanSetting("shortcuts", Config.CLIENT.getSettings()::shortcuts, Config.CLIENT.getSettings()::setShortcuts));
SETTINGS.add(new BooleanSetting("key_shortcuts", Config.CLIENT.getSettings()::shortcutKeys, Config.CLIENT.getSettings()::setShortcutKeys));
SETTINGS.add(new BooleanSetting("tooltips", Config.CLIENT.getSettings()::tooltips, Config.CLIENT.getSettings()::setTooltips));
SETTINGS.add(new BooleanSetting("watch", Config.CLIENT.getSettings()::watch, Config.CLIENT.getSettings()::setWatch));
SETTINGS.add(new BooleanSetting("smooth_watch", Config.CLIENT.getSettings()::smoothWatch, Config.CLIENT.getSettings()::setSmoothWatch));
@@ -84,7 +83,7 @@ public class ContentSettings extends ContentChild
});
container.add(settings);
this.valueField = new GuiTextFieldTooltip(x + 118, y + 24, 114, 20, Component.translatable("gui.worldhandler.generic.value"));
this.valueField.setFilter(string ->
{