Skip to content

Commit

Permalink
✅ v2.48.2 -> v2.49.0
Browse files Browse the repository at this point in the history
  • Loading branch information
1024-byteeeee authored Sep 30, 2024
2 parents f246f78 + 5171121 commit 9b22940
Show file tree
Hide file tree
Showing 27 changed files with 780 additions and 116 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loader_version = 0.16.0
# Mod Properties
mod_id = carpet-ams-addition
mod_name = Carpet AMS Addition
mod_version = 2.48.2
mod_version = 2.49.0
maven_group = carpetamsaddition
archives_base_name = Carpet-AMS-Addition

Expand Down
35 changes: 34 additions & 1 deletion src/main/java/club/mcams/carpet/AmsServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
//$$ import carpet.network.ServerNetworkHandler;
//#endif

import club.mcams.carpet.api.recipe.AmsRecipeManager;
import club.mcams.carpet.api.recipe.AmsRecipeBuilder;
import club.mcams.carpet.commands.RegisterCommands;
import club.mcams.carpet.commands.rule.commandPlayerLeader.LeaderCommandRegistry;
import club.mcams.carpet.config.LoadConfigFromJson;
Expand All @@ -41,6 +43,7 @@

import com.google.common.collect.Maps;

import com.google.gson.JsonElement;
import com.mojang.brigadier.CommandDispatcher;

import net.minecraft.server.MinecraftServer;
Expand All @@ -49,6 +52,11 @@
//$$ import net.minecraft.command.CommandRegistryAccess;
//#endif
import net.minecraft.server.network.ServerPlayerEntity;
//#if MC>=12102
//$$ import net.minecraft.recipe.Recipe;
//$$ import net.minecraft.registry.RegistryWrapper;
//#endif
import net.minecraft.util.Identifier;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -65,6 +73,10 @@ public class AmsServer implements CarpetExtension {
public static final Logger LOGGER = LogManager.getLogger(fancyName);
private static final AmsServer INSTANCE = new AmsServer();

public static AmsServer getInstance() {
return INSTANCE;
}

public static void init() {
CarpetServer.manageExtension(INSTANCE);
AMSTranslations.loadTranslations();
Expand All @@ -89,7 +101,6 @@ public void registerLoggers() {
AmsCarpetLoggerRegistry.registerLoggers();
}


@Override
public void registerCommands(
CommandDispatcher<ServerCommandSource> dispatcher
Expand All @@ -105,6 +116,28 @@ public void registerCommands(
);
}

public void registerCustomRecipes(
//#if MC>=12102
//$$ Map<Identifier, Recipe<?>> map, RegistryWrapper.WrapperLookup wrapperLookup
//#else
Map<Identifier, JsonElement> map
//#endif
) {
AmsRecipeBuilder amsRecipeBuilder = AmsRecipeBuilder.getInstance();
AmsRecipeManager amsRecipeManager = new AmsRecipeManager(
amsRecipeBuilder.shapelessRecipeList,
amsRecipeBuilder.shapedRecipeList,
amsRecipeBuilder.smeltingRecipeList
);
AmsRecipeManager.clearRecipeListMemory(amsRecipeBuilder);
amsRecipeBuilder.build();
//#if MC>=12102
//$$ amsRecipeManager.registerRecipes(map, wrapperLookup);
//#else
amsRecipeManager.registerRecipes(map);
//#endif
}

@Override
public void onPlayerLoggedIn(ServerPlayerEntity player) {
//#if MC==12005
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/club/mcams/carpet/AmsServerSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

package club.mcams.carpet;

import club.mcams.carpet.settings.RecipeRule;

import top.byteeeee.annotationtoolbox.annotation.GameVersion;

//#if MC>=12002
Expand All @@ -43,6 +41,7 @@
import club.mcams.carpet.validators.rule.renewableNetherScrap.DropRateValidator;

import club.mcams.carpet.settings.Rule;
import club.mcams.carpet.settings.RecipeRule;

import static carpet.settings.RuleCategory.*;
import static club.mcams.carpet.settings.AmsRuleCategory.*;
Expand Down Expand Up @@ -513,6 +512,15 @@ public class AmsServerSettings {
@Rule(categories = {AMS, FEATURE, SURVIVAL})
public static boolean easyRefreshTrades = false;

@Rule(categories = {AMS, FEATURE, SURVIVAL})
public static boolean jebSheepDropRandomColorWool = false;

@Rule(categories = {AMS, FEATURE, SURVIVAL})
public static boolean cryingObsidianNetherPortal = false;

@Rule(categories = {AMS, FEATURE, SURVIVAL}, strict = false)
public static int furnaceSmeltingTimeController = -1;

/*
* 区块加载规则
*/
Expand Down Expand Up @@ -596,6 +604,10 @@ public class AmsServerSettings {
public static boolean betterCraftablePolishedBlackStoneButton = false;
//#endif

@RecipeRule
@Rule(categories = {AMS, CRAFTING, SURVIVAL}, validators = RecipeRuleObserver.class)
public static boolean rottenFleshBurnedIntoLeather = false;

public enum blueSkullProbability {
VANILLA,
SURELY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,40 @@
import club.mcams.carpet.AmsServerSettings;
import club.mcams.carpet.api.recipe.template.ShapedRecipeTemplate;
import club.mcams.carpet.api.recipe.template.ShapelessRecipeTemplate;
import club.mcams.carpet.api.recipe.template.SmeltingRecipeTemplate;
import club.mcams.carpet.utils.ChainableHashMap;
import club.mcams.carpet.utils.ChainableList;
import club.mcams.carpet.utils.IdentifierUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AmsRecipeRegistry {
public class AmsRecipeBuilder {
private static final String MOD_ID = AmsServer.compactName;
private static final AmsRecipeRegistry instance = new AmsRecipeRegistry();
private static final AmsRecipeBuilder instance = new AmsRecipeBuilder();
public List<ShapedRecipeTemplate> shapedRecipeList = new ArrayList<>();
public List<ShapelessRecipeTemplate> shapelessRecipeList = new ArrayList<>();
public List<SmeltingRecipeTemplate> smeltingRecipeList = new ArrayList<>();

public static AmsRecipeRegistry getInstance() {
public static AmsRecipeBuilder getInstance() {
return instance;
}

public void register() {
// Shaped Recipe List
public void build() {
/*
* 有序合成配方
*/
if (AmsServerSettings.craftableEnchantedGoldenApples) {
String[][] enchantedGoldenApplePattern = {
String[][] notchApplePattern = {
{"#", "#", "#"},
{"#", "A", "#"},
{"#", "#", "#"}
};
Map<Character, String> enchantedGoldenAppleIngredients = new HashMap<>();
enchantedGoldenAppleIngredients.put('#', "minecraft:gold_block");
enchantedGoldenAppleIngredients.put('A', "minecraft:apple");
ChainableHashMap<Character, String> notchAppleIngredients = new ChainableHashMap<>();
notchAppleIngredients.cPut('#', "minecraft:gold_block").cPut('A', "minecraft:apple");
shapedRecipeList.add(new ShapedRecipeTemplate(
IdentifierUtil.of(MOD_ID, "enchanted_golden_apple"),
enchantedGoldenApplePattern,
enchantedGoldenAppleIngredients,
"minecraft:enchanted_golden_apple",
1
notchApplePattern, notchAppleIngredients, "minecraft:enchanted_golden_apple", 1
));
}

Expand All @@ -67,14 +67,11 @@ public void register() {
{"#", "#", "#"},
{"#", "#", "#"}
};
Map<Character, String> boneBlockIngredients = new HashMap<>();
boneBlockIngredients.put('#', "minecraft:bone");
ChainableHashMap<Character, String> boneBlockIngredients = new ChainableHashMap<>();
boneBlockIngredients.cPut('#', "minecraft:bone");
shapedRecipeList.add(new ShapedRecipeTemplate(
IdentifierUtil.of(MOD_ID, "bone_block"),
bonePattern,
boneBlockIngredients,
"minecraft:bone_block",
3
bonePattern, boneBlockIngredients, "minecraft:bone_block", 3
));
}

Expand All @@ -84,16 +81,11 @@ public void register() {
{"S", "D", "X"},
{" ", "S", "X"}
};
Map<Character, String> dispenserIngredients = new HashMap<>();
dispenserIngredients.put('D', "minecraft:dropper");
dispenserIngredients.put('S', "minecraft:stick");
dispenserIngredients.put('X', "minecraft:string");
ChainableHashMap<Character, String> dispenserIngredients = new ChainableHashMap<>();
dispenserIngredients.cPut('D', "minecraft:dropper").cPut('S', "minecraft:stick").cPut('X', "minecraft:string");
shapedRecipeList.add(new ShapedRecipeTemplate(
IdentifierUtil.of(MOD_ID, "dispenser1"),
dispenserPattern,
dispenserIngredients,
"minecraft:dispenser",
1
dispenserPattern, dispenserIngredients, "minecraft:dispenser", 1
));
}

Expand All @@ -103,17 +95,11 @@ public void register() {
{"P", "*", "P"},
{"P", "L", "P"}
};
Map<Character, String> elytraIngredients = new HashMap<>();
elytraIngredients.put('P', "minecraft:phantom_membrane");
elytraIngredients.put('S', "minecraft:stick");
elytraIngredients.put('*', "minecraft:saddle");
elytraIngredients.put('L', "minecraft:string");
ChainableHashMap<Character, String> elytraIngredients = new ChainableHashMap<>();
elytraIngredients.cPut('P', "minecraft:phantom_membrane").cPut('S', "minecraft:stick").cPut('*', "minecraft:saddle").cPut('L', "minecraft:string");
shapedRecipeList.add(new ShapedRecipeTemplate(
IdentifierUtil.of(MOD_ID, "elytra"),
elytraPattern,
elytraIngredients,
"minecraft:elytra",
1
elytraPattern, elytraIngredients, "minecraft:elytra", 1
));
}

Expand All @@ -124,61 +110,60 @@ public void register() {
{"R", "Q", "R"},
{"D", "D", "D"}
};
Map<Character, String> sculkSensorIngredients = new HashMap<>();
sculkSensorIngredients.put('D', "minecraft:deepslate");
sculkSensorIngredients.put('R', "minecraft:redstone");
sculkSensorIngredients.put('Q', "minecraft:quartz");
ChainableHashMap<Character, String> sculkSensorIngredients = new ChainableHashMap<>();
sculkSensorIngredients.cPut('D', "minecraft:deepslate").cPut('R', "minecraft:redstone").cPut('Q', "minecraft:quartz");
shapedRecipeList.add(new ShapedRecipeTemplate(
IdentifierUtil.of(MOD_ID, "sculk_sensor"),
sculkSensorPattern,
sculkSensorIngredients,
"minecraft:sculk_sensor",
1
sculkSensorPattern, sculkSensorIngredients, "minecraft:sculk_sensor", 1
));
}
//#endif

// Shapeless Recipe List
/*
* 无序合成配方
*/
if (AmsServerSettings.betterCraftableDispenser) {
List<String> dispenserIngredients = List.of(
"minecraft:bow",
"minecraft:dropper"
);
ChainableList<String> dispenserIngredients = new ChainableList<>();
dispenserIngredients.cAdd("minecraft:bow").cAdd("minecraft:dropper");
shapelessRecipeList.add(new ShapelessRecipeTemplate(
IdentifierUtil.of(MOD_ID, "dispenser2"),
dispenserIngredients,
"minecraft:dispenser",
1
dispenserIngredients, "minecraft:dispenser", 1
));
}

//#if MC>=11700 && MC<12102
if (AmsServerSettings.craftableBundle) {
List<String> bundleIngredients = List.of(
"minecraft:string",
"minecraft:leather"
);
ChainableList<String> bundleIngredients = new ChainableList<>();
bundleIngredients.cAdd("minecraft:string").cAdd("minecraft:leather");
shapelessRecipeList.add(new ShapelessRecipeTemplate(
IdentifierUtil.of(MOD_ID, "bundle"),
bundleIngredients,
"minecraft:bundle",
1
bundleIngredients, "minecraft:bundle", 1
));
}
//#endif

//#if MC>=11700
if (AmsServerSettings.betterCraftablePolishedBlackStoneButton) {
List<String> polishedBlackstoneButtonIngredients = List.of(
"minecraft:deepslate"
);
ChainableList<String> polishedBlackstoneButtonIngredients = new ChainableList<>();
polishedBlackstoneButtonIngredients.cAdd("minecraft:deepslate");
shapelessRecipeList.add(new ShapelessRecipeTemplate(
IdentifierUtil.of(MOD_ID, "polished_blackstone_button"),
polishedBlackstoneButtonIngredients,
"minecraft:polished_blackstone_button",
1
polishedBlackstoneButtonIngredients, "minecraft:polished_blackstone_button", 1
));
}
//#endif

/*
* 熔炉烧炼配方
*/
if (AmsServerSettings.rottenFleshBurnedIntoLeather) {
smeltingRecipeList.add(
new SmeltingRecipeTemplate(
IdentifierUtil.of(MOD_ID, "leather"),
"minecraft:rotten_flesh", "minecraft:leather",
0.1F, 50
)
);
}
}
}
27 changes: 13 additions & 14 deletions src/main/java/club/mcams/carpet/api/recipe/AmsRecipeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import club.mcams.carpet.api.recipe.template.ShapedRecipeTemplate;
import club.mcams.carpet.api.recipe.template.ShapelessRecipeTemplate;
import club.mcams.carpet.api.recipe.template.SmeltingRecipeTemplate;

import com.google.gson.JsonElement;
//#if MC>=12102
Expand All @@ -41,10 +42,12 @@
public class AmsRecipeManager {
private final List<ShapelessRecipeTemplate> shapelessRecipes;
private final List<ShapedRecipeTemplate> shapedRecipes;
private final List<SmeltingRecipeTemplate> smeltingRecipes;

public AmsRecipeManager(List<ShapelessRecipeTemplate> shapelessRecipes, List<ShapedRecipeTemplate> shapedRecipes) {
public AmsRecipeManager(List<ShapelessRecipeTemplate> shapelessRecipes, List<ShapedRecipeTemplate> shapedRecipes, List<SmeltingRecipeTemplate> smeltingRecipes) {
this.shapelessRecipes = shapelessRecipes;
this.shapedRecipes = shapedRecipes;
this.smeltingRecipes = smeltingRecipes;
}

public void registerRecipes(
Expand All @@ -57,28 +60,24 @@ public void registerRecipes(
//#if MC>=12102
//$$ Map<Identifier, JsonElement> recipeMap = new HashMap<>();
//#endif
for (ShapelessRecipeTemplate recipe : shapelessRecipes) {
recipe.addToRecipeMap(recipeMap);
}
for (ShapedRecipeTemplate recipe : shapedRecipes) {
recipe.addToRecipeMap(recipeMap);
}
shapelessRecipes.forEach(recipe -> recipe.addToRecipeMap(recipeMap));
shapedRecipes.forEach(recipe -> recipe.addToRecipeMap(recipeMap));
smeltingRecipes.forEach(recipe -> recipe.addToRecipeMap(recipeMap));
//#if MC>=12102
//$$ for (Map.Entry<Identifier, JsonElement> entry : recipeMap.entrySet()) {
//$$ Identifier id = entry.getKey();
//$$ JsonElement json = entry.getValue();
//$$ recipeMap.forEach((id, json) -> {
//$$ try {
//$$ RecipeEntry<?> recipeEntry = RecipeManager.deserialize(id, json.getAsJsonObject(), wrapperLookup);
//$$ map.put(id, recipeEntry.value());
//$$ } catch (JsonParseException e) {
//$$ AmsServer.LOGGER.warn("Failed to parse recipe: {}", id);
//$$ }
//$$ }
//$$ });
//#endif
}

public static void clearRecipeListMemory(AmsRecipeRegistry amsRecipeRegistry) {
amsRecipeRegistry.shapedRecipeList.clear();
amsRecipeRegistry.shapelessRecipeList.clear();
public static void clearRecipeListMemory(AmsRecipeBuilder amsRecipeBuilder) {
amsRecipeBuilder.shapedRecipeList.clear();
amsRecipeBuilder.shapelessRecipeList.clear();
amsRecipeBuilder.smeltingRecipeList.clear();
}
}
Loading

0 comments on commit 9b22940

Please sign in to comment.