1
0
forked from Clones/Controlify

🐛 Fix reach-around policy not being loaded from server config

✏️ Force-enable reach-around on the client if the server specifically allows it, regardless of option in settings
This commit is contained in:
isXander
2023-08-08 11:01:45 +01:00
parent 5836c380ac
commit 44ab103b65
6 changed files with 46 additions and 14 deletions

View File

@ -5,6 +5,7 @@ import dev.isxander.controlify.api.ControlifyApi;
import dev.isxander.controlify.config.GlobalSettings;
import dev.isxander.controlify.reacharound.ReachAroundHandler;
import dev.isxander.controlify.reacharound.ReachAroundMode;
import dev.isxander.controlify.reacharound.ReachAroundPolicy;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.BooleanControllerBuilder;
import dev.isxander.yacl3.api.controller.EnumControllerBuilder;
@ -13,6 +14,7 @@ import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
@ -40,11 +42,17 @@ public class GlobalSettingsScreenFactory {
.text(Component.translatable("controlify.gui.reach_around.tooltip"))
.text(Component.translatable("controlify.gui.reach_around.tooltip.parity").withStyle(ChatFormatting.GRAY))
.text(state == ReachAroundMode.EVERYWHERE ? Component.translatable("controlify.gui.reach_around.tooltip.warning").withStyle(ChatFormatting.RED) : Component.empty())
.text(!ReachAroundHandler.reachAroundPolicy ? Component.translatable("controlify.gui.reach_around.tooltip.server_disabled").withStyle(ChatFormatting.GOLD) : Component.empty())
.text(ReachAroundHandler.reachAroundPolicy != ReachAroundPolicy.UNSET ? Component.translatable("controlify.gui.reach_around.tooltip.server_controlled").withStyle(ChatFormatting.GOLD) : Component.empty())
.build())
.binding(GlobalSettings.DEFAULT.reachAround, () -> ReachAroundHandler.reachAroundPolicy ? globalSettings.reachAround : ReachAroundMode.OFF, v -> globalSettings.reachAround = v)
.controller(opt -> EnumControllerBuilder.create(opt).enumClass(ReachAroundMode.class))
.available(ReachAroundHandler.reachAroundPolicy)
.binding(GlobalSettings.DEFAULT.reachAround, () -> globalSettings.reachAround, v -> globalSettings.reachAround = v)
.controller(opt -> EnumControllerBuilder.create(opt)
.enumClass(ReachAroundMode.class)
.valueFormatter(mode -> switch (ReachAroundHandler.reachAroundPolicy) {
case UNSET -> mode.getDisplayName();
case ALLOWED -> CommonComponents.OPTION_ON;
case DISALLOWED -> CommonComponents.OPTION_OFF;
}))
.available(ReachAroundHandler.reachAroundPolicy == ReachAroundPolicy.UNSET)
.build())
.option(Option.<Boolean>createBuilder()
.name(Component.translatable("controlify.gui.ui_sounds"))