utils
This commit is contained in:
parent
ecb2cdcd85
commit
e5ec40b8c2
|
@ -1,41 +1,21 @@
|
|||
package de.cscherr.mcpht;
|
||||
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
||||
import de.cscherr.mcpht.util.Hack;
|
||||
import de.cscherr.mcpht.util.MaybeKey;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Fly {
|
||||
|
||||
public boolean enable = true;
|
||||
private static KeyBinding toggleKey;
|
||||
|
||||
public void init() {
|
||||
toggleKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"key.mcpht.toggleXray", // Translation of name
|
||||
InputUtil.Type.KEYSYM, // Type: MOUSE or KESYM (Keyboard)
|
||||
GLFW.GLFW_KEY_Y, // The keycode of the key (default?)
|
||||
"category.mcpht.rendering" // Translation key for the keybinding category
|
||||
));
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
// NOTE: IDK why we need a while here
|
||||
while (toggleKey.wasPressed()) {
|
||||
if (MCPHTClient.XRAY.getEnable()) {
|
||||
MCPHTClient.LOGGER.info(String.format("toggle XRay: %s", MCPHTClient.XRAY.enable));
|
||||
MCPHTClient.XRAY.enable = !MCPHTClient.XRAY.enable;
|
||||
MCPHTClient.MC.worldRenderer.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
public class Fly extends Hack {
|
||||
public Fly() {
|
||||
super(new MaybeKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyPress() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnable() {
|
||||
return enable && MCPHTClient.CONFIG.fly.enable;
|
||||
}
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
package de.cscherr.mcpht;
|
||||
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import de.cscherr.mcpht.util.Hack;
|
||||
import de.cscherr.mcpht.util.MaybeKey;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class XRay {
|
||||
public boolean enable = true;
|
||||
public class XRay extends Hack {
|
||||
public ArrayList<Block> whitelistBlocks = new ArrayList<>(
|
||||
List.of(
|
||||
// Ores
|
||||
|
@ -80,31 +78,24 @@ public class XRay {
|
|||
Blocks.RED_SHULKER_BOX
|
||||
)
|
||||
);
|
||||
private static KeyBinding toggleKey;
|
||||
|
||||
public void init() {
|
||||
toggleKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"key.mcpht.toggleXray", // Translation of name
|
||||
InputUtil.Type.KEYSYM, // Type: MOUSE or KESYM (Keyboard)
|
||||
GLFW.GLFW_KEY_X, // The keycode of the key (default?)
|
||||
"category.mcpht.rendering" // Translation key for the keybinding category
|
||||
));
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
// NOTE: IDK why we need a while here
|
||||
while (toggleKey.wasPressed()) {
|
||||
if (MCPHTClient.XRAY.getEnable()) {
|
||||
MCPHTClient.LOGGER.info(String.format("toggle XRay: %s", MCPHTClient.XRAY.enable));
|
||||
public XRay() {
|
||||
super(new MaybeKey("key.mcpht.toggleXray",
|
||||
"category.mcpht.rendering",
|
||||
GLFW.GLFW_KEY_X));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyPress() {
|
||||
MCPHTClient.XRAY.enable = !MCPHTClient.XRAY.enable;
|
||||
MCPHTClient.MC.worldRenderer.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean showRenderBlock(BlockState state) {
|
||||
return whitelistBlocks.contains(state.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnable() {
|
||||
return enable && MCPHTClient.CONFIG.xRay.enable;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package de.cscherr.mcpht.util;
|
||||
|
||||
import de.cscherr.mcpht.MCPHTClient;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class Hack {
|
||||
public boolean enable = false;
|
||||
public MaybeKey toggleKey;
|
||||
|
||||
public Hack(MaybeKey toggleKey) {
|
||||
toggleKey = toggleKey;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
if (toggleKey.hasKey) {
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
// NOTE: IDK why we need a while here
|
||||
while (toggleKey.key.wasPressed()) {
|
||||
if (this.getEnable()) {
|
||||
MCPHTClient.LOGGER.info(String.format("toggle %s: %s",
|
||||
this.getClass().getSimpleName(),
|
||||
this.getEnable()));
|
||||
onKeyPress();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void onKeyPress();
|
||||
|
||||
public abstract boolean getEnable();
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package de.cscherr.mcpht.util;
|
||||
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
|
||||
public class MaybeKey {
|
||||
public KeyBinding key;
|
||||
public String translationKey;
|
||||
public String translationCategory;
|
||||
public int keyCode;
|
||||
public boolean hasKey;
|
||||
|
||||
public MaybeKey() {
|
||||
hasKey = false;
|
||||
}
|
||||
|
||||
public MaybeKey(String translationKey, String translationCategory, int keyCode) {
|
||||
key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
translationKey, // Translation of name
|
||||
InputUtil.Type.KEYSYM, // Type: MOUSE or KESYM (Keyboard)
|
||||
keyCode, // The keycode of the key (default?)
|
||||
translationCategory // Translation key for the keybinding category
|
||||
));
|
||||
hasKey = true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package de.cscherr.mcpht.util.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class Event<T extends Listener> {
|
||||
public abstract void fire(ArrayList<T> listeners);
|
||||
|
||||
public abstract Class<T> getListenerType();
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package de.cscherr.mcpht.util.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface Listener extends EventListener {
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package de.cscherr.mcpht.util.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface UpdateListener extends Listener {
|
||||
public void onUpdate();
|
||||
public static class UpdateEvent extends Event<UpdateListener>
|
||||
{
|
||||
public static final UpdateEvent INSTANCE = new UpdateEvent();
|
||||
|
||||
@Override
|
||||
public void fire(ArrayList<UpdateListener> listeners)
|
||||
{
|
||||
for(UpdateListener listener : listeners)
|
||||
listener.onUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<UpdateListener> getListenerType()
|
||||
{
|
||||
return UpdateListener.class;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue