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 ) ,
2021-08-02 09:06:26 +02:00
CHUNK_CACHING ( ( ) - > BooleanConfig : : chunkCaching ) ,
2021-06-19 07:52:33 +02:00
;
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 ) {
2021-07-26 22:42:38 +02:00
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 ( ) ;
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-07-26 22:42:38 +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-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 ) {
ClientPlayerEntity player = Minecraft . getInstance ( ) . player ;
if ( player = = null | | state = = null ) return ;
if ( state = = BooleanDirective . DISPLAY ) {
2021-07-26 22:42:38 +02:00
ITextComponent text = new StringTextComponent ( " Normal debug mode is currently: " ) . append ( boolToText ( FlwConfig . get ( ) . client . debugNormals . get ( ) ) ) ;
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-07-26 22:42:38 +02:00
ITextComponent text = boolToText ( FlwConfig . get ( ) . client . debugNormals . get ( ) ) . append ( new StringTextComponent ( " normal debug mode " ) . 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
}
2021-08-02 09:06:26 +02:00
@OnlyIn ( Dist . CLIENT )
private static void chunkCaching ( BooleanDirective state ) {
ClientPlayerEntity player = Minecraft . getInstance ( ) . player ;
if ( player = = null | | state = = null ) return ;
if ( state = = BooleanDirective . DISPLAY ) {
2021-08-02 23:22:21 +02:00
ITextComponent text = new StringTextComponent ( " Chunk caching is currently: " ) . append ( boolToText ( FlwConfig . get ( ) . client . chunkCaching . get ( ) ) ) ;
2021-08-02 09:06:26 +02:00
player . displayClientMessage ( text , false ) ;
return ;
}
FlwConfig . get ( ) . client . chunkCaching . set ( state . get ( ) ) ;
ITextComponent text = boolToText ( FlwConfig . get ( ) . client . chunkCaching . get ( ) ) . append ( new StringTextComponent ( " chunk caching " ) . withStyle ( TextFormatting . WHITE ) ) ;
player . displayClientMessage ( text , false ) ;
Backend . reloadWorldRenderers ( ) ;
}
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
}
}