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 ;
import net.minecraft.client.Minecraft ;
import net.minecraft.client.entity.player.ClientPlayerEntity ;
import net.minecraft.util.text.IFormattableTextComponent ;
import net.minecraft.util.text.ITextComponent ;
import net.minecraft.util.text.StringTextComponent ;
import net.minecraft.util.text.TextFormatting ;
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 ) ;
}
@OnlyIn ( Dist . CLIENT )
private static void enabled ( BooleanDirective state ) {
ClientPlayerEntity player = Minecraft . getInstance ( ) . player ;
if ( player = = null | | state = = null ) return ;
if ( state = = BooleanDirective . DISPLAY ) {
ITextComponent text = new StringTextComponent ( " Flywheel Renderer is currently: " ) . append ( boolToText ( FlwConfig . get ( ) . client . enabled . get ( ) ) ) ;
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 ( ) ;
boolean cannotUseER = OptifineHandler . usingShaders ( ) & & enabled ;
FlwConfig . get ( ) . client . enabled . set ( enabled ) ;
2021-07-15 20:36:24 +02:00
ITextComponent text = boolToText ( FlwConfig . get ( ) . client . enabled . get ( ) ) . append ( new StringTextComponent ( " Flywheel Renderer " ) . withStyle ( TextFormatting . WHITE ) ) ;
ITextComponent error = new StringTextComponent ( " Flywheel Renderer does not support Optifine Shaders " ) . withStyle ( TextFormatting . RED ) ;
2021-06-19 07:52:33 +02:00
2021-07-15 20:36:24 +02:00
player . displayClientMessage ( cannotUseER ? error : text , false ) ;
2021-06-19 07:52:33 +02:00
Backend . reloadWorldRenderers ( ) ;
}
@OnlyIn ( Dist . CLIENT )
private static void normalOverlay ( BooleanDirective state ) {
ClientPlayerEntity player = Minecraft . getInstance ( ) . player ;
if ( player = = null | | state = = null ) return ;
if ( state = = BooleanDirective . DISPLAY ) {
ITextComponent text = new StringTextComponent ( " Normal overlay is currently: " ) . append ( boolToText ( FlwConfig . get ( ) . client . normalDebug . get ( ) ) ) ;
2021-07-15 20:36:24 +02:00
player . displayClientMessage ( text , false ) ;
2021-06-19 07:52:33 +02:00
return ;
}
FlwConfig . get ( ) . client . normalDebug . set ( state . get ( ) ) ;
2021-07-15 20:36:24 +02:00
ITextComponent text = boolToText ( FlwConfig . get ( ) . client . normalDebug . get ( ) ) . append ( new StringTextComponent ( " Normal Overlay " ) . withStyle ( TextFormatting . 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
}
private static IFormattableTextComponent boolToText ( boolean b ) {
2021-07-15 20:36:24 +02:00
return b ? new StringTextComponent ( " enabled " ) . withStyle ( TextFormatting . DARK_GREEN ) : new StringTextComponent ( " disabled " ) . withStyle ( TextFormatting . RED ) ;
2021-06-19 07:52:33 +02:00
}
}