aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2023-03-18 12:00:33 +0100
committermakamys <makamys@outlook.com>2023-03-18 12:57:41 +0100
commit979d794c61a68357d890aeb36966d1db0374e538 (patch)
tree2421e74b9d68f53811d4966a83be4efed3edc956
parent36fa2950ba78a10194ac7125167f499d8b3f107d (diff)
downloadNeodymium-979d794c61a68357d890aeb36966d1db0374e538.tar.gz
Neodymium-979d794c61a68357d890aeb36966d1db0374e538.tar.bz2
Neodymium-979d794c61a68357d890aeb36966d1db0374e538.zip
Lock certain debug features behind creative mode
-rw-r--r--src/main/java/makamys/neodymium/config/Config.java2
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java21
-rw-r--r--src/main/java/makamys/neodymium/util/CheatHelper.java32
3 files changed, 48 insertions, 7 deletions
diff --git a/src/main/java/makamys/neodymium/config/Config.java b/src/main/java/makamys/neodymium/config/Config.java
index 4935851..8ae3f79 100644
--- a/src/main/java/makamys/neodymium/config/Config.java
+++ b/src/main/java/makamys/neodymium/config/Config.java
@@ -110,6 +110,8 @@ public class Config {
info.needReload = needReload;
}
+ config.setCategoryComment("debug", "Note: Some debug features are only available in creative mode or dev environments.");
+
if(config.hasChanged() || (!config.getLoadedConfigVersion().equals(config.getDefinedConfigVersion()))) {
config.save();
}
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index 7c11c1a..d75aa43 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -30,6 +30,7 @@ import makamys.neodymium.Neodymium;
import makamys.neodymium.config.Config;
import makamys.neodymium.ducks.IWorldRenderer;
import makamys.neodymium.renderer.Mesh.GPUStatus;
+import makamys.neodymium.util.CheatHelper;
import makamys.neodymium.util.GuiHelper;
import makamys.neodymium.util.OFUtil;
import makamys.neodymium.util.Preprocessor;
@@ -241,11 +242,13 @@ public class NeoRenderer {
private void handleKeyboard() {
if(Config.debugPrefix == 0 || (Config.debugPrefix != -1 && Keyboard.isKeyDown(Config.debugPrefix))) {
- if(Keyboard.isKeyDown(Keyboard.KEY_F) && !wasDown[Keyboard.KEY_F]) {
- rendererActive = !rendererActive;
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_V) && !wasDown[Keyboard.KEY_V]) {
- renderWorld = !renderWorld;
+ if(CheatHelper.canCheat()) {
+ if(Keyboard.isKeyDown(Keyboard.KEY_F) && !wasDown[Keyboard.KEY_F]) {
+ rendererActive = !rendererActive;
+ }
+ if(Keyboard.isKeyDown(Keyboard.KEY_V) && !wasDown[Keyboard.KEY_V]) {
+ renderWorld = !renderWorld;
+ }
}
if(Keyboard.isKeyDown(Keyboard.KEY_R) && !wasDown[Keyboard.KEY_R]) {
reloadShader();
@@ -291,11 +294,11 @@ public class NeoRenderer {
glUseProgram(shader);
updateUniforms(alpha, pass);
- if(Config.wireframe) {
+ if(isWireframeEnabled()) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
}
glMultiDrawArrays(GL_QUADS, piFirst[pass], piCount[pass]);
- if(Config.wireframe) {
+ if(isWireframeEnabled()) {
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
}
@@ -631,6 +634,10 @@ public class NeoRenderer {
return world != null;
}
+ private static boolean isWireframeEnabled() {
+ return Config.wireframe && CheatHelper.canCheat();
+ }
+
public static class NeoChunkComparator implements Comparator<NeoChunk> {
Entity player;
diff --git a/src/main/java/makamys/neodymium/util/CheatHelper.java b/src/main/java/makamys/neodymium/util/CheatHelper.java
new file mode 100644
index 0000000..e54684b
--- /dev/null
+++ b/src/main/java/makamys/neodymium/util/CheatHelper.java
@@ -0,0 +1,32 @@
+package makamys.neodymium.util;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraft.world.World;
+
+public class CheatHelper {
+
+ private static final boolean IS_DEV_ENVIRONMENT = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
+
+ public static boolean canCheat() {
+ if(IS_DEV_ENVIRONMENT) {
+ return true;
+ } else {
+ return isCreative(Minecraft.getMinecraft().thePlayer);
+ }
+ }
+
+ public static boolean isCreative(EntityPlayer player) {
+ return player != null && player.capabilities.isCreativeMode;
+ }
+
+ public static boolean isCreativeByName(String player) {
+ World world = Minecraft.getMinecraft().theWorld;
+ if(world != null) {
+ return isCreative(world.getPlayerEntityByName(player));
+ }
+ return false;
+ }
+
+}