AutoStore 模组完整源码
这个提交包含在:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 本文件由 autostore-1.0-SNAPSHOT.jar 反编译并整理而来(CFR 0.152),
|
||||
* 混淆名已替换为 Minecraft 1.21.4 Yarn 可读映射,并补充中文注释。
|
||||
*/
|
||||
package autostore.client.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileAttribute;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
/**
|
||||
* 配置文件读写器。
|
||||
*
|
||||
* <p>使用 Gson 将 {@link ExpansionConfig} 序列化为 JSON,
|
||||
* 配置文件位于 Fabric 配置目录下的 {@code autostore.json}。</p>
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class ConfigStore {
|
||||
|
||||
/** 用于格式化的 Gson 实例(美化输出) */
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
/**
|
||||
* 从磁盘加载配置;文件不存在或解析失败时返回默认配置。
|
||||
*
|
||||
* @return 加载到的配置(不会为 null)
|
||||
*/
|
||||
public ExpansionConfig load() {
|
||||
Path path = this.path();
|
||||
if (!Files.exists(path, new LinkOption[0])) {
|
||||
return new ExpansionConfig();
|
||||
}
|
||||
try {
|
||||
String json = Files.readString(path, StandardCharsets.UTF_8);
|
||||
ExpansionConfig loaded = GSON.fromJson(json, ExpansionConfig.class);
|
||||
if (loaded == null) {
|
||||
return new ExpansionConfig();
|
||||
}
|
||||
// 以下字段为固定默认值,防止旧配置文件中的异常值影响运行
|
||||
loaded.autoEat = true;
|
||||
loaded.eatThreshold = 14;
|
||||
loaded.maxRings = 0;
|
||||
return loaded;
|
||||
} catch (Exception e) {
|
||||
// 解析失败时回退到默认配置
|
||||
return new ExpansionConfig();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将配置保存到磁盘(自动创建父目录)。
|
||||
*
|
||||
* @param config 要保存的配置
|
||||
*/
|
||||
public void save(ExpansionConfig config) {
|
||||
Path path = this.path();
|
||||
try {
|
||||
if (path.getParent() != null) {
|
||||
Files.createDirectories(path.getParent(), new FileAttribute[0]);
|
||||
}
|
||||
Files.writeString(path, GSON.toJson(config), StandardCharsets.UTF_8, new OpenOption[0]);
|
||||
} catch (IOException iOException) {
|
||||
// 保存失败时静默忽略(不阻塞游戏运行)
|
||||
}
|
||||
}
|
||||
|
||||
/** @return 配置文件路径(Fabric 配置目录 / autostore.json) */
|
||||
private Path path() {
|
||||
return FabricLoader.getInstance().getConfigDir().resolve("autostore.json");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 本文件由 autostore-1.0-SNAPSHOT.jar 反编译并整理而来(CFR 0.152),
|
||||
* 混淆名已替换为 Minecraft 1.21.4 Yarn 可读映射,并补充中文注释。
|
||||
*/
|
||||
package autostore.client.config;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
/**
|
||||
* 自动扩地配置数据类。
|
||||
*
|
||||
* <p>保存了扩地策略、目标数量、超时重试、区域限制以及 Baritone 寻路行为等全部可配置项,
|
||||
* 通过 {@link ConfigStore} 持久化为 JSON 文件。</p>
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ExpansionConfig {
|
||||
|
||||
/** 扩地策略:1=方形外扩,2=区域扩地,3=玩家周围,4=绕国一圈 */
|
||||
public int strategy = 1;
|
||||
|
||||
/** 目标邦国名称;为空时表示自动识别玩家当前所在邦国 */
|
||||
public String stateName = "";
|
||||
|
||||
/** 目标扩地数量;-1 表示持续扩地直到无可用区块 */
|
||||
public int targetCount = -1;
|
||||
|
||||
/** 等待/寻路超时时间(秒) */
|
||||
public int waitTimeoutSeconds = 60;
|
||||
|
||||
/** 超时后的最大重试次数 */
|
||||
public int retries = 2;
|
||||
|
||||
/** 区域扩地策略的中心 X 坐标(区块) */
|
||||
public int regionCenterX;
|
||||
|
||||
/** 区域扩地策略的中心 Z 坐标(区块) */
|
||||
public int regionCenterZ;
|
||||
|
||||
/** 区域扩地策略的半径(区块) */
|
||||
public int regionRadius = 5;
|
||||
|
||||
/** 区域扩地策略的矩形边界(区块坐标);minX > maxX 表示未圈选,使用中心+半径 */
|
||||
public int regionMinX = 0;
|
||||
|
||||
/** 区域扩地策略的矩形边界(区块坐标);未圈选时为 -1 */
|
||||
public int regionMaxX = -1;
|
||||
|
||||
/** 区域扩地策略的矩形边界(区块坐标);minZ > maxZ 表示未圈选,使用中心+半径 */
|
||||
public int regionMinZ = 0;
|
||||
|
||||
/** 区域扩地策略的矩形边界(区块坐标);未圈选时为 -1 */
|
||||
public int regionMaxZ = -1;
|
||||
|
||||
/** 是否允许 Baritone 疾跑 */
|
||||
public boolean allowSprint = true;
|
||||
|
||||
/** 是否允许 Baritone 游泳 */
|
||||
public boolean allowSwim = true;
|
||||
|
||||
/** 是否允许 Baritone 跳跃 */
|
||||
public boolean allowJump = true;
|
||||
|
||||
/** 是否允许 Baritone 破坏方块 */
|
||||
public boolean allowBreak;
|
||||
|
||||
/** 是否允许 Baritone 放置方块 */
|
||||
public boolean allowPlace;
|
||||
|
||||
/** 是否启用避开怪物 */
|
||||
public boolean avoidMobs = true;
|
||||
|
||||
/** 是否启用自动进食(饥饿时自动吃背包食物) */
|
||||
public boolean autoEat = true;
|
||||
|
||||
/** 触发自动进食的饥饿值阈值(0-20) */
|
||||
public int eatThreshold = 14;
|
||||
|
||||
/** 扩圈上限(0 表示不限制) */
|
||||
public int maxRings;
|
||||
|
||||
/** 地图自动刷新间隔(秒),最小 10 秒 */
|
||||
public int refreshIntervalSeconds = 30;
|
||||
|
||||
/**
|
||||
* 深拷贝当前配置,返回一个独立的副本。
|
||||
*
|
||||
* @return 与当前配置完全相同的副本
|
||||
*/
|
||||
public ExpansionConfig copy() {
|
||||
ExpansionConfig c = new ExpansionConfig();
|
||||
c.strategy = this.strategy;
|
||||
c.stateName = this.stateName;
|
||||
c.targetCount = this.targetCount;
|
||||
c.waitTimeoutSeconds = this.waitTimeoutSeconds;
|
||||
c.retries = this.retries;
|
||||
c.regionCenterX = this.regionCenterX;
|
||||
c.regionCenterZ = this.regionCenterZ;
|
||||
c.regionRadius = this.regionRadius;
|
||||
c.regionMinX = this.regionMinX;
|
||||
c.regionMaxX = this.regionMaxX;
|
||||
c.regionMinZ = this.regionMinZ;
|
||||
c.regionMaxZ = this.regionMaxZ;
|
||||
c.allowSprint = this.allowSprint;
|
||||
c.allowSwim = this.allowSwim;
|
||||
c.allowJump = this.allowJump;
|
||||
c.allowBreak = this.allowBreak;
|
||||
c.allowPlace = this.allowPlace;
|
||||
c.avoidMobs = this.avoidMobs;
|
||||
c.autoEat = this.autoEat;
|
||||
c.eatThreshold = this.eatThreshold;
|
||||
c.maxRings = this.maxRings;
|
||||
c.refreshIntervalSeconds = this.refreshIntervalSeconds;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户