-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
231 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,144 @@ | ||
# 卷帘门 | Rolling Gate | ||
|
||
> 一个NeoForge模组,控制Minecraft技术选项 | ||
> | ||
> | ||
> A NeoForge mod that controls Minecraft technology options | ||
[![Development Builds](https://github.com/Anvil-Dev/RollingGate/actions/workflows/ci.yml/badge.svg)](https://github.com/Anvil-Dev/RollingGate/actions/workflows/ci.yml) | ||
[![GitHub downloads](https://img.shields.io/github/downloads/Anvil-Dev/RollingGate/total?label=Github%20downloads&logo=github)](https://github.com/Anvil-Dev/RollingGate/releases) | ||
|
||
## 声明 | Disclaimer | ||
|
||
> 本模组仅支持 Minecraft 1.21+ ,暂无向更低版本兼容的计划。 | ||
> | ||
> This mod only supports Minecraft 1.21+ and has no plans to be compatible with lower versions at the moment. | ||
> | ||
> 本模组代码基于 [LGPL-3.0](./LICENSE) 协议开源,其它资产基于 [CC-BY-NC-ND 4.0](./LICENSE_ASSETS) 发布,请遵守协议。 | ||
> | ||
> This module code is open source based on the [LGPL-3.0](./LICENSE) protocol, while other assets are released based on | ||
> the [CC-BY-NC-ND 4.0](./LICENSE_ASSETS) protocol. Please comply with the protocol. | ||
## 快速开始 | Quick Start | ||
|
||
1. 下载模组,放置到 `.minecraft/mods` 或 `.minecraft/versions/{version}/mods` 文件夹 | ||
2. 进入存档,使用 `/rg` 命令显示模组控制面板以调整规则的启用状态 | ||
|
||
## 配置 | Configuration | ||
|
||
* 在 `configs/rolling-gate.json` 中修改默认配置,该配置将影响所有存档 | ||
* 在存档目录中创建 `rolling-gate.json` 文件以覆盖默认配置 | ||
* 配置文件格式为 JSON,示例如下: | ||
|
||
```json5 | ||
{ | ||
// string | ||
"rule1": "value", | ||
// int | ||
"rule2": 1, | ||
// double | ||
"rule3": 1.0, | ||
// boolean | ||
"rule4": true | ||
} | ||
``` | ||
|
||
## 命令 | Command | ||
|
||
* `/rg` - 显示模组控制面板 | ||
* `reload` - 重新加载配置文件 | ||
* `list` - 列出所有修改过的规则 | ||
* `[rule]` - 查看规则的详细信息 | ||
* `category [category]` - 查看分组下的所有规则 | ||
* `set [rule] [value]` - 设置规则的值 | ||
* `default [rule] [value]` - 设置当前存档的规则默认值 | ||
|
||
* `/rg` - Display mod control panel | ||
* `reload` - Reload configuration file | ||
* `list` - List all modified rules | ||
* `[rule]` - View detailed information of rules | ||
* `category [category]` - View all rules under the group | ||
* `set [rule] [value]` - Set the value of the rule | ||
* `default [rule] [value]` - Set default rules for the current save | ||
|
||
## 规则 | Rules | ||
|
||
| 规则 | 类型 | 默认值 | 允许值 | 描述 | | ||
|------------|--------|---------|------------------|------------| | ||
| `language` | String | `zh_cn` | `en_us`, `zh_cn` | 设置卷帘门的默认语言 | | ||
|
||
| Rule | Type | Default Value | Allowed Value | Description | | ||
|------------|--------|---------------|------------------|------------------------------------------| | ||
| `language` | String | `zh_cn` | `en_us`, `zh_cn` | Set the default language for RollingGate | | ||
|
||
## 贡献 | Contribution | ||
|
||
* Fork 仓库 | Fork Repository | ||
* [![Fork Repository](https://img.shields.io/badge/Fork%20Repository-blue?logo=github)](https://github.com/Anvil-Dev/RollingGate/fork) | ||
|
||
* 提交 PR | Submit PR | ||
* [![Submit PR](https://img.shields.io/badge/Submit%20PR-green?logo=github)](https://github.com/Anvil-Dev/RollingGate/pulls) | ||
|
||
## 贡献者 | Contributors | ||
|
||
<!--suppress ALL --> | ||
<table> | ||
<tr> | ||
<td align="center"> | ||
<a href="https://github.com/Gu-ZT"> | ||
<img src="https://avatars.githubusercontent.com/u/34372427?v=100&s=100" width="100px" height="100px" alt=""/><br /> | ||
<sub><b>Gugle</b></sub> | ||
</a><br /> | ||
<a title="Code">💻</a><br /> | ||
<a href="https://space.bilibili.com/19822751">19822751</a> | ||
</td> | ||
<td align="center"> | ||
<a href="https://github.com/Cjsah"> | ||
<img src="https://avatars.githubusercontent.com/u/46415647?v=100&s=100" width="100px" height="100px" alt=""/><br /> | ||
<sub><b>꧁[C̲̅j̲̅s̲̅a̲̅h̲̅]꧂</b></sub> | ||
</a><br /> | ||
<a title="Code">💻</a><br /> | ||
<a href="https://space.bilibili.com/19170004">19170004</a> | ||
</td> | ||
</tr> | ||
</table> | ||
|
||
## 联系我们 | Contact Us | ||
|
||
* [![Contact Us](https://img.shields.io/badge/Contact%20Us-white?logo=tencentqq)](https://qm.qq.com/q/alOmGR4G6k) | ||
|
||
## 赞助我们 | Sponsor Us | ||
|
||
* [![Sponsor Us](https://img.shields.io/badge/Sponsor%20Us-blue?logo=githubsponsors)](https://www.anvilcraft.dev/#/support) | ||
|
||
## 赞助者 | Sponsors | ||
|
||
## 编写附属 | Write Additional | ||
|
||
* 编写一个类实现 `dev.anvilcraft.rg.api.RGAdditional` | ||
* Write a class implement `dev.anvilcraft.rg.api.RGAdditional` | ||
|
||
```java | ||
public class YourAdditional implements RGAdditional { | ||
@Override | ||
public void loadRules(@NotNull RGRuleManager manager) { | ||
manager.register(YourRules.class); | ||
} | ||
} | ||
``` | ||
|
||
* 亦可以让你的模组主类实现 `dev.anvilcraft.rg.api.RGAdditional` | ||
* You can also enable your mod main class to implement `dev.anvilcraft.rg.api.RGAdditional` | ||
|
||
```java | ||
@Mod('your_mod_id') | ||
public class YourMod implements RGAdditional { | ||
public YourMod(IEventBus modEventBus, ModContainer modContainer) { | ||
// ... | ||
} | ||
|
||
@Override | ||
public void loadRules(@NotNull RGRuleManager manager) { | ||
manager.register(YourRules.class); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,76 @@ | ||
package dev.anvilcraft.rg; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.mojang.logging.LogUtils; | ||
import dev.anvilcraft.rg.api.RGAdditional; | ||
import dev.anvilcraft.rg.api.RGRuleException; | ||
import dev.anvilcraft.rg.api.RGRuleManager; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.util.GsonHelper; | ||
import net.minecraft.world.level.storage.LevelResource; | ||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.ModContainer; | ||
import net.neoforged.fml.ModList; | ||
import net.neoforged.fml.common.Mod; | ||
import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent; | ||
import net.neoforged.neoforge.common.NeoForge; | ||
import net.neoforged.neoforge.event.server.ServerStartingEvent; | ||
import org.apache.commons.io.FileUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.spongepowered.include.com.google.common.base.Charsets; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
@Mod(RollingGate.MODID) | ||
public class RollingGate { | ||
public class RollingGate implements RGAdditional { | ||
public static final String MODID = "rolling_gate"; | ||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
private static final RGRuleManager RULE_MANAGER = new RGRuleManager(); | ||
private static final LevelResource RULE_PATH = new LevelResource("rolling_gate.json"); | ||
|
||
public RollingGate(@NotNull IEventBus modEventBus, ModContainer modContainer) { | ||
NeoForge.EVENT_BUS.addListener(this::reInitRules); | ||
modEventBus.addListener(this::loadRGRules); | ||
} | ||
|
||
@Override | ||
public void loadRules(@NotNull RGRuleManager manager) { | ||
manager.register(RollingGateRules.class); | ||
} | ||
|
||
@SubscribeEvent | ||
public void loadRGRules(FMLLoadCompleteEvent event) { | ||
ModList.get().forEachModContainer((modId, modContainer) -> { | ||
RollingGate.RULE_MANAGER.setNamespace(modId); | ||
Optional<RGAdditional> additional = modContainer.getCustomExtension(RGAdditional.class); | ||
additional.ifPresent(add -> add.loadRules(RollingGate.RULE_MANAGER)); | ||
}); | ||
} | ||
|
||
public RollingGate(IEventBus modEventBus, ModContainer modContainer) { | ||
NeoForge.EVENT_BUS.addListener((ServerStartingEvent event) -> RGRuleManager.reInitSaveRules(event.getServer())); | ||
@SubscribeEvent | ||
public void reInitRules(@NotNull ServerStartingEvent event) { | ||
MinecraftServer server = event.getServer(); | ||
Path path = server.getWorldPath(RollingGate.RULE_PATH); | ||
JsonObject config = getOrCreateContent(path); | ||
RollingGate.RULE_MANAGER.reInit(config); | ||
} | ||
|
||
private static @NotNull JsonObject getOrCreateContent(@NotNull Path path) { | ||
File file = path.toFile(); | ||
try { | ||
if (!file.exists() || file.isDirectory()) { | ||
FileUtils.writeStringToFile(file, "{}", Charsets.UTF_8); | ||
return new JsonObject(); | ||
} | ||
String value = FileUtils.readFileToString(path.toFile(), Charsets.UTF_8); | ||
return GsonHelper.parse(value); | ||
} catch (IOException e) { | ||
throw new RGRuleException("Failed to read rolling gate config file", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package dev.anvilcraft.rg; | ||
|
||
public class RollingGateCategories { | ||
public static final String DISABLED = "DISABLED"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.anvilcraft.rg; | ||
|
||
import dev.anvilcraft.rg.api.Rule; | ||
|
||
public class RollingGateRules { | ||
@Rule(allowed = {"true", "false"}, categories = {RollingGateCategories.DISABLED}) | ||
public static final boolean antiCheatDisabled = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.anvilcraft.rg.api; | ||
|
||
import net.neoforged.fml.IExtensionPoint; | ||
|
||
public interface RGAdditional extends IExtensionPoint { | ||
void loadRules(RGRuleManager manager); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.