Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
wendavid552 committed Jun 19, 2024
2 parents 2521216 + 7b8bc81 commit 62e83af
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 20 deletions.
10 changes: 9 additions & 1 deletion common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {

// library mods
include(modImplementation("com.github.1024-byteeeee:AnnotationToolBox:${project.annotationtoolbox_version}"))
include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.mixinextras_version}")))

// Dependencies
include(implementation("com.esotericsoftware.yamlbeans:yamlbeans:${project.yamlbeans_version}"))
Expand Down Expand Up @@ -90,6 +91,13 @@ if (mcVersion >= 12005) {
COMPAT_RECIPES_ITEM_ID = "item"
}

def COMPAT_RECIPES_PATH
if (mcVersion >= 12100) {
COMPAT_RECIPES_PATH = "assets/carpetamsaddition/AmsRecipeTweakPack/ams/recipe/*.json"
} else {
COMPAT_RECIPES_PATH = "assets/carpetamsaddition/AmsRecipeTweakPack/ams/recipes/*.json"
}

String versionSuffix = ''
// detect github action environment variables
// https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
Expand Down Expand Up @@ -125,7 +133,7 @@ processResources {
}
}

filesMatching("assets/carpetamsaddition/AmsRecipeTweakPack/ams/recipes/*.json") {
filesMatching(COMPAT_RECIPES_PATH) {
filter {
text -> text.replace("/*ams_recipes_item_id*/", COMPAT_RECIPES_ITEM_ID)
}
Expand Down
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loader_version = 0.15.11
# Mod Properties
mod_id = carpet-ams-addition
mod_name = Carpet AMS Addition
mod_version = 2.44.4
mod_version = 2.44.6
maven_group = carpetamsaddition
archives_base_name = Carpet-AMS-Addition

Expand All @@ -17,4 +17,7 @@ archives_base_name = Carpet-AMS-Addition
yamlbeans_version = 1.17

# https://github.com/1024-byteeeee/AnnotationToolBox
annotationtoolbox_version = 0.3
annotationtoolbox_version = 0.3

# https://github.com/LlamaLad7/MixinExtras
mixinextras_version = 0.3.6
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ private boolean onEntityCollision(
if (AmsServerSettings.playerNoNetherPortalTeleport && entity instanceof PlayerEntity) {
return false;
} else {
//#if MC>=12100
//$$ return original.call(entity, canUsePortals);
//#else
return original.call(entity);
//#endif
}
}
}
51 changes: 34 additions & 17 deletions src/main/java/club/mcams/carpet/utils/CraftingRuleUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
import java.util.stream.Stream;

public class CraftingRuleUtil {
private static final String COMPAT_ADVANCEMENT_FOLDER_NAME;
private static final String COMPAT_RECIPE_FOLDER_NAME;

public static void clearAmsDatapacks(MinecraftServer minecraftServer) {
File datapackPath = new File(minecraftServer.getSavePath(WorldSavePath.DATAPACKS).toString() + "/AmsData/data/");
if (Files.isDirectory(datapackPath.toPath())) {
Expand All @@ -81,16 +84,16 @@ public static void loadAmsDatapacks(MinecraftServer minecraftServer) {
datapackPath += "/AmsData/";
boolean isFirstLoad = !Files.isDirectory(new File(datapackPath).toPath());
try {
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());
Files.createDirectories(new File(datapackPath + "data/ams/" + COMPAT_RECIPE_FOLDER_NAME).toPath());
Files.createDirectories(new File(datapackPath + "data/ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME).toPath());
Files.createDirectories(new File(datapackPath + "data/minecraft/" + COMPAT_RECIPE_FOLDER_NAME).toPath());
copyFile("assets/carpetamsaddition/AmsRecipeTweakPack/pack.mcmeta", datapackPath + "pack.mcmeta");
} catch (IOException e) {
AmsServer.LOGGER.error("Failed to create directories or copy files: {}", e.getMessage());
}
copyFile(
"assets/carpetamsaddition/AmsRecipeTweakPack/ams/advancements/root.json",
datapackPath + "data/ams/advancements/root.json"
"assets/carpetamsaddition/AmsRecipeTweakPack/ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME + "/root.json",
datapackPath + "data/ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME + "/root.json"
);
for (Field f : AmsServerSettings.class.getDeclaredFields()) {
CraftingRule craftingRule = f.getAnnotation(CraftingRule.class);
Expand Down Expand Up @@ -135,7 +138,11 @@ private static void updateCraftingRule(ParsedRule<?> rule, String[] recipes, Str
//#endif
List<String> installedRecipes = Lists.newArrayList();
try {
Stream<Path> fileStream = Files.list(new File(datapackPath + recipeNamespace, "recipes").toPath());
//#if MC>=12100
//$$ Stream<Path> fileStream = Files.list(new File(datapackPath + recipeNamespace, COMPAT_RECIPE_FOLDER_NAME).toPath());
//#else
Stream<Path> fileStream = Files.list(new File(datapackPath + recipeNamespace, COMPAT_RECIPE_FOLDER_NAME).toPath());
//#endif
fileStream.forEach(( path -> {
for (String recipeName : recipes) {
String fileName = path.getFileName().toString();
Expand All @@ -152,7 +159,7 @@ private static void updateCraftingRule(ParsedRule<?> rule, String[] recipes, Str
if (recipeNamespace.equals("ams")) {
List<String> installedAdvancements = Lists.newArrayList();
try {
Stream<Path> fileStream = Files.list(new File(datapackPath, "ams/advancements").toPath());
Stream<Path> fileStream = Files.list(new File(datapackPath, "ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME).toPath());
String finalRuleName = ruleName;
fileStream.forEach(( path -> {
String fileName = path.getFileName().toString().replace(".json", "");
Expand Down Expand Up @@ -184,7 +191,7 @@ private static void updateCraftingRule(ParsedRule<?> rule, String[] recipes, Str
copyRecipes(recipes, recipeNamespace, datapackPath, ruleName);
int value = (Integer) rule.get();
for (String recipeName : recipes) {
String filePath = datapackPath + recipeNamespace + "/recipes/" + recipeName;
String filePath = datapackPath + recipeNamespace + "/" + COMPAT_RECIPE_FOLDER_NAME + "/" + recipeName;
JsonObject jsonObject = readJson(filePath);
assert jsonObject != null;
jsonObject.getAsJsonObject("result").addProperty("count", value);
Expand All @@ -203,25 +210,25 @@ private static void updateCraftingRule(ParsedRule<?> rule, String[] recipes, Str

private static void writeAdvancement(String datapackPath, String ruleName, String[] recipes) {
copyFile(
"assets/carpetamsaddition/AmsRecipeTweakPack/ams/advancements/recipe_rule.json",
datapackPath + "ams/advancements/" + ruleName + ".json"
"assets/carpetamsaddition/AmsRecipeTweakPack/ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME + "/recipe_rule.json",
datapackPath + "ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME + "/" + ruleName + ".json"
);
JsonObject advancementJson = readJson(datapackPath + "ams/advancements/" + ruleName + ".json");
JsonObject advancementJson = readJson(datapackPath + "ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME + "/" + ruleName + ".json");
if (advancementJson != null) {
JsonArray recipeRewards = advancementJson.getAsJsonObject("rewards").getAsJsonArray("recipes");
for (String recipeName : recipes) {
recipeRewards.add("ams:" + recipeName.replace(".json", ""));
}
writeJson(advancementJson, datapackPath + "ams/advancements/" + ruleName + ".json");
writeJson(advancementJson, datapackPath + "ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME + "/" + ruleName + ".json");
} else {
JsonObject defaultJson = new JsonObject();
writeJson(defaultJson, datapackPath + "ams/advancements/" + ruleName + ".json");
writeJson(defaultJson, datapackPath + "ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME + "/" + ruleName + ".json");
}
}

private static void removeAdvancement(String datapackPath, String ruleName) {
try {
Files.deleteIfExists(new File(datapackPath + "ams/advancements/" + ruleName + ".json").toPath());
Files.deleteIfExists(new File(datapackPath + "ams/" + COMPAT_ADVANCEMENT_FOLDER_NAME + "/" + ruleName + ".json").toPath());
} catch (IOException e) {
AmsServer.LOGGER.error("Failed to delete advancement file: {}.json: {}", ruleName, e.getMessage());
}
Expand Down Expand Up @@ -251,7 +258,7 @@ private static void copyFile(String resourcePath, String targetPath) {
private static void deleteRecipes(String[] recipes, String recipeNamespace, String datapackPath, String ruleName, boolean removeAdvancement) {
for (String recipeName : recipes) {
try {
Files.deleteIfExists(new File(datapackPath + recipeNamespace + "/recipes", recipeName).toPath());
Files.deleteIfExists(new File(datapackPath + recipeNamespace + "/" + COMPAT_RECIPE_FOLDER_NAME, recipeName).toPath());
} catch (IOException e) {
AmsServer.LOGGER.error("Failed to delete recipe file {}: {}", recipeName, e.getMessage());
}
Expand All @@ -264,8 +271,8 @@ private static void deleteRecipes(String[] recipes, String recipeNamespace, Stri
private static void copyRecipes(String[] recipes, String recipeNamespace, String datapackPath, String ruleName) {
for (String recipeName : recipes) {
copyFile(
"assets/carpetamsaddition/AmsRecipeTweakPack/" + recipeNamespace + "/recipes/" + recipeName,
datapackPath + recipeNamespace + "/recipes/" + recipeName
"assets/carpetamsaddition/AmsRecipeTweakPack/" + recipeNamespace + "/" + COMPAT_RECIPE_FOLDER_NAME + "/" + recipeName,
datapackPath + recipeNamespace + "/" + COMPAT_RECIPE_FOLDER_NAME + "/" + recipeName
);
}
if (recipeNamespace.equals("ams")) {
Expand Down Expand Up @@ -299,4 +306,14 @@ private static void writeJson(JsonObject jsonObject, String filePath) {
AmsServer.LOGGER.error("Failed to write JSON to file '{}': {}", filePath, e.getMessage());
}
}

static {
//#if MC>=12100
//$$ COMPAT_ADVANCEMENT_FOLDER_NAME = "advancement";
//$$ COMPAT_RECIPE_FOLDER_NAME = "recipe";
//#else
COMPAT_ADVANCEMENT_FOLDER_NAME = "advancements";
COMPAT_RECIPE_FOLDER_NAME = "recipes";
//#endif
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"parent": "ams:root",
"criteria": {
"tick": {
"trigger": "minecraft:tick"
}
},
"rewards": {
"recipes": [

]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"criteria": {
"tick": {
"trigger": "minecraft:tick"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"pattern":[
"###",
"###",
"###"
],
"key":{
"#":{
"item":"minecraft:bone"
}
},
"result":{
"/*ams_recipes_item_id*/":"minecraft:bone_block",
"count":3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "minecraft:crafting_shaped",
"pattern":[
"SRS",
"R R",
"RRR"
],
"key":{
"S":{
"item":"minecraft:string"
},
"R":{
"item":"minecraft:rabbit_hide"
}
},
"result":{
"/*ams_recipes_item_id*/":"minecraft:bundle",
"count":1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type":"crafting_shapeless",
"ingredients":[
{
"item":"minecraft:bow"
},
{
"item":"minecraft:dropper"
}
],
"result":{
"/*ams_recipes_item_id*/":"minecraft:dispenser",
"count":1
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "minecraft:crafting_shaped",
"pattern":[
" SX",
"SDX",
" SX"
],
"key":{
"D":{
"item":"minecraft:dropper"
},
"S":{
"item":"minecraft:stick"
},
"X":{
"item":"minecraft:string"
}
},
"result":{
"/*ams_recipes_item_id*/":"minecraft:dispenser",
"count":1
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "minecraft:crafting_shaped",
"pattern":[
"PSP",
"P*P",
"PLP"
],
"key":{
"P":{
"item":"minecraft:phantom_membrane"
},
"S":{
"item":"minecraft:stick"
},
"*":{
"item":"minecraft:saddle"
},
"L":{
"item":"minecraft:string"
}
},
"result":{
"/*ams_recipes_item_id*/":"minecraft:elytra",
"count":1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"###",
"#A#",
"###"
],
"key": {
"#": {
"item": "minecraft:gold_block"
},
"A": {
"item": "minecraft:apple"
}
},
"result": {
"/*ams_recipes_item_id*/": "minecraft:enchanted_golden_apple",
"count": 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type":"crafting_shapeless",
"ingredients":[
{
"item":"minecraft:deepslate"
}
],
"result":{
"/*ams_recipes_item_id*/":"minecraft:polished_blackstone_button",
"count":1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "minecraft:crafting_shaped",
"pattern":[
" ",
"RQR",
"DDD"
],
"key":{
"D":{
"item":"minecraft:deepslate"
},
"R":{
"item":"minecraft:redstone"
},
"Q":{
"item":"minecraft:quartz"
}
},
"result":{
"/*ams_recipes_item_id*/":"minecraft:sculk_sensor",
"count":1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 6,
"description": "Carpet AMS addition recipe tweaking pack"
}
}
Loading

0 comments on commit 62e83af

Please sign in to comment.