添加Mod收费警告相关配置项

This commit is contained in:
Light_Quanta 2025-02-27 12:53:42 +08:00
parent a3df2118a2
commit bd214c1560
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 24 additions and 20 deletions

View file

@ -1,5 +1,6 @@
package com.atsuishio.superbwarfare.client.screens; package com.atsuishio.superbwarfare.client.screens;
import com.atsuishio.superbwarfare.config.client.ModSellWarningConfig;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Button;
@ -46,12 +47,6 @@ public class ModSellWarningScreen extends WarningScreen {
"stupidNoPayWarningChecksum" // 神秘的盐 "stupidNoPayWarningChecksum" // 神秘的盐
); );
//
// System.out.println("env info:");
// environmentInfo.forEach(System.out::println);
// System.out.println("env info end");
//
return sha256(String.join("|", environmentInfo)); return sha256(String.join("|", environmentInfo));
} }
@ -79,32 +74,25 @@ public class ModSellWarningScreen extends WarningScreen {
this.lastScreen = lastScreen; this.lastScreen = lastScreen;
} }
// TODO 正确实现校验和配置文件
private static String checksumTest = "";
@SubscribeEvent(priority = EventPriority.HIGH) @SubscribeEvent(priority = EventPriority.HIGH)
public static void onGuiOpen(ScreenEvent.Opening event) { public static void onGuiOpen(ScreenEvent.Opening event) {
if (!(event.getNewScreen() instanceof JoinMultiplayerScreen && !(event.getCurrentScreen() instanceof ModSellWarningScreen))) if (!(event.getNewScreen() instanceof JoinMultiplayerScreen && !(event.getCurrentScreen() instanceof ModSellWarningScreen)))
return; return;
System.out.println("multiplayer screen open"); if (ModSellWarningConfig.ENVIRONMENT_CHECKSUM.get().equals(ENVIRONMENT_CHECKSUM)) return;
if (checksumTest.equals(ENVIRONMENT_CHECKSUM)) return;
// if (ModSellWarningConfig.ENVIRONMENT_CHECKSUM.get().equals(ENVIRONMENT_CHECKSUM)) return;
// 拦截多人游戏界面加载 // 拦截多人游戏界面加载
event.setCanceled(true); event.setCanceled(true);
Minecraft.getInstance().setScreen(new ModSellWarningScreen(event.getCurrentScreen())); Minecraft.getInstance().setScreen(new ModSellWarningScreen(event.getCurrentScreen()));
System.out.println(ENVIRONMENT_CHECKSUM);
} }
@Override @Override
protected void initButtons(int pYOffset) { protected void initButtons(int pYOffset) {
this.addRenderableWidget(Button.builder(CommonComponents.GUI_PROCEED, button -> { this.addRenderableWidget(Button.builder(CommonComponents.GUI_PROCEED, button -> {
if (this.stopShowing.selected()) { if (this.stopShowing.selected()) {
checksumTest = ENVIRONMENT_CHECKSUM; ModSellWarningConfig.ENVIRONMENT_CHECKSUM.set(ENVIRONMENT_CHECKSUM);
// ModSellWarningConfig.ENVIRONMENT_CHECKSUM.set(ENVIRONMENT_CHECKSUM); ModSellWarningConfig.ENVIRONMENT_CHECKSUM.save();
// ModSellWarningConfig.ENVIRONMENT_CHECKSUM.save();
} }
Minecraft.getInstance().setScreen(new JoinMultiplayerScreen(this.lastScreen)); Minecraft.getInstance().setScreen(new JoinMultiplayerScreen(this.lastScreen));
}).bounds(this.width / 2 - 155, 100 + pYOffset, 150, 20).build()); }).bounds(this.width / 2 - 155, 100 + pYOffset, 150, 20).build());

View file

@ -1,9 +1,6 @@
package com.atsuishio.superbwarfare.config; package com.atsuishio.superbwarfare.config;
import com.atsuishio.superbwarfare.config.client.DisplayConfig; import com.atsuishio.superbwarfare.config.client.*;
import com.atsuishio.superbwarfare.config.client.KillMessageConfig;
import com.atsuishio.superbwarfare.config.client.ReloadConfig;
import com.atsuishio.superbwarfare.config.client.VehicleControlConfig;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
public class ClientConfig { public class ClientConfig {
@ -15,6 +12,7 @@ public class ClientConfig {
KillMessageConfig.init(builder); KillMessageConfig.init(builder);
DisplayConfig.init(builder); DisplayConfig.init(builder);
VehicleControlConfig.init(builder); VehicleControlConfig.init(builder);
ModSellWarningConfig.init(builder);
return builder.build(); return builder.build();
} }

View file

@ -0,0 +1,18 @@
package com.atsuishio.superbwarfare.config.client;
import net.minecraftforge.common.ForgeConfigSpec;
public class ModSellWarningConfig {
public static ForgeConfigSpec.ConfigValue<String> ENVIRONMENT_CHECKSUM;
public static void init(ForgeConfigSpec.Builder builder) {
builder.push("checksum");
builder.comment("System environment checksum, do not edit");
ENVIRONMENT_CHECKSUM = builder.define("environment_checksum", "");
builder.pop();
}
}