added key binding system
This commit is contained in:
@@ -5,7 +5,7 @@ import net.minecraft.text.LiteralText;
|
||||
|
||||
public class GuiScreen extends Screen {
|
||||
|
||||
protected GuiScreen(String name) {
|
||||
public GuiScreen(String name) {
|
||||
super(new LiteralText(name));
|
||||
}
|
||||
|
||||
@@ -14,4 +14,9 @@ public class GuiScreen extends Screen {
|
||||
this.renderBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPauseScreen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package kaptainwutax.seedcracker.init;
|
||||
|
||||
import kaptainwutax.seedcracker.util.Log;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
public class KeyBindings {
|
||||
|
||||
public static LinkedHashSet<KeyBinding> KEY_REGISTRY = new LinkedHashSet<>();
|
||||
public static LinkedHashSet<String> CATEGORY_REGISTRY = new LinkedHashSet<>();
|
||||
|
||||
public static KeyBinding OPEN_MENU = new KeyBinding(getName("open_menu"), 'M', getCategory("seedcracker"));
|
||||
|
||||
static {
|
||||
registerKeyBinding(OPEN_MENU);
|
||||
}
|
||||
|
||||
/*
|
||||
* Registers keys and their categories. Remember that everything is FIFO.
|
||||
*/
|
||||
private static void registerKeyBinding(KeyBinding keyBinding) {
|
||||
if(keyBinding == null) {
|
||||
throw new NullPointerException("Cannot register a null key binding!");
|
||||
} else {
|
||||
KEY_REGISTRY.add(keyBinding);
|
||||
CATEGORY_REGISTRY.add(keyBinding.getCategory());
|
||||
Log.debug("Registering key [" + keyBinding.getName() + ", " + keyBinding.getId() + "] from category [" + keyBinding.getCategory() + "].");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Generates the category and key prefixes for the language files.
|
||||
*/
|
||||
public static String getCategory(String registryName) {
|
||||
return "key.categories." + registryName;
|
||||
}
|
||||
|
||||
public static String getName(String registryName) {
|
||||
return "key." + registryName.toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package kaptainwutax.seedcracker.mixin;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import kaptainwutax.seedcracker.SeedCracker;
|
||||
import kaptainwutax.seedcracker.command.ClientCommands;
|
||||
import kaptainwutax.seedcracker.init.ClientCommands;
|
||||
import kaptainwutax.seedcracker.cracker.storage.HashedSeedData;
|
||||
import kaptainwutax.seedcracker.finder.FinderQueue;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
@@ -2,7 +2,10 @@ package kaptainwutax.seedcracker.mixin;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import kaptainwutax.seedcracker.SeedCracker;
|
||||
import kaptainwutax.seedcracker.command.ClientCommands;
|
||||
import kaptainwutax.seedcracker.gui.GuiScreen;
|
||||
import kaptainwutax.seedcracker.init.ClientCommands;
|
||||
import kaptainwutax.seedcracker.init.KeyBindings;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -17,6 +20,10 @@ public abstract class ClientPlayerEntityMixin {
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void tick(CallbackInfo ci) {
|
||||
SeedCracker.get().getDataStorage().tick();
|
||||
|
||||
if(MinecraftClient.getInstance().currentScreen == null && KeyBindings.OPEN_MENU.isPressed()) {
|
||||
MinecraftClient.getInstance().openScreen(new GuiScreen("Test"));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package kaptainwutax.seedcracker.mixin;
|
||||
|
||||
import kaptainwutax.seedcracker.init.KeyBindings;
|
||||
import net.minecraft.client.options.GameOptions;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@Mixin(GameOptions.class)
|
||||
public class GameOptionsMixin {
|
||||
|
||||
@Shadow public KeyBinding[] keysAll;
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void init(CallbackInfo ci) {
|
||||
KeyBinding[] oldKeys = this.keysAll;
|
||||
KeyBinding[] newKeys = new KeyBinding[oldKeys.length + KeyBindings.KEY_REGISTRY.size()];
|
||||
Iterator<KeyBinding> keyBindingIterator = KeyBindings.KEY_REGISTRY.iterator();
|
||||
|
||||
for(int i = 0; i < newKeys.length; i++) {
|
||||
if(i < oldKeys.length) {
|
||||
newKeys[i] = oldKeys[i];
|
||||
} else {
|
||||
newKeys[i] = keyBindingIterator.next();
|
||||
}
|
||||
}
|
||||
|
||||
this.keysAll = newKeys;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package kaptainwutax.seedcracker.mixin;
|
||||
|
||||
import kaptainwutax.seedcracker.init.KeyBindings;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(KeyBinding.class)
|
||||
public class KeyBindingMixin {
|
||||
|
||||
@Shadow @Final private static Map<String, Integer> categoryOrderMap;
|
||||
|
||||
static {
|
||||
int start = categoryOrderMap.size();
|
||||
|
||||
for(String category: KeyBindings.CATEGORY_REGISTRY) {
|
||||
categoryOrderMap.put(category, start++);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user