added a clientside config option to toggle the rainbow debugger

also added to a command to control the config option
This commit is contained in:
Zelophed 2020-01-30 19:11:23 +01:00
parent dbfc429391
commit 53a5ef6357
6 changed files with 97 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.simibubi.create.foundation.behaviour.filtering.FilteringCountUpdatePacket; 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.NbtPacket;
import com.simibubi.create.foundation.packet.SimplePacketBase; import com.simibubi.create.foundation.packet.SimplePacketBase;
import com.simibubi.create.modules.contraptions.components.contraptions.chassis.ConfigureChassisPacket; import com.simibubi.create.modules.contraptions.components.contraptions.chassis.ConfigureChassisPacket;
@ -45,6 +46,7 @@ public enum AllPackets {
// Server to Client // Server to Client
SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new), SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new),
BEAM_EFFECT(BlockzapperBeamPacket.class, BlockzapperBeamPacket::new), BEAM_EFFECT(BlockzapperBeamPacket.class, BlockzapperBeamPacket::new),
CONFIGURE_CONFIG(ConfigureConfigPacket.class, ConfigureConfigPacket::new),
; ;

View file

@ -21,6 +21,7 @@ public class CreateClientConfig {
public BooleanValue enableTooltips; public BooleanValue enableTooltips;
public DoubleValue fanParticleDensity; public DoubleValue fanParticleDensity;
public BooleanValue enableRainbowDebug;
CreateClientConfig(final ForgeConfigSpec.Builder builder) { CreateClientConfig(final ForgeConfigSpec.Builder builder) {
builder.comment( builder.comment(
@ -36,6 +37,11 @@ public class CreateClientConfig {
fanParticleDensity = builder.comment("", "Controls the average amount of fan particles spawned per tick.") fanParticleDensity = builder.comment("", "Controls the average amount of fan particles spawned per tick.")
.translation(basePath + name).defineInRange(name, .5D, 0D, 1D); .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(); builder.pop();
} }

View file

@ -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<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
if (option.equals("rainbowDebug")){
CreateClientConfig.instance.enableRainbowDebug.set(Boolean.parseBoolean(value));
}
}));
ctx.get().setPacketHandled(true);
}
}

View file

@ -2,12 +2,18 @@ package com.simibubi.create.foundation.command;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
public class CreateCommand { public class CreateCommand {
public CreateCommand(CommandDispatcher<CommandSource> dispatcher){ public CreateCommand(CommandDispatcher<CommandSource> dispatcher){
KillTPSCommand.register(dispatcher); KillTPSCommand.register(dispatcher);
dispatcher.register(Commands.literal("create")
.then(ToggleDebugCommand.register())
);
} }
} }

View file

@ -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<CommandSource, ?> 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;
}));
}
}

View file

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.mojang.blaze3d.platform.GlStateManager; 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.foundation.utility.TessellatorHelper;
import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
@ -61,7 +63,7 @@ public class KineticDebugger {
} }
public static boolean isActive() { public static boolean isActive() {
return Minecraft.getInstance().gameSettings.showDebugInfo; return Minecraft.getInstance().gameSettings.showDebugInfo && CreateClientConfig.instance.enableRainbowDebug.get();
} }
public static KineticTileEntity getSelectedTE() { public static KineticTileEntity getSelectedTE() {