Skip to content

Commit

Permalink
v1.14.0 -> v2.0.1
Browse files Browse the repository at this point in the history
 Carpet-AMS-Addition v2.0.1
  • Loading branch information
1024-byteeeee authored Jun 13, 2023
2 parents 004b50e + 28f1b5f commit ffc3f72
Show file tree
Hide file tree
Showing 53 changed files with 1,825 additions and 1,218 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
.gradle/
.idea/
build/

/run/*
!/run/eula.txt
!/run/options.txt
!/run/server.properties
logs/
4 changes: 4 additions & 0 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ dependencies {

// mods
modImplementation "carpet:fabric-carpet:${project.carpet_core_version}"

// libraries
implementation "org.yaml:snakeyaml:${project.snakeyaml_version}"
include "org.yaml:snakeyaml:${project.snakeyaml_version}"
}

loom {
Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ org.gradle.jvmargs = -Xmx4G
loader_version = 0.14.14

# Mod Properties
mod_version = 1.14.0
mod_version = 2.0.1
maven_group = carpetamsaddition
archives_base_name = Carpet-AMS-Addition

# Dependencies
# https://mvnrepository.com/artifact/org.yaml/snakeyaml
snakeyaml_version = 2.0
10 changes: 9 additions & 1 deletion readme_folder/en_us/rules_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,15 @@ Sculk shrieker can be moved by piston or sticky piston.
- Suggested options: `false`, `true`
- Categroies: `AMS`, `FEATURE`, `AMS_movable`

## movableCalibratedSculkSensor

Calibrated Sculk Sensor can be moved by piston or sticky piston.

- Type: `boolean`
- Default: `false`
- Suggested options: `false` , `true`
- Categroies: `AMS` , `FEATURE` , `AMS_movable`

## craftableEnchantedGoldApple

Enchanted gold apple can be crafted using gold block and apple, which is the original crafting recipe before 15w44a.
Expand Down Expand Up @@ -508,7 +517,6 @@ Dispenser can be crafted more flexible. It can be crafted using bow and dropper,
- Suggested options: `false`, `true`
- Categroies: `AMS`, `SURVIVAL`, `CRAFTING`


## betterCraftablePolishedBlackStoneButton

Use deepslate to crafted polished_blackstone_button in minecraft.
Expand Down
17 changes: 12 additions & 5 deletions readme_folder/rules_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
## 超级弓 (superBow)

开启后,可以让弓同时拥有无限和经验修补附魔。
> 谁能拒绝一把同时拥有无限和经验修补的弓呢?

- 类型: `boolean`

Expand Down Expand Up @@ -116,7 +115,6 @@
## 地狱可放水 (netherWaterPlacement)

开启后,玩家可通过使用水桶的方式在地狱维度中放置水源。
> 很古老的需求。

- 类型: `boolean`
- 默认值: `false`
Expand All @@ -127,7 +125,6 @@
## 💻易碎深板岩 (softDeepslate)

开启后,深板岩的挖掘硬度将与石头相同(均可在急迫二效果下用效率5钻石镐进行瞬间挖掘)。
> 如果挖沟时面对无法秒破的深板岩很恼火那么可以使用此规则来偷个懒。

- 类型: `boolean`
- 默认值: `false`
Expand All @@ -138,7 +135,6 @@
## 💻易碎黑曜石 (softObsidian)

开启后,黑曜石的挖掘硬度将与深板岩相同。
> 可以用来在面对大量黑曜石时偷个懒。

- 类型: `boolean`
- 默认值: `false`
Expand All @@ -149,7 +145,6 @@
## 伪和平(fakePeace)

开启后,所有生物不会生成,但不影响困难难度(类似伪和平)。
> 用于在镜像服快速的实现不刷怪物且不切换难度。

- 类型: `boolean`
- 默认值: `false`
Expand Down Expand Up @@ -455,6 +450,7 @@
- 参考选项: `false` , `true`
- 分类: `AMS` , `FEATURE` , `AMS_movable`


## 可移动幽匿感测体(movableSculkSensor)

开启后,幽匿感测体可以被活塞/黏性活塞推动。
Expand All @@ -464,6 +460,17 @@
- 参考选项: `false` , `true`
- 分类: `AMS` , `FEATURE` , `AMS_movable`


## 可移动校频幽匿感测体(movableCalibratedSculkSensor)

开启后,校频幽匿感测体可以被活塞/黏性活塞推动。

- 类型: `boolean`
- 默认值: `false`
- 参考选项: `false` , `true`
- 分类: `AMS` , `FEATURE` , `AMS_movable`


## 可移动幽匿尖啸体(movableSculkShrieker)

开启后,幽匿尖啸体可以被活塞/黏性活塞推动。
Expand Down
170 changes: 77 additions & 93 deletions src/main/java/club/mcams/carpet/AmsServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@
import carpet.script.bundled.BundledModule;
//#endif

import club.mcams.carpet.commands.chunkloadingCommandRegistry;
import club.mcams.carpet.function.ChunkLoading;
import club.mcams.carpet.logging.AmsCarpetLoggerRegistry;
import club.mcams.carpet.util.AmsCarpetTranslations;
import club.mcams.carpet.settings.CarpetRuleRegistrar;
import club.mcams.carpet.translations.AMSTranslations;
import club.mcams.carpet.translations.TranslationConstants;
import club.mcams.carpet.util.Logging;
import club.mcams.carpet.util.recipes.CraftingRule;

import com.google.common.base.CaseFormat;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import com.mojang.brigadier.CommandDispatcher;

import net.minecraft.resource.ResourcePackManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ReloadCommand;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.WorldSavePath;
//#if MC>=11900
//$$ import net.minecraft.command.CommandRegistryAccess;
Expand All @@ -56,33 +52,43 @@ public class AmsServer implements CarpetExtension {

public static MinecraftServer minecraftServer;
private static final AmsServer INSTANCE = new AmsServer();
public static final String fancyName = "Carpet AMS Addition";
public static final String name = AmsServerMod.getModId();
public static final String MOD_NAME = "Carpet AMS Addition";
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);
public static final String compactName = name.replace("-",""); // carpetamsaddition
public static final Logger LOGGER = LogManager.getLogger(fancyName);

@Override
public String version() {
return name;
public Map<String, String> canHasTranslations(String lang) {
Map<String, String> trimmedTranslation = Maps.newHashMap();
String prefix = TranslationConstants.CARPET_TRANSLATIONS_KEY_PREFIX;
AMSTranslations.getTranslation(lang).forEach((key, value) -> {
if (key.startsWith(prefix)) {
String newKey = key.substring(prefix.length());
//#if MC>=11900
//$$ newKey = "carpet." + newKey;
//#endif
trimmedTranslation.put(newKey, value);
}
});
return trimmedTranslation;
}
public void onPlayerLoggedOut(ServerPlayerEntity player) {
ChunkLoading.onPlayerDisconnect(player);

@Override
public String version() {
return AmsServerMod.getModId();
}
public static void init() {
CarpetServer.manageExtension(INSTANCE);
}

@Override
public Map<String, String> canHasTranslations(String lang) {
return AmsCarpetTranslations.getTranslationFromResourcePath(lang);
AMSTranslations.loadTranslations();
}

@Override
public void onGameStarted() {
// let's /carpet handle our few simple settings
CarpetServer.settingsManager.parseSettingsClass(AmsServerSettings.class);
LOGGER.info(MOD_NAME + " " + "v" + AmsServerMod.getVersion() + " 载入成功");
LOGGER.info(fancyName + " " + "v" + AmsServerMod.getVersion() + " 载入成功");
LOGGER.info("开源链接:https://github.com/Minecraft-AMS/Carpet-AMS-Addition");
LOGGER.info("BUG反馈:https://github.com/Minecraft-AMS/Carpet-AMS-Addition/issues");
CarpetRuleRegistrar.register(CarpetServer.settingsManager, AmsServerSettings.class);
}

@Override
Expand All @@ -102,28 +108,9 @@ public void onServerClosed(MinecraftServer server) {
}
}

//#if MC>=11900
//$$ @Override
//$$ public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, final CommandRegistryAccess commandBuildContext) {
//$$ chunkloadingCommandRegistry.register(dispatcher);
//$$ }
//#else
@Override
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) {
chunkloadingCommandRegistry.register(dispatcher);
}
//#endif

@Override
public void onPlayerLoggedIn(ServerPlayerEntity player) {
ChunkLoading.onPlayerConnect(player);
}

@Override
public void registerLoggers() {
AmsCarpetLoggerRegistry.registerLoggers();
}

/**
* From Rug Mod
*/
@Override
public void onServerLoadedWorlds(MinecraftServer server) {
String datapackPath = server.getSavePath(WorldSavePath.DATAPACKS).toString();
Expand All @@ -141,13 +128,13 @@ public void onServerLoadedWorlds(MinecraftServer server) {
Files.createDirectories(new File(datapackPath + "data/ams/recipes").toPath());
Files.createDirectories(new File(datapackPath + "data/ams/advancements").toPath());
Files.createDirectories(new File(datapackPath + "data/minecraft/recipes").toPath());
copyFile("assets/carpet-ams-addition/AmsRecipeTweakPack/pack.mcmeta", datapackPath + "pack.mcmeta");
copyFile("assets/carpetamsaddition/AmsRecipeTweakPack/pack.mcmeta", datapackPath + "pack.mcmeta");
} catch (IOException e) {
Logging.logStackTrace(e);
}

copyFile(
"assets/carpet-ams-addition/AmsRecipeTweakPack/ams/advancements/root.json",
"assets/carpetamsaddition/AmsRecipeTweakPack/ams/advancements/root.json",
datapackPath + "data/ams/advancements/root.json"
);

Expand All @@ -174,19 +161,19 @@ public void onServerLoadedWorlds(MinecraftServer server) {
private void registerCraftingRule(String ruleName, String[] recipes, String recipeNamespace, String dataPath) {
updateCraftingRule(CarpetServer.settingsManager.getRule(ruleName),recipes,recipeNamespace,dataPath,ruleName);
CarpetServer.settingsManager.addRuleObserver
((source, rule, s) -> {
//#if MC>=11900
//$$if (rule.name().equals(ruleName)) {
//$$ updateCraftingRule(rule, recipes, recipeNamespace, dataPath, ruleName);
//$$ reload();
//$$}
//#else
if (rule.name.equals(ruleName)) {
updateCraftingRule(rule, recipes, recipeNamespace, dataPath, ruleName);
reload();
}
//#endif
});
((source, rule, s) -> {
//#if MC>=11900
//$$if (rule.name().equals(ruleName)) {
//$$ updateCraftingRule(rule, recipes, recipeNamespace, dataPath, ruleName);
//$$ reload();
//$$}
//#else
if (rule.name.equals(ruleName)) {
updateCraftingRule(rule, recipes, recipeNamespace, dataPath, ruleName);
reload();
}
//#endif
});
}

private void updateCraftingRule(
Expand Down Expand Up @@ -280,7 +267,7 @@ else if (rule.type == boolean.class && rule.getBoolValue()) {
private void copyRecipes(String[] recipes, String recipeNamespace, String datapackPath, String ruleName) {
for (String recipeName : recipes) {
copyFile(
"assets/carpet-ams-addition/AmsRecipeTweakPack/" + recipeNamespace + "/recipes/" + recipeName,
"assets/carpetamsaddition/AmsRecipeTweakPack/" + recipeNamespace + "/recipes/" + recipeName,
datapackPath + recipeNamespace + "/recipes/" + recipeName
);
}
Expand Down Expand Up @@ -310,7 +297,7 @@ private void deleteRecipes(

private void writeAdvancement(String datapackPath, String ruleName, String[] recipes) {
copyFile(
"assets/carpet-ams-addition/AmsRecipeTweakPack/ams/advancements/recipe_rule.json",
"assets/carpetamsaddition/AmsRecipeTweakPack/ams/advancements/recipe_rule.json",
datapackPath + "ams/advancements/" + ruleName + ".json"
);

Expand Down Expand Up @@ -355,39 +342,36 @@ private void copyFile(String resourcePath, String targetPath) {
Logging.logStackTrace(e);
}
}
//#if MC>=11900
private static JsonObject readJson(String filePath) {
try {
FileReader reader = new FileReader(filePath);
return JsonParser.parseReader(reader).getAsJsonObject();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
//#else
//$$ private static JsonObject readJson(String filePath) {
//$$ JsonParser jsonParser = new JsonParser();
//$$ try {
//$$ FileReader reader = new FileReader(filePath);
//$$ return jsonParser.parse(reader).getAsJsonObject();
//$$ } catch (FileNotFoundException e) {
//$$ e.printStackTrace();
//$$ }
//$$ return null;
//$$}
//#endif

private static void writeJson(JsonObject jsonObject, String filePath) {
try {
FileWriter writer = new FileWriter(filePath);
writer.write(new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject));
writer.close();
} catch (IOException e) {
Logging.logStackTrace(e);
}
//#if MC>=11900
private static JsonObject readJson(String filePath) {
try {
FileReader reader = new FileReader(filePath);
return JsonParser.parseReader(reader).getAsJsonObject();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
//#else
//$$ private static JsonObject readJson(String filePath) {
//$$ JsonParser jsonParser = new JsonParser();
//$$ try {
//$$ FileReader reader = new FileReader(filePath);
//$$ return jsonParser.parse(reader).getAsJsonObject();
//$$ } catch (FileNotFoundException e) {
//$$ e.printStackTrace();
//$$ }
//$$ return null;
//$$}
//#endif



private static void writeJson(JsonObject jsonObject, String filePath) {
try {
FileWriter writer = new FileWriter(filePath);
writer.write(new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject));
writer.close();
} catch (IOException e) {
Logging.logStackTrace(e);
}
}
}
Loading

0 comments on commit ffc3f72

Please sign in to comment.