import com.irtimaled.bbor.client.events.*;
import com.irtimaled.bbor.client.gui.SettingsScreen;
+import com.irtimaled.bbor.client.keyboard.Key;
import com.irtimaled.bbor.client.keyboard.KeyListener;
import com.irtimaled.bbor.common.BoundingBoxCache;
import com.irtimaled.bbor.common.CommonProxy;
import com.irtimaled.bbor.common.EventBus;
import com.irtimaled.bbor.common.VillageColorCache;
import com.irtimaled.bbor.config.ConfigManager;
-import com.irtimaled.bbor.config.Setting;
public class ClientProxy extends CommonProxy {
- public static final String Name = "Bounding Box Outline Reloaded";
- public static boolean active;
-
static {
- KeyListener.register("Toggle Active", 0x42, Name)
- .onKeyPressHandler(ClientProxy::toggleActive)
- .onLongKeyPressHandler(60, SettingsScreen::show);
- KeyListener.register("Toggle Outer Box Only", 0x4f, Name)
- .onKeyPressHandler(ClientProxy::toggleOuterBoxesOnly);
+ Key mainKey = KeyListener.register("Toggle Active", "key.keyboard.b")
+ .onKeyPressHandler(ClientRenderer::toggleActive);
+ mainKey.register("key.keyboard.g")
+ .onKeyPressHandler(SettingsScreen::show);
+ mainKey.register("key.keyboard.o")
+ .onKeyPressHandler(() -> ConfigManager.Toggle(ConfigManager.outerBoxesOnly));
}
private boolean ready;
- public static void toggleActive() {
- active = !active;
- if (!active) return;
-
- PlayerCoords.setActiveY();
- }
-
- private static void toggleOuterBoxesOnly() {
- if(!active) return;
-
- Setting<Boolean> outerBoxesOnly = ConfigManager.outerBoxesOnly;
- outerBoxesOnly.set(!outerBoxesOnly.get());
- }
-
private ClientRenderer renderer;
@Override
}
private void render(Render event) {
- if (!active || !ready) return;
+ if (!ready) return;
- renderer.render(event.getDimensionId(), ConfigManager.outerBoxesOnly.get());
+ renderer.render(event.getDimensionId());
}
private void disconnectedFromServer() {
- active = false;
+ ClientRenderer.deactivate();
if (ConfigManager.keepCacheBetweenSessions.get()) return;
ready = false;
VillageColorCache.clear();
private static final int CHUNK_SIZE = 16;
private static final Map<Class<? extends AbstractBoundingBox>, AbstractRenderer> boundingBoxRendererMap = new HashMap<>();
+ private static boolean active;
+
+ public static boolean getActive() {
+ return active;
+ }
+
+ public static void toggleActive() {
+ active = !active;
+ if (!active) return;
+
+ PlayerCoords.setActiveY();
+ }
+
+ static void deactivate() {
+ active = false;
+ }
+
private final GetCache getCache;
private long seed;
private Set<AbstractBoundingBox> spawnChunkBoundingBoxes = new HashSet<>();
return boundingBox.intersectsBounds(minX, minZ, maxX, maxZ);
}
- public void render(int dimensionId, Boolean outerBoxesOnly) {
+ public void render(int dimensionId) {
+ if(!active) return;
+
Map<AbstractBoundingBox, Set<AbstractBoundingBox>> boundingBoxes = getBoundingBoxes(dimensionId);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
if (ConfigManager.alwaysVisible.get()) {
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
}
+
+ Boolean outerBoxesOnly = ConfigManager.outerBoxesOnly.get();
for (Map.Entry<AbstractBoundingBox, Set<AbstractBoundingBox>> entry : boundingBoxes.entrySet()) {
AbstractBoundingBox key = entry.getKey();
if (!key.shouldRender()) continue;
package com.irtimaled.bbor.client.gui;
+import com.irtimaled.bbor.config.ConfigManager;
import com.irtimaled.bbor.config.Setting;
public class BoolSettingButton extends AbstractButton {
@Override
public void onPressed() {
- setting.set(!setting.get());
+ ConfigManager.Toggle(setting);
}
}
package com.irtimaled.bbor.client.gui;
import com.irtimaled.bbor.client.ClientProxy;
+import com.irtimaled.bbor.client.ClientRenderer;
import com.irtimaled.bbor.client.renderers.Renderer;
import com.irtimaled.bbor.common.BoundingBoxType;
import com.irtimaled.bbor.common.TypeHelper;
@Override
protected void initGui() {
- this.title = ClientProxy.Name;
+ this.title = "Bounding Box Outline Reloaded";
this.controls = new HashSet<>();
this.addTabs("General", "Structures", "Villages");
(id, x, y, width) -> new AbstractButton(id, x, y, width, "Active", this.mc.world != null) {
@Override
public void onPressed() {
- ClientProxy.toggleActive();
+ ClientRenderer.toggleActive();
}
@Override
protected int getState() {
- return enabled ? ClientProxy.active ? 2 : 1 : 0;
+ return enabled ? ClientRenderer.getActive() ? 2 : 1 : 0;
}
},
(id, x, y, width) -> new BoolSettingButton(id, x, y, width, "Outer Box Only", ConfigManager.outerBoxesOnly),
--- /dev/null
+package com.irtimaled.bbor.client.keyboard;
+
+import net.minecraft.client.settings.KeyBinding;
+import net.minecraft.client.util.InputMappings;
+
+class CustomKeyBinding extends KeyBinding {
+ private final Key key;
+
+ CustomKeyBinding(String description, int keyCode) {
+ super(description, keyCode, KeyListener.Category);
+ this.key = new Key(keyCode);
+ }
+
+ @Override
+ public void bind(InputMappings.Input input) {
+ super.bind(input);
+ int keyCode = input.getKeyCode();
+ key.updateKeyCode(keyCode);
+ }
+
+ public Key getKey() {
+ return key;
+ }
+}
\ No newline at end of file
package com.irtimaled.bbor.client.keyboard;
-import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.util.InputMappings;
-public class Key extends KeyBinding {
- private InputMappings.Input input;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Key {
+ private int keyCode;
private KeyHandler onKeyPress;
- private KeyHandler onLongKeyPress;
- private int longPressDuration;
+ private Set<Key> subKeys = new HashSet<>();
+ private boolean triggeredSincePress;
- Key(String description, int keyCode, String category) {
- super(description, keyCode, category);
+ Key(int keyCode) {
+ this.keyCode = keyCode;
}
public Key onKeyPressHandler(KeyHandler onKeyPress) {
return this;
}
- public Key onLongKeyPressHandler(int duration, KeyHandler onLongKeyPress) {
- this.longPressDuration = duration;
- this.onLongKeyPress = onLongKeyPress;
- return this;
- }
-
- InputMappings.Input getInput() {
- if (input == null)
- return getDefault();
- return input;
- }
-
- @Override
- public void bind(InputMappings.Input input) {
- this.input = input;
- super.bind(input);
+ void updateKeyCode(int keyCode) {
+ this.keyCode = keyCode;
}
private int pressDuration = 0;
- @Override
- public boolean isPressed() {
- return pressDuration == 1;
+ private void runHandler(KeyHandler onKeyPress) {
+ triggeredSincePress = true;
+ onKeyPress.handle();
}
- void release() {
- if (onKeyPress != null && (onLongKeyPress == null || pressDuration < longPressDuration)) {
- onKeyPress.handle();
+ private void press() {
+ for (Key subKey : subKeys) {
+ subKey.triggeredSincePress = false;
}
-
- pressDuration = 0;
+ triggeredSincePress = false;
+ pressDuration++;
}
- void repeat() {
- if (onLongKeyPress == null) return;
-
- if (pressDuration <= longPressDuration) {
- pressDuration++;
+ private void release() {
+ try {
+ for (Key subKey : subKeys) {
+ if (subKey.pressDuration > 0) {
+ subKey.release();
+ return;
+ }
+ if (subKey.triggeredSincePress) {
+ return;
+ }
+ }
+ if (onKeyPress != null && pressDuration > 0) {
+ runHandler(onKeyPress);
+ }
+ } finally {
+ pressDuration = 0;
}
+ }
- if (pressDuration == longPressDuration) {
- onLongKeyPress.handle();
+ boolean handleKeyEvent(int keyCode, boolean isPressed) {
+ if (this.keyCode == keyCode) {
+ if (isPressed) {
+ press();
+ } else {
+ release();
+ }
+ return true;
+ } else if (this.pressDuration > 0) {
+ for (Key subKey : subKeys) {
+ if (subKey.handleKeyEvent(keyCode, isPressed)) {
+ return true;
+ }
+ }
}
+
+ return false;
}
- void press() {
- pressDuration++;
+ public Key register(String keyName) {
+ InputMappings.Input input = InputMappings.getInputByName(keyName);
+ Key key = new Key(input.getKeyCode());
+ subKeys.add(key);
+ return key;
}
}
private static final Minecraft minecraft = Minecraft.getInstance();
private static long mainWindowHandle;
private static Set<Key> keys = new HashSet<>();
+ private static Set<CustomKeyBinding> keyBindings = new HashSet<>();
+ public static final String Category = "Bounding Box Outline Reloaded";
public static void init() {
mainWindowHandle = minecraft.mainWindow.getHandle();
GLFW.glfwSetKeyCallback(mainWindowHandle, KeyListener::onKeyEvent);
}
- public static Key register(String description, int keyCode, String category) {
- Key key = new Key(description, keyCode, category);
+ public static Key register(String description, String keyName) {
+ InputMappings.Input input = InputMappings.getInputByName(keyName);
+ CustomKeyBinding keyBinding = new CustomKeyBinding(description, input.getKeyCode());
+ keyBindings.add(keyBinding);
+
+ Key key = keyBinding.getKey();
keys.add(key);
return key;
}
private static void onKeyEvent(long windowHandle, int keyCode, int scanCode, int action, int modifiers) {
- if (windowHandle == mainWindowHandle && minecraft.currentScreen == null && keyCode != -1 && !InputMappings.isKeyDown(292)) {
- InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode);
- for (Key key : keys) {
- if (key.getInput() == input) {
- switch (action) {
- case GLFW.GLFW_PRESS:
- key.press();
- break;
- case GLFW.GLFW_REPEAT:
- key.repeat();
- break;
- case GLFW.GLFW_RELEASE:
- key.release();
- return;
- }
- if (minecraft.currentScreen != null)
- key.release();
- return;
- }
+ boolean isPressed = action > 0;
+ if (windowHandle == mainWindowHandle &&
+ minecraft.currentScreen == null &&
+ keyCode != -1 &&
+ !InputMappings.isKeyDown(292) &&
+ handleKeyEvent(keyCode, isPressed))
+ return;
+ minecraft.keyboardListener.onKeyEvent(windowHandle, keyCode, scanCode, action, modifiers);
+ }
+
+ private static boolean handleKeyEvent(int keyCode, boolean isPressed) {
+ for (Key key : keys) {
+ if (key.handleKeyEvent(keyCode, isPressed)) {
+ return true;
}
}
- minecraft.keyboardListener.onKeyEvent(windowHandle, keyCode, scanCode, action, modifiers);
+ return false;
}
public static KeyBinding[] keyBindings() {
- return keys.stream().toArray(KeyBinding[]::new);
+ return keyBindings.toArray(new KeyBinding[0]);
}
}
settings.add(setting);
return setting;
}
+
+ public static void Toggle(Setting<Boolean> setting) {
+ setting.set(!setting.get());
+ }
}
public class Setting<T> extends AbstractSetting {
private T value;
- public Setting(char type, T value) {
+ Setting(char type, T value) {
super(type);
this.value = value;
}
package com.irtimaled.bbor.mixin.client.settings;
-import com.irtimaled.bbor.client.ClientProxy;
+import com.irtimaled.bbor.client.keyboard.KeyListener;
import net.minecraft.client.settings.KeyBinding;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
private static Map<String, Integer> CATEGORY_ORDER;
static {
- CATEGORY_ORDER.put(ClientProxy.Name, 0);
+ CATEGORY_ORDER.put(KeyListener.Category, 0);
}
}