From 53a5ef63576ef9e288f819a9f0e19bf3d0a027f7 Mon Sep 17 00:00:00 2001 From: Zelophed Date: Thu, 30 Jan 2020 19:11:23 +0100 Subject: [PATCH] added a clientside config option to toggle the rainbow debugger also added to a command to control the config option --- .../java/com/simibubi/create/AllPackets.java | 2 + .../simibubi/create/CreateClientConfig.java | 6 +++ .../command/ConfigureConfigPacket.java | 43 +++++++++++++++++++ .../foundation/command/CreateCommand.java | 6 +++ .../command/ToggleDebugCommand.java | 37 ++++++++++++++++ .../modules/contraptions/KineticDebugger.java | 4 +- 6 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java create mode 100644 src/main/java/com/simibubi/create/foundation/command/ToggleDebugCommand.java diff --git a/src/main/java/com/simibubi/create/AllPackets.java b/src/main/java/com/simibubi/create/AllPackets.java index 56412ba42..59cb0ec91 100644 --- a/src/main/java/com/simibubi/create/AllPackets.java +++ b/src/main/java/com/simibubi/create/AllPackets.java @@ -5,6 +5,7 @@ import java.util.function.Function; import java.util.function.Supplier; import com.simibubi.create.foundation.behaviour.filtering.FilteringCountUpdatePacket; +import com.simibubi.create.foundation.command.ConfigureConfigPacket; import com.simibubi.create.foundation.packet.NbtPacket; import com.simibubi.create.foundation.packet.SimplePacketBase; import com.simibubi.create.modules.contraptions.components.contraptions.chassis.ConfigureChassisPacket; @@ -45,6 +46,7 @@ public enum AllPackets { // Server to Client SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new), BEAM_EFFECT(BlockzapperBeamPacket.class, BlockzapperBeamPacket::new), + CONFIGURE_CONFIG(ConfigureConfigPacket.class, ConfigureConfigPacket::new), ; diff --git a/src/main/java/com/simibubi/create/CreateClientConfig.java b/src/main/java/com/simibubi/create/CreateClientConfig.java index d8575d48f..fdf01dad5 100644 --- a/src/main/java/com/simibubi/create/CreateClientConfig.java +++ b/src/main/java/com/simibubi/create/CreateClientConfig.java @@ -21,6 +21,7 @@ public class CreateClientConfig { public BooleanValue enableTooltips; public DoubleValue fanParticleDensity; + public BooleanValue enableRainbowDebug; CreateClientConfig(final ForgeConfigSpec.Builder builder) { builder.comment( @@ -36,6 +37,11 @@ public class CreateClientConfig { fanParticleDensity = builder.comment("", "Controls the average amount of fan particles spawned per tick.") .translation(basePath + name).defineInRange(name, .5D, 0D, 1D); + name = "enableRainbowDebug"; + enableRainbowDebug = builder.comment("", "Show colorful debug information while the F3-Menu is open.") + .translation(basePath + name).define(name, true); + + builder.pop(); } diff --git a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java new file mode 100644 index 000000000..b7cbb38d4 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java @@ -0,0 +1,43 @@ +package com.simibubi.create.foundation.command; + +import com.simibubi.create.CreateClientConfig; +import com.simibubi.create.foundation.packet.SimplePacketBase; +import net.minecraft.network.PacketBuffer; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.network.NetworkEvent; + +import java.util.function.Supplier; + +public class ConfigureConfigPacket extends SimplePacketBase { + + private String option; + private String value; + + public ConfigureConfigPacket(String option, String value) { + this.option = option; + this.value = value; + } + + public ConfigureConfigPacket(PacketBuffer buffer) { + this.option = buffer.readString(); + this.value = buffer.readString(); + } + + @Override + public void write(PacketBuffer buffer) { + buffer.writeString(option); + buffer.writeString(value); + } + + @Override + public void handle(Supplier ctx) { + ctx.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { + if (option.equals("rainbowDebug")){ + CreateClientConfig.instance.enableRainbowDebug.set(Boolean.parseBoolean(value)); + } + })); + + ctx.get().setPacketHandled(true); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/command/CreateCommand.java b/src/main/java/com/simibubi/create/foundation/command/CreateCommand.java index 38e08ee73..e5d365969 100644 --- a/src/main/java/com/simibubi/create/foundation/command/CreateCommand.java +++ b/src/main/java/com/simibubi/create/foundation/command/CreateCommand.java @@ -2,12 +2,18 @@ package com.simibubi.create.foundation.command; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; public class CreateCommand { public CreateCommand(CommandDispatcher dispatcher){ KillTPSCommand.register(dispatcher); + + dispatcher.register(Commands.literal("create") + .then(ToggleDebugCommand.register()) + ); } } diff --git a/src/main/java/com/simibubi/create/foundation/command/ToggleDebugCommand.java b/src/main/java/com/simibubi/create/foundation/command/ToggleDebugCommand.java new file mode 100644 index 000000000..9c9b104af --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/command/ToggleDebugCommand.java @@ -0,0 +1,37 @@ +package com.simibubi.create.foundation.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.simibubi.create.AllPackets; +import com.simibubi.create.CreateClientConfig; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.network.PacketDistributor; + +public class ToggleDebugCommand { + + static ArgumentBuilder register() { + return Commands.literal("toggleDebug") + .requires(cs -> cs.hasPermissionLevel(0)) + .then(Commands.argument("value", BoolArgumentType.bool()) + .executes(ctx -> { + boolean value = BoolArgumentType.getBool(ctx, "value"); + System.out.println("Command toggleDebug " + value); + + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> CreateClientConfig.instance.enableRainbowDebug.set(value)); + + DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> + AllPackets.channel.send( + PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) ctx.getSource().getEntity()), + new ConfigureConfigPacket("rainbowDebug", String.valueOf(value)))); + + ctx.getSource().sendFeedback(new StringTextComponent((value ? "enabled" : "disabled") + " rainbow debug"), true); + + return 1; + })); + } +} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/KineticDebugger.java b/src/main/java/com/simibubi/create/modules/contraptions/KineticDebugger.java index 9d2e10935..432a7d471 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/KineticDebugger.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/KineticDebugger.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.List; import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.Create; +import com.simibubi.create.CreateClientConfig; import com.simibubi.create.foundation.utility.TessellatorHelper; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; @@ -61,7 +63,7 @@ public class KineticDebugger { } public static boolean isActive() { - return Minecraft.getInstance().gameSettings.showDebugInfo; + return Minecraft.getInstance().gameSettings.showDebugInfo && CreateClientConfig.instance.enableRainbowDebug.get(); } public static KineticTileEntity getSelectedTE() {