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:
@ -15,6 +15,7 @@ import dev.isxander.controlify.gui.screen.SubmitUnknownControllerScreen;
|
||||
import dev.isxander.controlify.ingame.ControllerPlayerMovement;
|
||||
import dev.isxander.controlify.reacharound.ReachAroundHandler;
|
||||
import dev.isxander.controlify.reacharound.ReachAroundMode;
|
||||
import dev.isxander.controlify.reacharound.ReachAroundPolicy;
|
||||
import dev.isxander.controlify.screenop.ScreenProcessorProvider;
|
||||
import dev.isxander.controlify.config.ControlifyConfig;
|
||||
import dev.isxander.controlify.hid.ControllerHIDService;
|
||||
@ -248,7 +249,7 @@ public class Controlify implements ControlifyApi {
|
||||
});
|
||||
ClientPlayNetworking.registerGlobalReceiver(ReachAroundPolicyPacket.TYPE, (packet, player, sender) -> {
|
||||
Log.LOGGER.info("Connected server specified reach around policy is {}.", packet.allowed() ? "ALLOWED" : "DISALLOWED");
|
||||
ReachAroundHandler.reachAroundPolicy = packet.allowed();
|
||||
ReachAroundHandler.reachAroundPolicy = ReachAroundPolicy.fromServer(packet.allowed());
|
||||
|
||||
if (config().globalSettings().reachAround == ReachAroundMode.EVERYWHERE && !packet.allowed()) {
|
||||
ToastUtils.sendToast(
|
||||
@ -260,7 +261,7 @@ public class Controlify implements ControlifyApi {
|
||||
});
|
||||
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
|
||||
DebugLog.log("Disconnected from server, resetting reach around policy");
|
||||
ReachAroundHandler.reachAroundPolicy = true;
|
||||
ReachAroundHandler.reachAroundPolicy = ReachAroundPolicy.UNSET;
|
||||
});
|
||||
|
||||
FabricLoader.getInstance().getEntrypoints("controlify", ControlifyEntrypoint.class).forEach(entrypoint -> {
|
||||
@ -602,6 +603,7 @@ public class Controlify implements ControlifyApi {
|
||||
}
|
||||
|
||||
if (foundVersion != null) {
|
||||
Log.LOGGER.info("Sending new features toast for {}", foundVersion);
|
||||
ToastUtils.sendToast(
|
||||
Component.translatable("controlify.new_features.title", foundVersion),
|
||||
Component.translatable("controlify.new_features." + foundVersion),
|
||||
|
@ -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"))
|
||||
|
@ -8,7 +8,7 @@ import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
public class ReachAroundHandler {
|
||||
public static boolean reachAroundPolicy = true;
|
||||
public static ReachAroundPolicy reachAroundPolicy = ReachAroundPolicy.UNSET;
|
||||
|
||||
public static HitResult getReachAroundHitResult(Entity entity, HitResult hitResult) {
|
||||
// if there is already a valid hit, we don't want to override it
|
||||
@ -34,7 +34,7 @@ public class ReachAroundHandler {
|
||||
}
|
||||
|
||||
private static boolean canReachAround(Entity cameraEntity) {
|
||||
return reachAroundPolicy
|
||||
return reachAroundPolicy.canReachAround(Controlify.instance().config().globalSettings().reachAround)
|
||||
// don't want to place blocks while riding an entity
|
||||
&& cameraEntity.getVehicle() == null
|
||||
// straight ahead = 0deg, up = -90deg, down = 90deg
|
||||
@ -42,8 +42,6 @@ public class ReachAroundHandler {
|
||||
&& cameraEntity.getXRot() >= 45
|
||||
// if the player is not standing on a block, this is inappropriate
|
||||
// this also prevents selecting fluids as a valid position
|
||||
&& cameraEntity.onGround()
|
||||
// must respect config option
|
||||
&& Controlify.instance().config().globalSettings().reachAround.canReachAround();
|
||||
&& cameraEntity.onGround();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package dev.isxander.controlify.reacharound;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public enum ReachAroundPolicy {
|
||||
ALLOWED(mode -> true),
|
||||
DISALLOWED(mode -> false),
|
||||
UNSET(ReachAroundMode::canReachAround);
|
||||
|
||||
private final Function<ReachAroundMode, Boolean> canReachAround;
|
||||
|
||||
ReachAroundPolicy(Function<ReachAroundMode, Boolean> canReachAround) {
|
||||
this.canReachAround = canReachAround;
|
||||
}
|
||||
|
||||
public boolean canReachAround(ReachAroundMode mode) {
|
||||
return canReachAround.apply(mode);
|
||||
}
|
||||
|
||||
public static ReachAroundPolicy fromServer(boolean allowed) {
|
||||
return allowed ? ALLOWED : DISALLOWED;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package dev.isxander.controlify.server;
|
||||
|
||||
import dev.isxander.yacl3.config.ConfigEntry;
|
||||
import dev.isxander.yacl3.config.ConfigInstance;
|
||||
import dev.isxander.yacl3.config.GsonConfigInstance;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
@ -9,5 +10,5 @@ public class ControlifyServerConfig {
|
||||
.setPath(FabricLoader.getInstance().getConfigDir().resolve("controlify.json"))
|
||||
.build();
|
||||
|
||||
public boolean reachAroundPolicy = false;
|
||||
@ConfigEntry public boolean reachAroundPolicy = false;
|
||||
}
|
||||
|
@ -14,8 +14,8 @@
|
||||
"controlify.gui.reach_around.tooltip": "If enabled, you can interact with the block you are standing on in the direction you are looking.",
|
||||
"controlify.gui.reach_around.tooltip.parity": "This is parity with bedrock edition where you can also do this.",
|
||||
"controlify.gui.reach_around.tooltip.warning": "WARNING: This is an unfair advantage over other players without Controlify, and you will likely be flagged by many anti-cheats. This should only be used in situations where everyone playing recognises that you have this ability and are okay with it.",
|
||||
"controlify.gui.reach_around.tooltip.server_disabled": "The server you are playing on has does not allow you to use this feature.",
|
||||
"controlify.reach_around.off": "Off",
|
||||
"controlify.gui.reach_around.tooltip.server_controlled": "The server you are playing on is controlling this setting.",
|
||||
"controlify.reach_around.off": "OFF",
|
||||
"controlify.reach_around.singleplayer_only": "Singleplayer Only",
|
||||
"controlify.reach_around.singleplayer_and_lan": "Singleplayer and LAN",
|
||||
"controlify.reach_around.everywhere": "Everywhere",
|
||||
|
Reference in New Issue
Block a user