2021-06-19 07:52:33 +02:00
|
|
|
package com.jozufozu.flywheel.config;
|
|
|
|
|
2021-06-30 21:43:54 +02:00
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2021-06-19 07:52:33 +02:00
|
|
|
import com.jozufozu.flywheel.backend.Backend;
|
|
|
|
import com.jozufozu.flywheel.backend.OptifineHandler;
|
|
|
|
|
2021-11-18 23:59:39 +01:00
|
|
|
import net.minecraft.ChatFormatting;
|
2021-06-19 07:52:33 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.client.player.LocalPlayer;
|
2021-11-24 01:21:37 +01:00
|
|
|
import net.minecraft.network.FriendlyByteBuf;
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.network.chat.Component;
|
2021-11-18 23:59:39 +01:00
|
|
|
import net.minecraft.network.chat.MutableComponent;
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.network.chat.TextComponent;
|
2021-06-19 07:52:33 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
|
|
|
|
|
|
public enum BooleanConfig {
|
|
|
|
ENGINE(() -> BooleanConfig::enabled),
|
|
|
|
NORMAL_OVERLAY(() -> BooleanConfig::normalOverlay),
|
|
|
|
;
|
|
|
|
|
|
|
|
final Supplier<Consumer<BooleanDirective>> receiver;
|
|
|
|
|
|
|
|
BooleanConfig(Supplier<Consumer<BooleanDirective>> receiver) {
|
|
|
|
this.receiver = receiver;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SConfigureBooleanPacket packet(BooleanDirective directive) {
|
|
|
|
return new SConfigureBooleanPacket(this, directive);
|
|
|
|
}
|
|
|
|
|
2021-11-01 01:24:57 +01:00
|
|
|
/**
|
|
|
|
* Encode a variant of BooleanConfig. Symmetrical function to {@link #decode}
|
|
|
|
*/
|
2021-11-24 01:21:37 +01:00
|
|
|
public void encode(FriendlyByteBuf buffer) {
|
2021-11-01 01:24:57 +01:00
|
|
|
buffer.writeByte(this.ordinal());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Safely decode a variant of BooleanConfig. Symmetrical function to {@link #encode}
|
|
|
|
*/
|
2021-11-24 01:21:37 +01:00
|
|
|
public static BooleanConfig decode(FriendlyByteBuf buffer) {
|
2021-11-01 01:24:57 +01:00
|
|
|
byte t = buffer.readByte();
|
|
|
|
BooleanConfig[] values = values();
|
|
|
|
// Protects against version differences.
|
|
|
|
// Shouldn't ever happen but do a sanity check for safety.
|
|
|
|
if (t >= 0 && t < values.length)
|
|
|
|
return values[t];
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-19 07:52:33 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
private static void enabled(BooleanDirective state) {
|
2021-09-15 08:45:29 +02:00
|
|
|
LocalPlayer player = Minecraft.getInstance().player;
|
2021-06-19 07:52:33 +02:00
|
|
|
if (player == null || state == null) return;
|
|
|
|
|
|
|
|
if (state == BooleanDirective.DISPLAY) {
|
2021-11-09 05:48:02 +01:00
|
|
|
Component text = new TextComponent("Flywheel renderer is currently: ").append(boolToText(FlwConfig.get().enabled()));
|
2021-07-15 20:36:24 +02:00
|
|
|
player.displayClientMessage(text, false);
|
2021-06-19 07:52:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean enabled = state.get();
|
2021-07-26 22:42:38 +02:00
|
|
|
boolean cannotUse = OptifineHandler.usingShaders() && enabled;
|
2021-06-19 07:52:33 +02:00
|
|
|
|
|
|
|
FlwConfig.get().client.enabled.set(enabled);
|
|
|
|
|
2021-11-09 05:48:02 +01:00
|
|
|
Component text = boolToText(FlwConfig.get().enabled()).append(new TextComponent(" Flywheel renderer").withStyle(ChatFormatting.WHITE));
|
2021-09-15 08:45:29 +02:00
|
|
|
Component error = new TextComponent("Flywheel renderer does not support Optifine Shaders").withStyle(ChatFormatting.RED);
|
2021-06-19 07:52:33 +02:00
|
|
|
|
2021-07-26 22:42:38 +02:00
|
|
|
player.displayClientMessage(cannotUse ? error : text, false);
|
2021-06-19 07:52:33 +02:00
|
|
|
Backend.reloadWorldRenderers();
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
private static void normalOverlay(BooleanDirective state) {
|
2021-09-15 08:45:29 +02:00
|
|
|
LocalPlayer player = Minecraft.getInstance().player;
|
2021-06-19 07:52:33 +02:00
|
|
|
if (player == null || state == null) return;
|
|
|
|
|
|
|
|
if (state == BooleanDirective.DISPLAY) {
|
2021-11-09 05:48:02 +01:00
|
|
|
Component text = new TextComponent("Normal debug mode is currently: ").append(boolToText(FlwConfig.get().debugNormals()));
|
2021-07-15 20:36:24 +02:00
|
|
|
player.displayClientMessage(text, false);
|
2021-06-19 07:52:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-26 22:42:38 +02:00
|
|
|
FlwConfig.get().client.debugNormals.set(state.get());
|
2021-06-19 07:52:33 +02:00
|
|
|
|
2021-11-09 05:48:02 +01:00
|
|
|
Component text = boolToText(FlwConfig.get().debugNormals()).append(new TextComponent(" normal debug mode").withStyle(ChatFormatting.WHITE));
|
2021-06-19 07:52:33 +02:00
|
|
|
|
2021-07-15 20:36:24 +02:00
|
|
|
player.displayClientMessage(text, false);
|
2021-06-19 07:52:33 +02:00
|
|
|
}
|
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
private static MutableComponent boolToText(boolean b) {
|
|
|
|
return b ? new TextComponent("enabled").withStyle(ChatFormatting.DARK_GREEN) : new TextComponent("disabled").withStyle(ChatFormatting.RED);
|
2021-06-19 07:52:33 +02:00
|
|
|
}
|
|
|
|
}
|