mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-09 22:06:09 +01:00
b762b1a7d3
# Conflicts: # changelog.txt # gradle.properties # src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java # src/main/java/com/jozufozu/flywheel/config/BooleanConfig.java # src/main/java/com/jozufozu/flywheel/config/SConfigureBooleanPacket.java # src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java # src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java # src/main/java/com/jozufozu/flywheel/util/WorldAttached.java # src/main/resources/flywheel.mixins.json
99 lines
3.3 KiB
Java
99 lines
3.3 KiB
Java
package com.jozufozu.flywheel.config;
|
|
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Supplier;
|
|
|
|
import com.jozufozu.flywheel.backend.Backend;
|
|
import com.jozufozu.flywheel.backend.OptifineHandler;
|
|
|
|
import net.minecraft.ChatFormatting;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.player.LocalPlayer;
|
|
import net.minecraft.network.FriendlyByteBuf;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.chat.MutableComponent;
|
|
import net.minecraft.network.chat.TextComponent;
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* Encode a variant of BooleanConfig. Symmetrical function to {@link #decode}
|
|
*/
|
|
public void encode(FriendlyByteBuf buffer) {
|
|
buffer.writeByte(this.ordinal());
|
|
}
|
|
|
|
/**
|
|
* Safely decode a variant of BooleanConfig. Symmetrical function to {@link #encode}
|
|
*/
|
|
public static BooleanConfig decode(FriendlyByteBuf buffer) {
|
|
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;
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
private static void enabled(BooleanDirective state) {
|
|
LocalPlayer player = Minecraft.getInstance().player;
|
|
if (player == null || state == null) return;
|
|
|
|
if (state == BooleanDirective.DISPLAY) {
|
|
Component text = new TextComponent("Flywheel renderer is currently: ").append(boolToText(FlwConfig.get().enabled()));
|
|
player.displayClientMessage(text, false);
|
|
return;
|
|
}
|
|
|
|
boolean enabled = state.get();
|
|
boolean cannotUse = OptifineHandler.usingShaders() && enabled;
|
|
|
|
FlwConfig.get().client.enabled.set(enabled);
|
|
|
|
Component text = boolToText(FlwConfig.get().enabled()).append(new TextComponent(" Flywheel renderer").withStyle(ChatFormatting.WHITE));
|
|
Component error = new TextComponent("Flywheel renderer does not support Optifine Shaders").withStyle(ChatFormatting.RED);
|
|
|
|
player.displayClientMessage(cannotUse ? error : text, false);
|
|
Backend.reloadWorldRenderers();
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
private static void normalOverlay(BooleanDirective state) {
|
|
LocalPlayer player = Minecraft.getInstance().player;
|
|
if (player == null || state == null) return;
|
|
|
|
if (state == BooleanDirective.DISPLAY) {
|
|
Component text = new TextComponent("Normal debug mode is currently: ").append(boolToText(FlwConfig.get().debugNormals()));
|
|
player.displayClientMessage(text, false);
|
|
return;
|
|
}
|
|
|
|
FlwConfig.get().client.debugNormals.set(state.get());
|
|
|
|
Component text = boolToText(FlwConfig.get().debugNormals()).append(new TextComponent(" normal debug mode").withStyle(ChatFormatting.WHITE));
|
|
|
|
player.displayClientMessage(text, false);
|
|
}
|
|
|
|
private static MutableComponent boolToText(boolean b) {
|
|
return b ? new TextComponent("enabled").withStyle(ChatFormatting.DARK_GREEN) : new TextComponent("disabled").withStyle(ChatFormatting.RED);
|
|
}
|
|
}
|