diff --git a/src/main/java/club/mcams/carpet/AmsServer.java b/src/main/java/club/mcams/carpet/AmsServer.java index 46c80aea..036a2113 100644 --- a/src/main/java/club/mcams/carpet/AmsServer.java +++ b/src/main/java/club/mcams/carpet/AmsServer.java @@ -1,397 +1,397 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - - -package club.mcams.carpet; - -import carpet.CarpetExtension; -import carpet.CarpetServer; -//#if MC>=11900 -//$$ import carpet.api.settings.CarpetRule; -//$$ import carpet.api.settings.RuleHelper; -//$$ import carpet.script.Module; -//#else -import carpet.settings.ParsedRule; -import carpet.script.bundled.BundledModule; -//#endif - -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 net.minecraft.resource.ResourcePackManager; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.ReloadCommand; -import net.minecraft.util.WorldSavePath; -//#if MC>=11900 -//$$ import net.minecraft.command.CommandRegistryAccess; -//#endif - -import org.apache.commons.io.FileUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.*; -import java.lang.reflect.Field; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; - -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 compactName = name.replace("-",""); // carpetamsaddition - public static final Logger LOGGER = LogManager.getLogger(fancyName); - - @Override - public Map canHasTranslations(String lang) { - Map 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; - } - - @Override - public String version() { - return AmsServerMod.getModId(); - } - public static void init() { - CarpetServer.manageExtension(INSTANCE); - AMSTranslations.loadTranslations(); - } - - @Override - public void onGameStarted() { - // let's /carpet handle our few simple settings - 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 - public void onServerLoaded(MinecraftServer server) { - minecraftServer = server; - } - - @Override - public void onServerClosed(MinecraftServer server) { - File datapackPath = new File(server.getSavePath(WorldSavePath.DATAPACKS).toString() + "/AmsData/data/"); - if (Files.isDirectory(datapackPath.toPath())) { - try { - FileUtils.deleteDirectory(datapackPath); - } catch (IOException e) { - Logging.logStackTrace(e); - } - } - } - - /** - * From Rug Mod - */ - @Override - public void onServerLoadedWorlds(MinecraftServer server) { - String datapackPath = server.getSavePath(WorldSavePath.DATAPACKS).toString(); - if (Files.isDirectory(new File(datapackPath + "/Ams_flexibleData/").toPath())) { - try { - FileUtils.deleteDirectory(new File(datapackPath + "/Ams_flexibleData/")); - } catch (IOException e) { - Logging.logStackTrace(e); - } - } - 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()); - copyFile("assets/carpetamsaddition/AmsRecipeTweakPack/pack.mcmeta", datapackPath + "pack.mcmeta"); - } catch (IOException e) { - Logging.logStackTrace(e); - } - - copyFile( - "assets/carpetamsaddition/AmsRecipeTweakPack/ams/advancements/root.json", - datapackPath + "data/ams/advancements/root.json" - ); - - for (Field f : AmsServerSettings.class.getDeclaredFields()) { - CraftingRule craftingRule = f.getAnnotation(CraftingRule.class); - if (craftingRule == null) continue; - registerCraftingRule( - craftingRule.name().isEmpty() ? f.getName() : craftingRule.name(), - craftingRule.recipes(), - craftingRule.recipeNamespace(), - datapackPath + "data/" - ); - } - reload(); - if (isFirstLoad) { - //#if MC>=11900 - //$$server.getCommandManager().executeWithPrefix(server.getCommandSource(), "/datapack enable \"file/AmsData\""); - //#else - server.getCommandManager().execute(server.getCommandSource(), "/datapack enable \"file/AmsData\""); - //#endif - } - } - - 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 - }); - } - - private void updateCraftingRule( - ParsedRule rule, - String[] recipes, - String recipeNamespace, - String datapackPath, - String ruleName - ) { - ruleName = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, ruleName); - //#if MC>=11900 - //$$if (rule.type() == String.class) { - //$$String value = RuleHelper.toRuleString(rule.value()); - //#else - if (rule.type == String.class) { - String value = rule.getAsString(); - //#endif - List installedRecipes = Lists.newArrayList(); - try { - Stream fileStream = Files.list(new File(datapackPath + recipeNamespace, "recipes").toPath()); - fileStream.forEach(( path -> { - for (String recipeName : recipes) { - String fileName = path.getFileName().toString(); - if (fileName.startsWith(recipeName)) { - installedRecipes.add(fileName); - } - } - } )); - fileStream.close(); - } catch (IOException e) { - Logging.logStackTrace(e); - } - - deleteRecipes(installedRecipes.toArray(new String[0]), recipeNamespace, datapackPath, ruleName, false); - - if (recipeNamespace.equals("ams")) { - List installedAdvancements = Lists.newArrayList(); - try { - Stream fileStream = Files.list(new File(datapackPath, "ams/advancements").toPath()); - String finalRuleName = ruleName; - fileStream.forEach(( path -> { - String fileName = path.getFileName().toString().replace(".json", ""); - if (fileName.startsWith(finalRuleName)) { - installedAdvancements.add(fileName); - } - } )); - fileStream.close(); - } catch (IOException e) { - Logging.logStackTrace(e); - } - for (String advancement : installedAdvancements.toArray(new String[0])) { - removeAdvancement(datapackPath, advancement); - } - } - - if (!value.equals("off")) { - List tempRecipes = Lists.newArrayList(); - for (String recipeName : recipes) { - tempRecipes.add(recipeName + "_" + value + ".json"); - } - - copyRecipes(tempRecipes.toArray(new String[0]), recipeNamespace, datapackPath, ruleName + "_" + value); - } - } - //#if MC>=11900 - //$$else if (rule.type() == Integer.class && (Integer) rule.value() > 0) { - //#else - else if (rule.type == int.class && (Integer) rule.get() > 0) { - //#endif - copyRecipes(recipes, recipeNamespace, datapackPath, ruleName); - int value = (Integer) rule.get(); - for (String recipeName : recipes) { - String filePath = datapackPath + recipeNamespace + "/recipes/" + recipeName; - JsonObject jsonObject = readJson(filePath); - assert jsonObject != null; - jsonObject.getAsJsonObject("result").addProperty("count", value); - writeJson(jsonObject, filePath); - } - } - //#if MC>=11900 - //$$else if (rule.type() == Boolean.class && RuleHelper.getBooleanValue(rule)) { - //#else - else if (rule.type == boolean.class && rule.getBoolValue()) { - //#endif - copyRecipes(recipes, recipeNamespace, datapackPath, ruleName); - } else { - deleteRecipes(recipes, recipeNamespace, datapackPath, ruleName, true); - } - } - - private 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 - ); - } - if (recipeNamespace.equals("ams")) { - writeAdvancement(datapackPath, ruleName, recipes); - } - } - - private 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()); - } catch (IOException e) { - Logging.logStackTrace(e); - } - } - if (removeAdvancement && recipeNamespace.equals("ams")) { - removeAdvancement(datapackPath, ruleName); - } - } - - private void writeAdvancement(String datapackPath, String ruleName, String[] recipes) { - copyFile( - "assets/carpetamsaddition/AmsRecipeTweakPack/ams/advancements/recipe_rule.json", - datapackPath + "ams/advancements/" + ruleName + ".json" - ); - - JsonObject advancementJson = readJson(datapackPath + "ams/advancements/" + ruleName + ".json"); - assert 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"); - } - - private void removeAdvancement(String datapackPath, String ruleName) { - try { - Files.deleteIfExists(new File(datapackPath + "ams/advancements/" + ruleName + ".json").toPath()); - } catch (IOException e) { - Logging.logStackTrace(e); - } - } - - private void reload() { - ResourcePackManager resourcePackManager = minecraftServer.getDataPackManager(); - resourcePackManager.scanPacks(); - Collection collection = Lists.newArrayList(resourcePackManager.getEnabledNames()); - collection.add("AmsData"); - - ReloadCommand.tryReloadDataPacks(collection, minecraftServer.getCommandSource()); - } - - private void copyFile(String resourcePath, String targetPath) { - InputStream source = BundledModule.class.getClassLoader().getResourceAsStream(resourcePath); - Path target = new File(targetPath).toPath(); - - try { - assert source != null; - Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - Logging.logStackTrace(e); - } catch (NullPointerException e) { - LOGGER.error("Resource '" + resourcePath + "' is null:"); - 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); - } - } +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + + +package club.mcams.carpet; + +import carpet.CarpetExtension; +import carpet.CarpetServer; +//#if MC>=11900 +//$$ import carpet.api.settings.CarpetRule; +//$$ import carpet.api.settings.RuleHelper; +//$$ import carpet.script.Module; +//#else +import carpet.settings.ParsedRule; +import carpet.script.bundled.BundledModule; +//#endif + +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 net.minecraft.resource.ResourcePackManager; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.command.ReloadCommand; +import net.minecraft.util.WorldSavePath; +//#if MC>=11900 +//$$ import net.minecraft.command.CommandRegistryAccess; +//#endif + +import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.*; +import java.lang.reflect.Field; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +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 compactName = name.replace("-",""); // carpetamsaddition + public static final Logger LOGGER = LogManager.getLogger(fancyName); + + @Override + public Map canHasTranslations(String lang) { + Map 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; + } + + @Override + public String version() { + return AmsServerMod.getModId(); + } + public static void init() { + CarpetServer.manageExtension(INSTANCE); + AMSTranslations.loadTranslations(); + } + + @Override + public void onGameStarted() { + // let's /carpet handle our few simple settings + 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 + public void onServerLoaded(MinecraftServer server) { + minecraftServer = server; + } + + @Override + public void onServerClosed(MinecraftServer server) { + File datapackPath = new File(server.getSavePath(WorldSavePath.DATAPACKS).toString() + "/AmsData/data/"); + if (Files.isDirectory(datapackPath.toPath())) { + try { + FileUtils.deleteDirectory(datapackPath); + } catch (IOException e) { + Logging.logStackTrace(e); + } + } + } + + /** + * From Rug Mod + */ + @Override + public void onServerLoadedWorlds(MinecraftServer server) { + String datapackPath = server.getSavePath(WorldSavePath.DATAPACKS).toString(); + if (Files.isDirectory(new File(datapackPath + "/Ams_flexibleData/").toPath())) { + try { + FileUtils.deleteDirectory(new File(datapackPath + "/Ams_flexibleData/")); + } catch (IOException e) { + Logging.logStackTrace(e); + } + } + 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()); + copyFile("assets/carpetamsaddition/AmsRecipeTweakPack/pack.mcmeta", datapackPath + "pack.mcmeta"); + } catch (IOException e) { + Logging.logStackTrace(e); + } + + copyFile( + "assets/carpetamsaddition/AmsRecipeTweakPack/ams/advancements/root.json", + datapackPath + "data/ams/advancements/root.json" + ); + + for (Field f : AmsServerSettings.class.getDeclaredFields()) { + CraftingRule craftingRule = f.getAnnotation(CraftingRule.class); + if (craftingRule == null) continue; + registerCraftingRule( + craftingRule.name().isEmpty() ? f.getName() : craftingRule.name(), + craftingRule.recipes(), + craftingRule.recipeNamespace(), + datapackPath + "data/" + ); + } + reload(); + if (isFirstLoad) { + //#if MC>=11900 + //$$server.getCommandManager().executeWithPrefix(server.getCommandSource(), "/datapack enable \"file/AmsData\""); + //#else + server.getCommandManager().execute(server.getCommandSource(), "/datapack enable \"file/AmsData\""); + //#endif + } + } + + 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 + }); + } + + private void updateCraftingRule( + ParsedRule rule, + String[] recipes, + String recipeNamespace, + String datapackPath, + String ruleName + ) { + ruleName = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, ruleName); + //#if MC>=11900 + //$$if (rule.type() == String.class) { + //$$String value = RuleHelper.toRuleString(rule.value()); + //#else + if (rule.type == String.class) { + String value = rule.getAsString(); + //#endif + List installedRecipes = Lists.newArrayList(); + try { + Stream fileStream = Files.list(new File(datapackPath + recipeNamespace, "recipes").toPath()); + fileStream.forEach(( path -> { + for (String recipeName : recipes) { + String fileName = path.getFileName().toString(); + if (fileName.startsWith(recipeName)) { + installedRecipes.add(fileName); + } + } + } )); + fileStream.close(); + } catch (IOException e) { + Logging.logStackTrace(e); + } + + deleteRecipes(installedRecipes.toArray(new String[0]), recipeNamespace, datapackPath, ruleName, false); + + if (recipeNamespace.equals("ams")) { + List installedAdvancements = Lists.newArrayList(); + try { + Stream fileStream = Files.list(new File(datapackPath, "ams/advancements").toPath()); + String finalRuleName = ruleName; + fileStream.forEach(( path -> { + String fileName = path.getFileName().toString().replace(".json", ""); + if (fileName.startsWith(finalRuleName)) { + installedAdvancements.add(fileName); + } + } )); + fileStream.close(); + } catch (IOException e) { + Logging.logStackTrace(e); + } + for (String advancement : installedAdvancements.toArray(new String[0])) { + removeAdvancement(datapackPath, advancement); + } + } + + if (!value.equals("off")) { + List tempRecipes = Lists.newArrayList(); + for (String recipeName : recipes) { + tempRecipes.add(recipeName + "_" + value + ".json"); + } + + copyRecipes(tempRecipes.toArray(new String[0]), recipeNamespace, datapackPath, ruleName + "_" + value); + } + } + //#if MC>=11900 + //$$else if (rule.type() == Integer.class && (Integer) rule.value() > 0) { + //#else + else if (rule.type == int.class && (Integer) rule.get() > 0) { + //#endif + copyRecipes(recipes, recipeNamespace, datapackPath, ruleName); + int value = (Integer) rule.get(); + for (String recipeName : recipes) { + String filePath = datapackPath + recipeNamespace + "/recipes/" + recipeName; + JsonObject jsonObject = readJson(filePath); + assert jsonObject != null; + jsonObject.getAsJsonObject("result").addProperty("count", value); + writeJson(jsonObject, filePath); + } + } + //#if MC>=11900 + //$$else if (rule.type() == Boolean.class && RuleHelper.getBooleanValue(rule)) { + //#else + else if (rule.type == boolean.class && rule.getBoolValue()) { + //#endif + copyRecipes(recipes, recipeNamespace, datapackPath, ruleName); + } else { + deleteRecipes(recipes, recipeNamespace, datapackPath, ruleName, true); + } + } + + private 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 + ); + } + if (recipeNamespace.equals("ams")) { + writeAdvancement(datapackPath, ruleName, recipes); + } + } + + private 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()); + } catch (IOException e) { + Logging.logStackTrace(e); + } + } + if (removeAdvancement && recipeNamespace.equals("ams")) { + removeAdvancement(datapackPath, ruleName); + } + } + + private void writeAdvancement(String datapackPath, String ruleName, String[] recipes) { + copyFile( + "assets/carpetamsaddition/AmsRecipeTweakPack/ams/advancements/recipe_rule.json", + datapackPath + "ams/advancements/" + ruleName + ".json" + ); + + JsonObject advancementJson = readJson(datapackPath + "ams/advancements/" + ruleName + ".json"); + assert 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"); + } + + private void removeAdvancement(String datapackPath, String ruleName) { + try { + Files.deleteIfExists(new File(datapackPath + "ams/advancements/" + ruleName + ".json").toPath()); + } catch (IOException e) { + Logging.logStackTrace(e); + } + } + + private void reload() { + ResourcePackManager resourcePackManager = minecraftServer.getDataPackManager(); + resourcePackManager.scanPacks(); + Collection collection = Lists.newArrayList(resourcePackManager.getEnabledNames()); + collection.add("AmsData"); + + ReloadCommand.tryReloadDataPacks(collection, minecraftServer.getCommandSource()); + } + + private void copyFile(String resourcePath, String targetPath) { + InputStream source = BundledModule.class.getClassLoader().getResourceAsStream(resourcePath); + Path target = new File(targetPath).toPath(); + + try { + assert source != null; + Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + Logging.logStackTrace(e); + } catch (NullPointerException e) { + LOGGER.error("Resource '" + resourcePath + "' is null:"); + 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); + } + } } \ No newline at end of file diff --git a/src/main/java/club/mcams/carpet/AmsServerMod.java b/src/main/java/club/mcams/carpet/AmsServerMod.java index d136ce1c..59d652fe 100644 --- a/src/main/java/club/mcams/carpet/AmsServerMod.java +++ b/src/main/java/club/mcams/carpet/AmsServerMod.java @@ -1,48 +1,48 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet; - -import club.mcams.carpet.util.AutoMixinAuditExecutor.AutoMixinAuditExecutor; - -import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; - -public class AmsServerMod implements ModInitializer { - - private static final String MOD_ID = "carpet-ams-addition"; - private static String version; - - @Override - public void onInitialize() { - version = FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow(RuntimeException::new).getMetadata().getVersion().getFriendlyString(); - AutoMixinAuditExecutor.run(); - AmsServer.init(); - } - public static String getModId() - { - return MOD_ID; - } - - public static String getVersion() - { - return version; - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet; + +import club.mcams.carpet.util.AutoMixinAuditExecutor.AutoMixinAuditExecutor; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.FabricLoader; + +public class AmsServerMod implements ModInitializer { + + private static final String MOD_ID = "carpet-ams-addition"; + private static String version; + + @Override + public void onInitialize() { + version = FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow(RuntimeException::new).getMetadata().getVersion().getFriendlyString(); + AutoMixinAuditExecutor.run(); + AmsServer.init(); + } + public static String getModId() + { + return MOD_ID; + } + + public static String getVersion() + { + return version; + } +} diff --git a/src/main/java/club/mcams/carpet/AmsServerSettings.java b/src/main/java/club/mcams/carpet/AmsServerSettings.java index 856d8dfb..9162cb8c 100644 --- a/src/main/java/club/mcams/carpet/AmsServerSettings.java +++ b/src/main/java/club/mcams/carpet/AmsServerSettings.java @@ -1,250 +1,250 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet; - -import club.mcams.carpet.util.recipes.CraftingRule; -import club.mcams.carpet.settings.Rule; -import static club.mcams.carpet.settings.AmsRuleCategory.*; - -/** - * Here is your example Settings class you can plug to use carpetmod /carpet settings command - */ - -public class AmsServerSettings { - - @Rule(categories = {AMS, FEATURE}) - public static boolean superBow = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean scheduledRandomTickCactus = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean scheduledRandomTickBamboo = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean scheduledRandomTickChorusFlower = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean scheduledRandomTickSugarCane = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean scheduledRandomTickStem = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean scheduledRandomTickAllPlants = false; - - @Rule(categories = {AMS, OPTIMIZATION}) - public static boolean optimizedDragonRespawn = false; - - @Rule( - options = {"bone_block", "wither_skeleton_skull", "note_block", "OFF"}, - categories = {AMS, FEATURE, AMS_CHUNKLOADER} - ) - public static String noteBlockChunkLoader = "OFF"; - - @Rule( - options = {"bone_block", "bedrock", "all", "OFF"}, - categories = {AMS, FEATURE, AMS_CHUNKLOADER} - ) - public static String pistonBlockChunkLoader = "OFF"; - - @Rule(categories = {AMS, FEATURE, AMS_CHUNKLOADER}) - public static boolean bellBlockChunkLoader = false; - - @Rule(categories = {AMS, COMMAND, AMS_CHUNKLOADER}) - public static String commandChunkLoading = "false"; - - @Rule(categories = {AMS, FEATURE}) - public static boolean netherWaterPlacement = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean softDeepslate = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean softObsidian = false; - - @Rule(categories = {AMS, FEATURE, TNT}) - public static boolean blowUpEverything = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean sharedVillagerDiscounts = false; - - @Rule(categories = {AMS, FEATURE}) - public static boolean fakePeace = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean extinguishedCampfire = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean safeFlight = false; - - //#if MC<11900 - @Rule(categories = {AMS, FEATURE}) - public static boolean boneBlockUpdateSuppressor = false; - //#endif - - @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) - public static boolean weakObsidian = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) - public static boolean weakCryingObsidian = false; - - //#if MC>=11900 - @SuppressWarnings("unused") - @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) - public static boolean weakReinforcedDeepslate = false; - //#endif - - @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) - public static boolean weakBedRock = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) - public static boolean enhancedWorldEater = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean infiniteTrades = false; - - @Rule(categories = {AMS, FEATURE}) - public static boolean invulnerable = false; - - @Rule(categories = {AMS, FEATURE, CREATIVE}) - public static boolean creativeOneHitKill = false; - - @Rule(categories = {AMS, FEATURE, SURVIVAL}) - public static boolean largeEnderChest = false; - - @Rule(categories = {AMS, FEATURE, OPTIMIZATION}) - public static boolean bambooModelNoOffset = false; - - @Rule(categories = {AMS, FEATURE}) - public static boolean bambooCollisionBoxDisabled = false; - - @Rule(categories = {AMS, FEATURE}) - public static boolean campfireSmokeParticleDisabled = false; - - @Rule(categories = {AMS, FEATURE}) - public static boolean antiFireTotem = false; - - @Rule(categories = {AMS, FEATURE, TNT}) - public static boolean itemAntiExplosion = false; - - @Rule(categories = {AMS, FEATURE, CREATIVE}) - public static boolean creativeShulkerBoxDropsDisable = false; - - // 可移动方块规则 - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableEnderChest = false; - - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableEndPortalFrame = false; - - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableObsidian = false; - - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableCryingObsidian = false; - - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableBedRock = false; - - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableEnchantingTable = false; - - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableBeacon = false; - - //#if MC>=11900 - @SuppressWarnings("unused") - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableReinforcedDeepslate = false; - //#endif - - //#if MC>=11900 - @SuppressWarnings("unused") - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableSculkCatalyst = false; - //#endif - - //#if MC>=11900 - @SuppressWarnings("unused") - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableSculkSensor = false; - //#endif - - //#if MC>=11900 - @SuppressWarnings("unused") - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableSculkShrieker = false; - //#endif - - //#if MC>=12000 - @SuppressWarnings("unused") - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableCalibratedSculkSensor = false; - //#endif - - @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) - public static boolean movableAnvil = false; - - /** - * 合成表规�? - */ - @SuppressWarnings("unused") - @CraftingRule(recipes = "enchanted_golden_apples.json") - @Rule(categories = {AMS, CRAFTING, SURVIVAL}) - public static boolean craftableEnchantedGoldenApples = false; - - //#if MC>=11700 - @SuppressWarnings("unused") - @CraftingRule(recipes = "bundle.json") - @Rule(categories = {AMS, CRAFTING, SURVIVAL}) - public static boolean craftableBundle = false; - //#endif - - //#if MC<11900 && MC>=11700 - @SuppressWarnings("unused") - @CraftingRule(recipes = "sculk_sensor.json") - @Rule(categories = {AMS, CRAFTING, SURVIVAL}) - public static boolean craftableSculkSensor = false; - //#endif - - @SuppressWarnings("unused") - @CraftingRule(recipes = "bone_block.json") - @Rule(categories = {AMS, CRAFTING, SURVIVAL}) - public static boolean betterCraftableBoneBlock = false; - - @SuppressWarnings("unused") - @CraftingRule(recipes = "elytra.json") - @Rule(categories = {AMS, CRAFTING, SURVIVAL}) - public static boolean craftableElytra = false; - - @SuppressWarnings("unused") - @CraftingRule(recipes = {"dispenser1.json", "dispenser2.json"}) - @Rule(categories = {AMS, CRAFTING, SURVIVAL}) - public static boolean betterCraftableDispenser = false; - - //#if MC>=11700 - @SuppressWarnings("unused") - @CraftingRule(recipes = "polished_blackstone_button.json") - @Rule(categories = {AMS, CRAFTING, SURVIVAL}) - public static boolean betterCraftablePolishedBlackStoneButton = false; - //#endif -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet; + +import club.mcams.carpet.util.recipes.CraftingRule; +import club.mcams.carpet.settings.Rule; +import static club.mcams.carpet.settings.AmsRuleCategory.*; + +/** + * Here is your example Settings class you can plug to use carpetmod /carpet settings command + */ + +public class AmsServerSettings { + + @Rule(categories = {AMS, FEATURE}) + public static boolean superBow = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean scheduledRandomTickCactus = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean scheduledRandomTickBamboo = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean scheduledRandomTickChorusFlower = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean scheduledRandomTickSugarCane = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean scheduledRandomTickStem = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean scheduledRandomTickAllPlants = false; + + @Rule(categories = {AMS, OPTIMIZATION}) + public static boolean optimizedDragonRespawn = false; + + @Rule( + options = {"bone_block", "wither_skeleton_skull", "note_block", "OFF"}, + categories = {AMS, FEATURE, AMS_CHUNKLOADER} + ) + public static String noteBlockChunkLoader = "OFF"; + + @Rule( + options = {"bone_block", "bedrock", "all", "OFF"}, + categories = {AMS, FEATURE, AMS_CHUNKLOADER} + ) + public static String pistonBlockChunkLoader = "OFF"; + + @Rule(categories = {AMS, FEATURE, AMS_CHUNKLOADER}) + public static boolean bellBlockChunkLoader = false; + + @Rule(categories = {AMS, COMMAND, AMS_CHUNKLOADER}) + public static String commandChunkLoading = "false"; + + @Rule(categories = {AMS, FEATURE}) + public static boolean netherWaterPlacement = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean softDeepslate = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean softObsidian = false; + + @Rule(categories = {AMS, FEATURE, TNT}) + public static boolean blowUpEverything = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean sharedVillagerDiscounts = false; + + @Rule(categories = {AMS, FEATURE}) + public static boolean fakePeace = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean extinguishedCampfire = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean safeFlight = false; + + //#if MC<11900 + @Rule(categories = {AMS, FEATURE}) + public static boolean boneBlockUpdateSuppressor = false; + //#endif + + @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) + public static boolean weakObsidian = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) + public static boolean weakCryingObsidian = false; + + //#if MC>=11900 + @SuppressWarnings("unused") + @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) + public static boolean weakReinforcedDeepslate = false; + //#endif + + @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) + public static boolean weakBedRock = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL, TNT}) + public static boolean enhancedWorldEater = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean infiniteTrades = false; + + @Rule(categories = {AMS, FEATURE}) + public static boolean invulnerable = false; + + @Rule(categories = {AMS, FEATURE, CREATIVE}) + public static boolean creativeOneHitKill = false; + + @Rule(categories = {AMS, FEATURE, SURVIVAL}) + public static boolean largeEnderChest = false; + + @Rule(categories = {AMS, FEATURE, OPTIMIZATION}) + public static boolean bambooModelNoOffset = false; + + @Rule(categories = {AMS, FEATURE}) + public static boolean bambooCollisionBoxDisabled = false; + + @Rule(categories = {AMS, FEATURE}) + public static boolean campfireSmokeParticleDisabled = false; + + @Rule(categories = {AMS, FEATURE}) + public static boolean antiFireTotem = false; + + @Rule(categories = {AMS, FEATURE, TNT}) + public static boolean itemAntiExplosion = false; + + @Rule(categories = {AMS, FEATURE, CREATIVE}) + public static boolean creativeShulkerBoxDropsDisable = false; + + // 可移动方块规则 + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableEnderChest = false; + + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableEndPortalFrame = false; + + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableObsidian = false; + + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableCryingObsidian = false; + + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableBedRock = false; + + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableEnchantingTable = false; + + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableBeacon = false; + + //#if MC>=11900 + @SuppressWarnings("unused") + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableReinforcedDeepslate = false; + //#endif + + //#if MC>=11900 + @SuppressWarnings("unused") + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableSculkCatalyst = false; + //#endif + + //#if MC>=11900 + @SuppressWarnings("unused") + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableSculkSensor = false; + //#endif + + //#if MC>=11900 + @SuppressWarnings("unused") + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableSculkShrieker = false; + //#endif + + //#if MC>=12000 + @SuppressWarnings("unused") + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableCalibratedSculkSensor = false; + //#endif + + @Rule(categories = {AMS, FEATURE, AMS_MOVABLE}) + public static boolean movableAnvil = false; + + /** + * 合成表规�? + */ + @SuppressWarnings("unused") + @CraftingRule(recipes = "enchanted_golden_apples.json") + @Rule(categories = {AMS, CRAFTING, SURVIVAL}) + public static boolean craftableEnchantedGoldenApples = false; + + //#if MC>=11700 + @SuppressWarnings("unused") + @CraftingRule(recipes = "bundle.json") + @Rule(categories = {AMS, CRAFTING, SURVIVAL}) + public static boolean craftableBundle = false; + //#endif + + //#if MC<11900 && MC>=11700 + @SuppressWarnings("unused") + @CraftingRule(recipes = "sculk_sensor.json") + @Rule(categories = {AMS, CRAFTING, SURVIVAL}) + public static boolean craftableSculkSensor = false; + //#endif + + @SuppressWarnings("unused") + @CraftingRule(recipes = "bone_block.json") + @Rule(categories = {AMS, CRAFTING, SURVIVAL}) + public static boolean betterCraftableBoneBlock = false; + + @SuppressWarnings("unused") + @CraftingRule(recipes = "elytra.json") + @Rule(categories = {AMS, CRAFTING, SURVIVAL}) + public static boolean craftableElytra = false; + + @SuppressWarnings("unused") + @CraftingRule(recipes = {"dispenser1.json", "dispenser2.json"}) + @Rule(categories = {AMS, CRAFTING, SURVIVAL}) + public static boolean betterCraftableDispenser = false; + + //#if MC>=11700 + @SuppressWarnings("unused") + @CraftingRule(recipes = "polished_blackstone_button.json") + @Rule(categories = {AMS, CRAFTING, SURVIVAL}) + public static boolean betterCraftablePolishedBlackStoneButton = false; + //#endif +} diff --git a/src/main/java/club/mcams/carpet/function/BlockChunkLoader.java b/src/main/java/club/mcams/carpet/function/BlockChunkLoader.java index 77c51374..4922b5d9 100644 --- a/src/main/java/club/mcams/carpet/function/BlockChunkLoader.java +++ b/src/main/java/club/mcams/carpet/function/BlockChunkLoader.java @@ -1,38 +1,38 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - - -package club.mcams.carpet.function; - -import net.minecraft.server.world.ChunkTicketType; -import net.minecraft.util.math.ChunkPos; - -import java.util.Comparator; - -public class BlockChunkLoader { - public static final ChunkTicketType - BLOCK_LOADER = ChunkTicketType.create - ( - "block_loader", Comparator.comparingLong(ChunkPos::toLong), - 300 - ); -} - - +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + + +package club.mcams.carpet.function; + +import net.minecraft.server.world.ChunkTicketType; +import net.minecraft.util.math.ChunkPos; + +import java.util.Comparator; + +public class BlockChunkLoader { + public static final ChunkTicketType + BLOCK_LOADER = ChunkTicketType.create + ( + "block_loader", Comparator.comparingLong(ChunkPos::toLong), + 300 + ); +} + + diff --git a/src/main/java/club/mcams/carpet/function/ChunkLoading.java b/src/main/java/club/mcams/carpet/function/ChunkLoading.java index 7fce3129..63fe144c 100644 --- a/src/main/java/club/mcams/carpet/function/ChunkLoading.java +++ b/src/main/java/club/mcams/carpet/function/ChunkLoading.java @@ -1,56 +1,56 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.function; - -import carpet.CarpetServer; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.network.ServerPlayerEntity; - -import java.util.HashMap; -import java.util.Map; - -public class ChunkLoading { - public static Map onlinePlayerMap = new HashMap<>(); - - public static void setPlayerInteraction(String playerName, boolean b, boolean online) { - if (playerFromName(playerName) == null) return; - if (online) { - onlinePlayerMap.put(playerName, b); - } - } - - public static void onPlayerConnect(PlayerEntity player) { - String playerName = player.getName().getString(); - setPlayerInteraction(playerName, true, true); - } - - public static void onPlayerDisconnect(PlayerEntity player) { - String playerName = player.getName().getString(); - if (onlinePlayerMap.containsKey(playerName)) { - setPlayerInteraction(playerName, true, false); - onlinePlayerMap.remove(playerName); - } - } - - protected static ServerPlayerEntity playerFromName(String name) { - return CarpetServer.minecraft_server.getPlayerManager().getPlayer(name); - } +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.function; + +import carpet.CarpetServer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.network.ServerPlayerEntity; + +import java.util.HashMap; +import java.util.Map; + +public class ChunkLoading { + public static Map onlinePlayerMap = new HashMap<>(); + + public static void setPlayerInteraction(String playerName, boolean b, boolean online) { + if (playerFromName(playerName) == null) return; + if (online) { + onlinePlayerMap.put(playerName, b); + } + } + + public static void onPlayerConnect(PlayerEntity player) { + String playerName = player.getName().getString(); + setPlayerInteraction(playerName, true, true); + } + + public static void onPlayerDisconnect(PlayerEntity player) { + String playerName = player.getName().getString(); + if (onlinePlayerMap.containsKey(playerName)) { + setPlayerInteraction(playerName, true, false); + onlinePlayerMap.remove(playerName); + } + } + + protected static ServerPlayerEntity playerFromName(String name) { + return CarpetServer.minecraft_server.getPlayerManager().getPlayer(name); + } } \ No newline at end of file diff --git a/src/main/java/club/mcams/carpet/logging/AmsCarpetLoggerRegistry.java b/src/main/java/club/mcams/carpet/logging/AmsCarpetLoggerRegistry.java index f9a0046e..fbaecf90 100644 --- a/src/main/java/club/mcams/carpet/logging/AmsCarpetLoggerRegistry.java +++ b/src/main/java/club/mcams/carpet/logging/AmsCarpetLoggerRegistry.java @@ -1,41 +1,41 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.logging; - -import carpet.logging.Logger; -public class AmsCarpetLoggerRegistry { - - public static void registerLoggers() { -// LoggerRegistry.registerLogger("dragonPortalLocation", standardLogger("dragonPortalLocation", null, null)); - } - - static Logger standardLogger(String logName, String def, String[] options) { - try { - return new Logger(AmsCarpetLoggerRegistry.class.getField("__" + logName), logName, def, options - //#if MC>=11700 - , true - //#endif - ); - } catch (NoSuchFieldException e) { - throw new RuntimeException("Failed to create logger " + logName); - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.logging; + +import carpet.logging.Logger; +public class AmsCarpetLoggerRegistry { + + public static void registerLoggers() { +// LoggerRegistry.registerLogger("dragonPortalLocation", standardLogger("dragonPortalLocation", null, null)); + } + + static Logger standardLogger(String logName, String def, String[] options) { + try { + return new Logger(AmsCarpetLoggerRegistry.class.getField("__" + logName), logName, def, options + //#if MC>=11700 + , true + //#endif + ); + } catch (NoSuchFieldException e) { + throw new RuntimeException("Failed to create logger " + logName); + } + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/carpet/SettingsManagerMixin.java b/src/main/java/club/mcams/carpet/mixin/carpet/SettingsManagerMixin.java index 921b5597..82148e06 100644 --- a/src/main/java/club/mcams/carpet/mixin/carpet/SettingsManagerMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/carpet/SettingsManagerMixin.java @@ -1,65 +1,65 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.carpet; - -import carpet.settings.SettingsManager; -import carpet.utils.Messenger; - -import club.mcams.carpet.AmsServer; -import club.mcams.carpet.AmsServerMod; - -import net.minecraft.server.command.ServerCommandSource; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Slice; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import static carpet.utils.Translations.tr; - -@Mixin(SettingsManager.class) -public abstract class SettingsManagerMixin { - @SuppressWarnings("DefaultAnnotationParam") - @Inject( - method = "listAllSettings", - slice = @Slice( - from = @At( - value = "CONSTANT", - args = "stringValue=ui.version", // after printed fabric-carpet version - ordinal = 0 - ) - ), - at = @At( - value = "INVOKE", - target = "Lcarpet/settings/SettingsManager;getCategories()Ljava/lang/Iterable;", - ordinal = 0 - ), - remap = false - ) - private void printVersion(ServerCommandSource source, CallbackInfoReturnable cir) { - Messenger.m(source, - String.format("g %s ", AmsServer.fancyName), - String.format("g %s: ", tr("ui.version", "version")), - String.format("g %s", AmsServerMod.getVersion()) - ); - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.carpet; + +import carpet.settings.SettingsManager; +import carpet.utils.Messenger; + +import club.mcams.carpet.AmsServer; +import club.mcams.carpet.AmsServerMod; + +import net.minecraft.server.command.ServerCommandSource; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Slice; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import static carpet.utils.Translations.tr; + +@Mixin(SettingsManager.class) +public abstract class SettingsManagerMixin { + @SuppressWarnings("DefaultAnnotationParam") + @Inject( + method = "listAllSettings", + slice = @Slice( + from = @At( + value = "CONSTANT", + args = "stringValue=ui.version", // after printed fabric-carpet version + ordinal = 0 + ) + ), + at = @At( + value = "INVOKE", + target = "Lcarpet/settings/SettingsManager;getCategories()Ljava/lang/Iterable;", + ordinal = 0 + ), + remap = false + ) + private void printVersion(ServerCommandSource source, CallbackInfoReturnable cir) { + Messenger.m(source, + String.format("g %s ", AmsServer.fancyName), + String.format("g %s: ", tr("ui.version", "version")), + String.format("g %s", AmsServerMod.getVersion()) + ); + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/interaction/ThreadedAnvilChunkStorageMixin.java b/src/main/java/club/mcams/carpet/mixin/interaction/ThreadedAnvilChunkStorageMixin.java index fcf288cb..c83c7576 100644 --- a/src/main/java/club/mcams/carpet/mixin/interaction/ThreadedAnvilChunkStorageMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/interaction/ThreadedAnvilChunkStorageMixin.java @@ -1,51 +1,51 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.interaction; - -import club.mcams.carpet.function.ChunkLoading; - -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ThreadedAnvilChunkStorage.class) -public abstract class ThreadedAnvilChunkStorageMixin { - - @Final - @Shadow - ServerWorld world; - - @Inject(method = "doesNotGenerateChunks", at = @At("HEAD"), cancellable = true) - private void doesNotGenerateChunks(ServerPlayerEntity player, CallbackInfoReturnable cir) { - String playerName = player.getName().getString(); - if (!ChunkLoading.onlinePlayerMap.getOrDefault(playerName, true)) { - cir.setReturnValue(true); - cir.cancel(); - } - } +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.interaction; + +import club.mcams.carpet.function.ChunkLoading; + +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.server.world.ThreadedAnvilChunkStorage; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ThreadedAnvilChunkStorage.class) +public abstract class ThreadedAnvilChunkStorageMixin { + + @Final + @Shadow + ServerWorld world; + + @Inject(method = "doesNotGenerateChunks", at = @At("HEAD"), cancellable = true) + private void doesNotGenerateChunks(ServerPlayerEntity player, CallbackInfoReturnable cir) { + String playerName = player.getName().getString(); + if (!ChunkLoading.onlinePlayerMap.getOrDefault(playerName, true)) { + cir.setReturnValue(true); + cir.cancel(); + } + } } \ No newline at end of file diff --git a/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/BellBlockMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/BellBlockMixin.java index 4b96bec1..163db659 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/BellBlockMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/BellBlockMixin.java @@ -1,60 +1,60 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.blockChunkLoader; - -import club.mcams.carpet.AmsServerSettings; -import club.mcams.carpet.function.BlockChunkLoader; - -import net.minecraft.block.BellBlock; -import net.minecraft.entity.Entity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(BellBlock.class) -public abstract class BellBlockMixin { - @Inject( - method = - //#if MC>=11700 - "ring(Lnet/minecraft/entity/Entity;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Z", - //#else - //$$ "ring(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Z", - //#endif - at = @At("HEAD") - ) - private void ringByTriggeredMixin( - //#if MC>=11700 - Entity entity, - //#endif - World world, BlockPos pos, Direction direction, CallbackInfoReturnable cir) { - if (AmsServerSettings.bellBlockChunkLoader && !world.isClient) { - ChunkPos chunkPos = new ChunkPos(pos); - ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.blockChunkLoader; + +import club.mcams.carpet.AmsServerSettings; +import club.mcams.carpet.function.BlockChunkLoader; + +import net.minecraft.block.BellBlock; +import net.minecraft.entity.Entity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(BellBlock.class) +public abstract class BellBlockMixin { + @Inject( + method = + //#if MC>=11700 + "ring(Lnet/minecraft/entity/Entity;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Z", + //#else + //$$ "ring(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Z", + //#endif + at = @At("HEAD") + ) + private void ringByTriggeredMixin( + //#if MC>=11700 + Entity entity, + //#endif + World world, BlockPos pos, Direction direction, CallbackInfoReturnable cir) { + if (AmsServerSettings.bellBlockChunkLoader && !world.isClient) { + ChunkPos chunkPos = new ChunkPos(pos); + ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); + } + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/NoteBlockMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/NoteBlockMixin.java index 7b9b2d7d..7c938000 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/NoteBlockMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/NoteBlockMixin.java @@ -1,75 +1,75 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.blockChunkLoader; - -import club.mcams.carpet.AmsServerSettings; -import club.mcams.carpet.function.BlockChunkLoader; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.NoteBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.World; -//#if MC>=11900 -//$$ import net.minecraft.block.BlockState; -//$$ import net.minecraft.entity.Entity; -//#endif - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Objects; - -@Mixin(NoteBlock.class) -public abstract class NoteBlockMixin { - @Inject(at = @At("HEAD"), method = "playNote") - private void playNoteMixin( - //#if MC>=11900 - //$$ Entity entity, - //#endif - //#if MC>=11903 - //$$ BlockState blockState, - //#endif - World world, BlockPos pos, CallbackInfo info) { - if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "note_block") && !world.isClient) { - ChunkPos chunkPos = new ChunkPos(pos); - ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); - } - if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "bone_block") && !world.isClient) { - BlockState noteBlock = world.getBlockState(pos.up(1)); - if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "bone_block") && noteBlock.isOf(Blocks.BONE_BLOCK)) { - ChunkPos chunkPos = new ChunkPos(pos.up(1)); - ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); - } - } - if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "wither_skeleton_skull") && !world.isClient) { - BlockState noteBlock = world.getBlockState(pos.up(1)); - if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "wither_skeleton_skull") && (noteBlock.isOf(Blocks.WITHER_SKELETON_SKULL)) || (noteBlock.isOf(Blocks.WITHER_SKELETON_WALL_SKULL))) { - ChunkPos chunkPos = new ChunkPos(pos.up(1)); - ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); - } - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.blockChunkLoader; + +import club.mcams.carpet.AmsServerSettings; +import club.mcams.carpet.function.BlockChunkLoader; + +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.NoteBlock; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.World; +//#if MC>=11900 +//$$ import net.minecraft.block.BlockState; +//$$ import net.minecraft.entity.Entity; +//#endif + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Objects; + +@Mixin(NoteBlock.class) +public abstract class NoteBlockMixin { + @Inject(at = @At("HEAD"), method = "playNote") + private void playNoteMixin( + //#if MC>=11900 + //$$ Entity entity, + //#endif + //#if MC>=11903 + //$$ BlockState blockState, + //#endif + World world, BlockPos pos, CallbackInfo info) { + if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "note_block") && !world.isClient) { + ChunkPos chunkPos = new ChunkPos(pos); + ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); + } + if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "bone_block") && !world.isClient) { + BlockState noteBlock = world.getBlockState(pos.up(1)); + if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "bone_block") && noteBlock.isOf(Blocks.BONE_BLOCK)) { + ChunkPos chunkPos = new ChunkPos(pos.up(1)); + ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); + } + } + if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "wither_skeleton_skull") && !world.isClient) { + BlockState noteBlock = world.getBlockState(pos.up(1)); + if (Objects.equals(AmsServerSettings.noteBlockChunkLoader, "wither_skeleton_skull") && (noteBlock.isOf(Blocks.WITHER_SKELETON_SKULL)) || (noteBlock.isOf(Blocks.WITHER_SKELETON_WALL_SKULL))) { + ChunkPos chunkPos = new ChunkPos(pos.up(1)); + ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); + } + } + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/PistonBlockMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/PistonBlockMixin.java index 189c48e5..be5dfa54 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/PistonBlockMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/blockChunkLoader/PistonBlockMixin.java @@ -1,65 +1,65 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.blockChunkLoader; - -import club.mcams.carpet.AmsServerSettings; -import club.mcams.carpet.function.BlockChunkLoader; - -import net.minecraft.block.Blocks; -import net.minecraft.block.FacingBlock; -import net.minecraft.block.PistonBlock; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Objects; - -@Mixin(PistonBlock.class) -public abstract class PistonBlockMixin { - @Inject(method = "onSyncedBlockEvent", at = @At("HEAD")) - private void onSyncedBlockEvent(BlockState state, World world, BlockPos pos, int type, int data, CallbackInfoReturnable cir) { - if((Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "bone_block") || Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "all")) && !world.isClient) { - Direction direction = state.get(FacingBlock.FACING); - BlockState pistonBlock = world.getBlockState(pos.up(1)); - if ((Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "bone_block") || Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "all")) && pistonBlock.isOf(Blocks.BONE_BLOCK)) { - ChunkPos chunkPos = new ChunkPos(pos.offset(direction)); - ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); - } - } - - if((Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "bedrock") || Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "all")) && !world.isClient) { - Direction direction = state.get(FacingBlock.FACING); - BlockState pistonBlock = world.getBlockState(pos.down(1)); - if ((Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "bedrock") || Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "all")) && pistonBlock.isOf(Blocks.BEDROCK)) { - ChunkPos chunkPos = new ChunkPos(pos.offset(direction)); - ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); - } - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.blockChunkLoader; + +import club.mcams.carpet.AmsServerSettings; +import club.mcams.carpet.function.BlockChunkLoader; + +import net.minecraft.block.Blocks; +import net.minecraft.block.FacingBlock; +import net.minecraft.block.PistonBlock; +import net.minecraft.block.BlockState; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.Objects; + +@Mixin(PistonBlock.class) +public abstract class PistonBlockMixin { + @Inject(method = "onSyncedBlockEvent", at = @At("HEAD")) + private void onSyncedBlockEvent(BlockState state, World world, BlockPos pos, int type, int data, CallbackInfoReturnable cir) { + if((Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "bone_block") || Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "all")) && !world.isClient) { + Direction direction = state.get(FacingBlock.FACING); + BlockState pistonBlock = world.getBlockState(pos.up(1)); + if ((Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "bone_block") || Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "all")) && pistonBlock.isOf(Blocks.BONE_BLOCK)) { + ChunkPos chunkPos = new ChunkPos(pos.offset(direction)); + ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); + } + } + + if((Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "bedrock") || Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "all")) && !world.isClient) { + Direction direction = state.get(FacingBlock.FACING); + BlockState pistonBlock = world.getBlockState(pos.down(1)); + if ((Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "bedrock") || Objects.equals(AmsServerSettings.pistonBlockChunkLoader, "all")) && pistonBlock.isOf(Blocks.BEDROCK)) { + ChunkPos chunkPos = new ChunkPos(pos.offset(direction)); + ((ServerWorld) world).getChunkManager().addTicket(BlockChunkLoader.BLOCK_LOADER, chunkPos, 3, chunkPos); + } + } + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/AbstractPlantPartBlockMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/AbstractPlantPartBlockMixin.java index 6e733c71..2434cf1b 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/AbstractPlantPartBlockMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/AbstractPlantPartBlockMixin.java @@ -1,67 +1,67 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.scheduledRandomTick; - -import club.mcams.carpet.AmsServerSettings; - -import net.minecraft.block.AbstractPlantPartBlock; -import net.minecraft.block.AbstractPlantStemBlock; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -//#if MC>=11900 -//$$import net.minecraft.util.math.random.Random; -//#else -import java.util.Random; -//#endif - -@Mixin(AbstractPlantPartBlock.class) -public abstract class AbstractPlantPartBlockMixin{ - @Inject( - method = "scheduledTick", - at = @At( - value = "INVOKE", - shift = At.Shift.AFTER, - target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" - ), - cancellable = true - ) - private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (AmsServerSettings.scheduledRandomTickStem || AmsServerSettings.scheduledRandomTickAllPlants) { - ci.cancel(); - } - } - - @Inject( - method = "scheduledTick", - at = @At("TAIL") - ) - private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (state.getBlock() instanceof AbstractPlantStemBlock && (AmsServerSettings.scheduledRandomTickStem || AmsServerSettings.scheduledRandomTickAllPlants)) { - state.randomTick(world, pos, random); - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.scheduledRandomTick; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.block.AbstractPlantPartBlock; +import net.minecraft.block.AbstractPlantStemBlock; +import net.minecraft.block.BlockState; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//#if MC>=11900 +//$$import net.minecraft.util.math.random.Random; +//#else +import java.util.Random; +//#endif + +@Mixin(AbstractPlantPartBlock.class) +public abstract class AbstractPlantPartBlockMixin{ + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (AmsServerSettings.scheduledRandomTickStem || AmsServerSettings.scheduledRandomTickAllPlants) { + ci.cancel(); + } + } + + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (state.getBlock() instanceof AbstractPlantStemBlock && (AmsServerSettings.scheduledRandomTickStem || AmsServerSettings.scheduledRandomTickAllPlants)) { + state.randomTick(world, pos, random); + } + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/BambooBlockMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/BambooBlockMixin.java index fef38f1d..a3eb9816 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/BambooBlockMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/BambooBlockMixin.java @@ -1,71 +1,71 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.scheduledRandomTick; - -import club.mcams.carpet.AmsServerSettings; - -import net.minecraft.block.BambooBlock; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -//#if MC>=11900 -//$$import net.minecraft.util.math.random.Random; -//#else -import java.util.Random; -//#endif - -@Mixin(BambooBlock.class) -public abstract class BambooBlockMixin{ - - @Shadow - public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); - - @Inject( - method = "scheduledTick", - at = @At( - value = "INVOKE", - shift = At.Shift.AFTER, - target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" - ), - cancellable = true - ) - private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (AmsServerSettings.scheduledRandomTickBamboo || AmsServerSettings.scheduledRandomTickAllPlants) { - ci.cancel(); - } - } - - @Inject( - method = "scheduledTick", - at = @At("TAIL") - ) - private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (AmsServerSettings.scheduledRandomTickBamboo || AmsServerSettings.scheduledRandomTickAllPlants) { - this.randomTick(state, world, pos, random); - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.scheduledRandomTick; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.block.BambooBlock; +import net.minecraft.block.BlockState; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//#if MC>=11900 +//$$import net.minecraft.util.math.random.Random; +//#else +import java.util.Random; +//#endif + +@Mixin(BambooBlock.class) +public abstract class BambooBlockMixin{ + + @Shadow + public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); + + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (AmsServerSettings.scheduledRandomTickBamboo || AmsServerSettings.scheduledRandomTickAllPlants) { + ci.cancel(); + } + } + + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (AmsServerSettings.scheduledRandomTickBamboo || AmsServerSettings.scheduledRandomTickAllPlants) { + this.randomTick(state, world, pos, random); + } + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/CactusBlockMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/CactusBlockMixin.java index 4e7599fd..2e6df2bc 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/CactusBlockMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/CactusBlockMixin.java @@ -1,68 +1,68 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.scheduledRandomTick; - -import club.mcams.carpet.AmsServerSettings; - -import net.minecraft.block.BlockState; -import net.minecraft.block.CactusBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -//#if MC>=11900 -//$$import net.minecraft.util.math.random.Random; -//#else -import java.util.Random; -//#endif - -@Mixin(CactusBlock.class) -public abstract class CactusBlockMixin{ - @Shadow - public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); - - @Inject( - method = "scheduledTick", - at = @At( - value = "INVOKE", - shift = At.Shift.AFTER, - target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" - ), - cancellable = true - ) - private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (AmsServerSettings.scheduledRandomTickCactus || AmsServerSettings.scheduledRandomTickAllPlants) - ci.cancel(); - } - - @Inject( - method = "scheduledTick", - at = @At("TAIL") - ) - private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (AmsServerSettings.scheduledRandomTickCactus || AmsServerSettings.scheduledRandomTickAllPlants) - this.randomTick(state, world, pos, random); - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.scheduledRandomTick; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.block.BlockState; +import net.minecraft.block.CactusBlock; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//#if MC>=11900 +//$$import net.minecraft.util.math.random.Random; +//#else +import java.util.Random; +//#endif + +@Mixin(CactusBlock.class) +public abstract class CactusBlockMixin{ + @Shadow + public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); + + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (AmsServerSettings.scheduledRandomTickCactus || AmsServerSettings.scheduledRandomTickAllPlants) + ci.cancel(); + } + + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (AmsServerSettings.scheduledRandomTickCactus || AmsServerSettings.scheduledRandomTickAllPlants) + this.randomTick(state, world, pos, random); + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/ChorusFlowerBlockMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/ChorusFlowerBlockMixin.java index 0cff2b87..0a3b04d7 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/ChorusFlowerBlockMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/ChorusFlowerBlockMixin.java @@ -1,68 +1,68 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.scheduledRandomTick; - -import club.mcams.carpet.AmsServerSettings; - -import net.minecraft.block.BlockState; -import net.minecraft.block.ChorusFlowerBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -//#if MC>=11900 -//$$import net.minecraft.util.math.random.Random; -//#else -import java.util.Random; -//#endif - -@Mixin(ChorusFlowerBlock.class) -public abstract class ChorusFlowerBlockMixin{ - @Shadow - public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); - - @Inject( - method = "scheduledTick", - at = @At( - value = "INVOKE", - shift = At.Shift.AFTER, - target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" - ), - cancellable = true - ) - private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (AmsServerSettings.scheduledRandomTickChorusFlower || AmsServerSettings.scheduledRandomTickAllPlants) - ci.cancel(); - } - - @Inject( - method = "scheduledTick", - at = @At("TAIL") - ) - private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (AmsServerSettings.scheduledRandomTickChorusFlower || AmsServerSettings.scheduledRandomTickAllPlants) - this.randomTick(state, world, pos, random); - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.scheduledRandomTick; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.block.BlockState; +import net.minecraft.block.ChorusFlowerBlock; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//#if MC>=11900 +//$$import net.minecraft.util.math.random.Random; +//#else +import java.util.Random; +//#endif + +@Mixin(ChorusFlowerBlock.class) +public abstract class ChorusFlowerBlockMixin{ + @Shadow + public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); + + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (AmsServerSettings.scheduledRandomTickChorusFlower || AmsServerSettings.scheduledRandomTickAllPlants) + ci.cancel(); + } + + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (AmsServerSettings.scheduledRandomTickChorusFlower || AmsServerSettings.scheduledRandomTickAllPlants) + this.randomTick(state, world, pos, random); + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/SugarCaneBlockMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/SugarCaneBlockMixin.java index a0301ca5..86fc97ed 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/SugarCaneBlockMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/scheduledRandomTick/SugarCaneBlockMixin.java @@ -1,70 +1,70 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.scheduledRandomTick; - -import club.mcams.carpet.AmsServerSettings; - -import net.minecraft.block.BlockState; -import net.minecraft.block.SugarCaneBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -//#if MC>=11900 -//$$import net.minecraft.util.math.random.Random; -//#else -import java.util.Random; -//#endif - -@Mixin(SugarCaneBlock.class) -public abstract class SugarCaneBlockMixin{ - @Shadow - public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); - - @Inject( - method = "scheduledTick", - at = @At( - value = "INVOKE", - shift = At.Shift.AFTER, - target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" - ), - cancellable = true - ) - private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (AmsServerSettings.scheduledRandomTickSugarCane || AmsServerSettings.scheduledRandomTickAllPlants) { - ci.cancel(); - } - } - - @Inject( - method = "scheduledTick", - at = @At("TAIL") - ) - private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (AmsServerSettings.scheduledRandomTickSugarCane || AmsServerSettings.scheduledRandomTickAllPlants) { - this.randomTick(state, world, pos, random); - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.scheduledRandomTick; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.block.BlockState; +import net.minecraft.block.SugarCaneBlock; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//#if MC>=11900 +//$$import net.minecraft.util.math.random.Random; +//#else +import java.util.Random; +//#endif + +@Mixin(SugarCaneBlock.class) +public abstract class SugarCaneBlockMixin{ + @Shadow + public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); + + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTickMixinInvoke(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (AmsServerSettings.scheduledRandomTickSugarCane || AmsServerSettings.scheduledRandomTickAllPlants) { + ci.cancel(); + } + } + + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTickMixinTail(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (AmsServerSettings.scheduledRandomTickSugarCane || AmsServerSettings.scheduledRandomTickAllPlants) { + this.randomTick(state, world, pos, random); + } + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/sharedVillagerDiscounts/GetValueForInvoker.java b/src/main/java/club/mcams/carpet/mixin/rule/sharedVillagerDiscounts/GetValueForInvoker.java index a24bbc6c..3d9f82d0 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/sharedVillagerDiscounts/GetValueForInvoker.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/sharedVillagerDiscounts/GetValueForInvoker.java @@ -1,34 +1,34 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.sharedVillagerDiscounts; - -import net.minecraft.village.VillageGossipType; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -import java.util.function.Predicate; - -@Mixin(targets = "net.minecraft.village.VillagerGossips$Reputation") -public interface GetValueForInvoker { - @Invoker("getValueFor") - public int _getValueFor(Predicate gossipTypeFilter); -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.sharedVillagerDiscounts; + +import net.minecraft.village.VillageGossipType; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.function.Predicate; + +@Mixin(targets = "net.minecraft.village.VillagerGossips$Reputation") +public interface GetValueForInvoker { + @Invoker("getValueFor") + public int _getValueFor(Predicate gossipTypeFilter); +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/sharedVillagerDiscounts/VillagerGossipsMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/sharedVillagerDiscounts/VillagerGossipsMixin.java index 2060811c..f08fe722 100644 --- a/src/main/java/club/mcams/carpet/mixin/rule/sharedVillagerDiscounts/VillagerGossipsMixin.java +++ b/src/main/java/club/mcams/carpet/mixin/rule/sharedVillagerDiscounts/VillagerGossipsMixin.java @@ -1,56 +1,56 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.mixin.rule.sharedVillagerDiscounts; - -import club.mcams.carpet.AmsServerSettings; - -import net.minecraft.village.VillageGossipType; -import net.minecraft.village.VillagerGossips; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Map; -import java.util.UUID; -import java.util.function.Predicate; - -import static net.minecraft.village.VillageGossipType.MAJOR_POSITIVE; - -@Mixin(VillagerGossips.class) -public abstract class VillagerGossipsMixin { - @Shadow - @Final - private Map entityReputation; - @Inject(method = "getReputationFor(Ljava/util/UUID;Ljava/util/function/Predicate;)I", at = @At("HEAD"), cancellable = true) - public void getReputation(UUID target, Predicate filter, CallbackInfoReturnable cir) { - if (AmsServerSettings.sharedVillagerDiscounts && filter.test(MAJOR_POSITIVE)) { - GetValueForInvoker targetReputation = (GetValueForInvoker)entityReputation.get(target); - int otherRepertory = 0; - if (targetReputation != null) { otherRepertory = targetReputation._getValueFor(vgt -> filter.test(vgt) && !vgt.equals(MAJOR_POSITIVE)); } - int majorPositiveRepertory = entityReputation.values().stream().mapToInt(r -> ((GetValueForInvoker) r)._getValueFor(vgt -> vgt.equals(MAJOR_POSITIVE))).sum(); - cir.setReturnValue(otherRepertory + Math.min(majorPositiveRepertory, MAJOR_POSITIVE.maxValue * MAJOR_POSITIVE.multiplier)); - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.sharedVillagerDiscounts; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.village.VillageGossipType; +import net.minecraft.village.VillagerGossips; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.Map; +import java.util.UUID; +import java.util.function.Predicate; + +import static net.minecraft.village.VillageGossipType.MAJOR_POSITIVE; + +@Mixin(VillagerGossips.class) +public abstract class VillagerGossipsMixin { + @Shadow + @Final + private Map entityReputation; + @Inject(method = "getReputationFor(Ljava/util/UUID;Ljava/util/function/Predicate;)I", at = @At("HEAD"), cancellable = true) + public void getReputation(UUID target, Predicate filter, CallbackInfoReturnable cir) { + if (AmsServerSettings.sharedVillagerDiscounts && filter.test(MAJOR_POSITIVE)) { + GetValueForInvoker targetReputation = (GetValueForInvoker)entityReputation.get(target); + int otherRepertory = 0; + if (targetReputation != null) { otherRepertory = targetReputation._getValueFor(vgt -> filter.test(vgt) && !vgt.equals(MAJOR_POSITIVE)); } + int majorPositiveRepertory = entityReputation.values().stream().mapToInt(r -> ((GetValueForInvoker) r)._getValueFor(vgt -> vgt.equals(MAJOR_POSITIVE))).sum(); + cir.setReturnValue(otherRepertory + Math.min(majorPositiveRepertory, MAJOR_POSITIVE.maxValue * MAJOR_POSITIVE.multiplier)); + } + } +} diff --git a/src/main/java/club/mcams/carpet/settings/AmsRuleCategory.java b/src/main/java/club/mcams/carpet/settings/AmsRuleCategory.java index 7af9bd21..1e553c1b 100644 --- a/src/main/java/club/mcams/carpet/settings/AmsRuleCategory.java +++ b/src/main/java/club/mcams/carpet/settings/AmsRuleCategory.java @@ -1,41 +1,41 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.settings; - -@SuppressWarnings("unused") -public class AmsRuleCategory { - public static final String AMS = "AMS"; - public static final String CRAFTING = "crafting"; - public static final String AMS_MOVABLE = "AMS_movable"; - public static final String AMS_CHUNKLOADER = "AMS_chunkLoader"; -//================================================================== - public static final String BUGFIX = "bugfix"; - public static final String SURVIVAL = "survival"; - public static final String CREATIVE = "creative"; - public static final String EXPERIMENTAL = "experimental"; - public static final String OPTIMIZATION = "optimization"; - public static final String FEATURE = "feature"; - public static final String COMMAND = "command"; - public static final String TNT = "tnt"; - public static final String DISPENSER = "dispenser"; - public static final String SCARPET = "scarpet"; - public static final String CLIENT = "client"; -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.settings; + +@SuppressWarnings("unused") +public class AmsRuleCategory { + public static final String AMS = "AMS"; + public static final String CRAFTING = "crafting"; + public static final String AMS_MOVABLE = "AMS_movable"; + public static final String AMS_CHUNKLOADER = "AMS_chunkLoader"; +//================================================================== + public static final String BUGFIX = "bugfix"; + public static final String SURVIVAL = "survival"; + public static final String CREATIVE = "creative"; + public static final String EXPERIMENTAL = "experimental"; + public static final String OPTIMIZATION = "optimization"; + public static final String FEATURE = "feature"; + public static final String COMMAND = "command"; + public static final String TNT = "tnt"; + public static final String DISPENSER = "dispenser"; + public static final String SCARPET = "scarpet"; + public static final String CLIENT = "client"; +} diff --git a/src/main/java/club/mcams/carpet/util/AutoMixinAuditExecutor/AutoMixinAuditExecutor.java b/src/main/java/club/mcams/carpet/util/AutoMixinAuditExecutor/AutoMixinAuditExecutor.java index adff66e4..e1239da0 100644 --- a/src/main/java/club/mcams/carpet/util/AutoMixinAuditExecutor/AutoMixinAuditExecutor.java +++ b/src/main/java/club/mcams/carpet/util/AutoMixinAuditExecutor/AutoMixinAuditExecutor.java @@ -1,38 +1,38 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.util.AutoMixinAuditExecutor; - -import club.mcams.carpet.AmsServer; -import club.mcams.carpet.util.MixinUtil; - -import net.fabricmc.loader.api.FabricLoader; - -public class AutoMixinAuditExecutor { - private static final String KEYWORD_PROPERTY = "carpetamsaddition.mixin_audit"; - public static void run() { - if (FabricLoader.getInstance().isDevelopmentEnvironment() && "true".equals(System.getProperty(KEYWORD_PROPERTY))) { - AmsServer.LOGGER.info("Triggered auto mixin audit"); - boolean ok = MixinUtil.audit(null); - AmsServer.LOGGER.info("Mixin audit result: " + (ok ? "successful" : "failed")); - System.exit(ok ? 0 : 1); - } - } +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.util.AutoMixinAuditExecutor; + +import club.mcams.carpet.AmsServer; +import club.mcams.carpet.util.MixinUtil; + +import net.fabricmc.loader.api.FabricLoader; + +public class AutoMixinAuditExecutor { + private static final String KEYWORD_PROPERTY = "carpetamsaddition.mixin_audit"; + public static void run() { + if (FabricLoader.getInstance().isDevelopmentEnvironment() && "true".equals(System.getProperty(KEYWORD_PROPERTY))) { + AmsServer.LOGGER.info("Triggered auto mixin audit"); + boolean ok = MixinUtil.audit(null); + AmsServer.LOGGER.info("Mixin audit result: " + (ok ? "successful" : "failed")); + System.exit(ok ? 0 : 1); + } + } } \ No newline at end of file diff --git a/src/main/java/club/mcams/carpet/util/CommandHelper.java b/src/main/java/club/mcams/carpet/util/CommandHelper.java index e5aab34c..57a1620f 100644 --- a/src/main/java/club/mcams/carpet/util/CommandHelper.java +++ b/src/main/java/club/mcams/carpet/util/CommandHelper.java @@ -1,56 +1,56 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.util; - -import net.minecraft.command.CommandSource; - -/** - * From gnembon's carpet mod lol - *

- * A few helpful methods to work with settings and commands. - *

- * This is not any kind of API, but it's unlikely to change - */ -public final class CommandHelper { - private CommandHelper() { - } - - /** - * Whether the given source has enough permission level to run a command that requires the given commandLevel - */ - public static boolean canUseCommand(CommandSource source, Object commandLevel) { - if (commandLevel instanceof Boolean) return (Boolean) commandLevel; - String commandLevelString = commandLevel.toString(); - switch (commandLevelString) { - case "true": return true; - case "false": return false; - case "ops": return source.hasPermissionLevel(2); // typical for other cheaty commands - case "0": - case "1": - case "2": - case "3": - case "4": - return source.hasPermissionLevel(Integer.parseInt(commandLevelString)); - default: - return false; - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.util; + +import net.minecraft.command.CommandSource; + +/** + * From gnembon's carpet mod lol + *

+ * A few helpful methods to work with settings and commands. + *

+ * This is not any kind of API, but it's unlikely to change + */ +public final class CommandHelper { + private CommandHelper() { + } + + /** + * Whether the given source has enough permission level to run a command that requires the given commandLevel + */ + public static boolean canUseCommand(CommandSource source, Object commandLevel) { + if (commandLevel instanceof Boolean) return (Boolean) commandLevel; + String commandLevelString = commandLevel.toString(); + switch (commandLevelString) { + case "true": return true; + case "false": return false; + case "ops": return source.hasPermissionLevel(2); // typical for other cheaty commands + case "0": + case "1": + case "2": + case "3": + case "4": + return source.hasPermissionLevel(Integer.parseInt(commandLevelString)); + default: + return false; + } + } +} diff --git a/src/main/java/club/mcams/carpet/util/Logging.java b/src/main/java/club/mcams/carpet/util/Logging.java index a4820134..1a9c96f0 100644 --- a/src/main/java/club/mcams/carpet/util/Logging.java +++ b/src/main/java/club/mcams/carpet/util/Logging.java @@ -1,95 +1,95 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.util; - -import club.mcams.carpet.AmsServer; - -import java.util.Collections; -import java.util.IdentityHashMap; -import java.util.Set; - -public class Logging { - public static void logStackTrace(Throwable e) { - Set dejaVu = Collections.newSetFromMap(new IdentityHashMap<>()); - dejaVu.add(e); - - // Print our stack trace - AmsServer.LOGGER.error(e); - StackTraceElement[] trace = e.getStackTrace(); - for (StackTraceElement traceElement : trace) { - AmsServer.LOGGER.error("\tat " + traceElement); - } - - // Print suppressed exceptions, if any - for (Throwable se : e.getSuppressed()) { - logEnclosedStackTrace(se, trace, "Suppressed: ", "\t", dejaVu); - } - - // Print cause, if any - Throwable ourCause = e.getCause(); - if (ourCause != null) { - logEnclosedStackTrace(ourCause, trace, "Caused by: ", "", dejaVu); - } - } - - private static void logEnclosedStackTrace( - Throwable e, - StackTraceElement[] enclosingTrace, - String caption, - String prefix, - Set dejaVu - ) { - if (dejaVu.contains(e)) { - AmsServer.LOGGER.error(prefix + caption + "[CIRCULAR REFERENCE: " + e + "]"); - } else { - dejaVu.add(e); - // Compute number of frames in common between e and enclosing trace - StackTraceElement[] trace = e.getStackTrace(); - int m = trace.length - 1; - int n = enclosingTrace.length - 1; - while (m >= 0 && n >= 0 && trace[m].equals(enclosingTrace[n])) { - m--; - n--; - } - int framesInCommon = trace.length - 1 - m; - - // Print our stack trace - AmsServer.LOGGER.error(prefix + caption + e); - for (int i = 0; i <= m; i++) { - AmsServer.LOGGER.error(prefix + "\tat " + trace[i]); - } - if (framesInCommon != 0) { - AmsServer.LOGGER.error(prefix + "\t... " + framesInCommon + " more"); - } - - // Print suppressed exceptions, if any - for (Throwable se : e.getSuppressed()) { - logEnclosedStackTrace(se, trace, "Suppressed: ", prefix + "\t", dejaVu); - } - - // Print cause, if any - Throwable ourCause = e.getCause(); - if (ourCause != null) { - logEnclosedStackTrace(ourCause, trace, "Caused by: ", prefix, dejaVu); - } - } - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.util; + +import club.mcams.carpet.AmsServer; + +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Set; + +public class Logging { + public static void logStackTrace(Throwable e) { + Set dejaVu = Collections.newSetFromMap(new IdentityHashMap<>()); + dejaVu.add(e); + + // Print our stack trace + AmsServer.LOGGER.error(e); + StackTraceElement[] trace = e.getStackTrace(); + for (StackTraceElement traceElement : trace) { + AmsServer.LOGGER.error("\tat " + traceElement); + } + + // Print suppressed exceptions, if any + for (Throwable se : e.getSuppressed()) { + logEnclosedStackTrace(se, trace, "Suppressed: ", "\t", dejaVu); + } + + // Print cause, if any + Throwable ourCause = e.getCause(); + if (ourCause != null) { + logEnclosedStackTrace(ourCause, trace, "Caused by: ", "", dejaVu); + } + } + + private static void logEnclosedStackTrace( + Throwable e, + StackTraceElement[] enclosingTrace, + String caption, + String prefix, + Set dejaVu + ) { + if (dejaVu.contains(e)) { + AmsServer.LOGGER.error(prefix + caption + "[CIRCULAR REFERENCE: " + e + "]"); + } else { + dejaVu.add(e); + // Compute number of frames in common between e and enclosing trace + StackTraceElement[] trace = e.getStackTrace(); + int m = trace.length - 1; + int n = enclosingTrace.length - 1; + while (m >= 0 && n >= 0 && trace[m].equals(enclosingTrace[n])) { + m--; + n--; + } + int framesInCommon = trace.length - 1 - m; + + // Print our stack trace + AmsServer.LOGGER.error(prefix + caption + e); + for (int i = 0; i <= m; i++) { + AmsServer.LOGGER.error(prefix + "\tat " + trace[i]); + } + if (framesInCommon != 0) { + AmsServer.LOGGER.error(prefix + "\t... " + framesInCommon + " more"); + } + + // Print suppressed exceptions, if any + for (Throwable se : e.getSuppressed()) { + logEnclosedStackTrace(se, trace, "Suppressed: ", prefix + "\t", dejaVu); + } + + // Print cause, if any + Throwable ourCause = e.getCause(); + if (ourCause != null) { + logEnclosedStackTrace(ourCause, trace, "Caused by: ", prefix, dejaVu); + } + } + } +} diff --git a/src/main/java/club/mcams/carpet/util/Messenger.java b/src/main/java/club/mcams/carpet/util/Messenger.java index 6ceeee06..4a7151f6 100644 --- a/src/main/java/club/mcams/carpet/util/Messenger.java +++ b/src/main/java/club/mcams/carpet/util/Messenger.java @@ -1,253 +1,253 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.util; - -import club.mcams.carpet.mixin.translations.StyleAccessor; -import club.mcams.carpet.translations.AMSTranslations; -import club.mcams.carpet.translations.Translator; -import club.mcams.carpet.util.compat.DimensionWrapper; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.*; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3i; - -import com.google.common.collect.ImmutableMap; - -import org.jetbrains.annotations.Nullable; - -//#if MC>=11900 -//$$ import java.util.function.Supplier; -//#endif - - -/** - * Reference: Carpet TIS Addition - */ -public class Messenger { - private static final Translator translator = new Translator("util"); - - // Compound Text - public static BaseText c(Object... fields) { - //#if MC>=11900 - //$$ return (MutableText) carpet.utils.Messenger.c(fields); - //#else - return carpet.utils.Messenger.c(fields); - //#endif - } - - // Simple Text - public static BaseText s(Object text) { - //#if MC>=11900 - //$$ return Text.literal(text.toString()); - //#else - return new LiteralText(text.toString()); - //#endif - } - - // Simple Text with carpet style - public static BaseText s(Object text, String carpetStyle) { - return formatting(s(text), carpetStyle); - } - - // Simple Text with formatting - public static BaseText s(Object text, Formatting textFormatting) { - return formatting(s(text), textFormatting); - } - - // Fancy Text - public static BaseText fancy(String carpetStyle, BaseText displayText, BaseText hoverText, ClickEvent clickEvent) { - BaseText text = copy(displayText); - if (carpetStyle != null) { - text.setStyle(parseCarpetStyle(carpetStyle)); - } - if (hoverText != null) { - hover(text, hoverText); - } - if (clickEvent != null) { - click(text, clickEvent); - } - return text; - } - - public static BaseText fancy(BaseText displayText, BaseText hoverText, ClickEvent clickEvent) { - return fancy(null, displayText, hoverText, clickEvent); - } - - // Translation Text - public static BaseText tr(String key, Object... args) { - //#if MC>=11900 - //$$ return Text.translatable(key, args); - //#else - return new TranslatableText(key, args); - //#endif - } - - public static BaseText copy(BaseText text) { - return (BaseText) text.shallowCopy(); - } - - public static void tell(ServerCommandSource source, BaseText text) { - Entity entity = source.getEntity(); - text = entity instanceof ServerPlayerEntity ? - AMSTranslations.translate(text, (ServerPlayerEntity) entity) : - AMSTranslations.translate(text); - //#if MC>=12000 - //$$ source.sendFeedback((Supplier) text, false); - //#else - source.sendFeedback(text, false); - //#endif - } - - public static BaseText formatting(BaseText text, Formatting... formattings) { - text.formatted(formattings); - return text; - } - - public static BaseText formatting(BaseText text, String carpetStyle) { - Style textStyle = text.getStyle(); - StyleAccessor parsedStyle = (StyleAccessor) parseCarpetStyle(carpetStyle); - textStyle = textStyle.withColor(parsedStyle.getColorField()); - textStyle = textStyle.withBold(parsedStyle.getBoldField()); - textStyle = textStyle.withItalic(parsedStyle.getItalicField()); - ((StyleAccessor) textStyle).setUnderlinedField(parsedStyle.getUnderlineField()); - ((StyleAccessor) textStyle).setStrikethroughField(parsedStyle.getStrikethroughField()); - ((StyleAccessor) textStyle).setObfuscatedField(parsedStyle.getObfuscatedField()); - return style(text, textStyle); - } - - public static BaseText style(BaseText text, Style style) { - text.setStyle(style); - return text; - } - - public static BaseText click(BaseText text, ClickEvent clickEvent) { - style(text, text.getStyle().withClickEvent(clickEvent)); - return text; - } - - public static BaseText hover(BaseText text, HoverEvent hoverEvent) { - style(text, text.getStyle().withHoverEvent(hoverEvent)); - return text; - } - - public static BaseText hover(BaseText text, BaseText hoverText) { - return hover(text, new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); - } - - public static BaseText entity(String style, Entity entity) { - BaseText entityBaseName = (BaseText) entity.getType().getName(); - BaseText entityDisplayName = (BaseText) entity.getName(); - BaseText hoverText = Messenger.c( - translator.tr("entity_type", entityBaseName, s(EntityType.getId(entity.getType()).toString())), newLine(), - getTeleportHint(entityDisplayName) - ); - return fancy(style, entityDisplayName, hoverText, new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, TextUtil.tp(entity))); - } - - private static BaseText getTeleportHint(BaseText dest) { - return translator.tr("teleport_hint", dest); - } - - public static BaseText newLine() { - return s("\n"); - } - - private static final ImmutableMap DIMENSION_NAME = ImmutableMap.of( - DimensionWrapper.OVERWORLD, tr("createWorld.customize.preset.overworld"), - DimensionWrapper.THE_NETHER, tr("advancements.nether.root.title"), - DimensionWrapper.THE_END, tr("advancements.end.root.title") - ); - - public static BaseText dimension(DimensionWrapper dim) { - BaseText dimText = DIMENSION_NAME.get(dim); - return dimText != null ? copy(dimText) : Messenger.s(dim.getIdentifierString()); - } - - private static BaseText __coord(String style, @Nullable DimensionWrapper dim, String posStr, String command) { - BaseText hoverText = Messenger.s(""); - hoverText.append(getTeleportHint(Messenger.s(posStr))); - if (dim != null) { - hoverText.append("\n"); - hoverText.append(translator.tr("teleport_hint.dimension")); - hoverText.append(": "); - hoverText.append(dimension(dim)); - } - return fancy(style, Messenger.s(posStr), hoverText, new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)); - } - - public static BaseText coord(String style, Vec3d pos, DimensionWrapper dim) { - return __coord(style, dim, TextUtil.coord(pos), TextUtil.tp(pos, dim)); - } - - public static BaseText coord(String style, Vec3i pos, DimensionWrapper dim) { - return __coord(style, dim, TextUtil.coord(pos), TextUtil.tp(pos, dim)); - } - - public static BaseText coord(String style, ChunkPos pos, DimensionWrapper dim) { - return __coord(style, dim, TextUtil.coord(pos), TextUtil.tp(pos, dim)); - } - - public static BaseText coord(String style, Vec3d pos) { - return __coord(style, null, TextUtil.coord(pos), TextUtil.tp(pos)); - } - - public static BaseText coord(String style, Vec3i pos) { - return __coord(style, null, TextUtil.coord(pos), TextUtil.tp(pos)); - } - - public static BaseText coord(String style, ChunkPos pos) { - return __coord(style, null, TextUtil.coord(pos), TextUtil.tp(pos)); - } - - public static BaseText coord(Vec3d pos, DimensionWrapper dim) { - return coord(null, pos, dim); - } - - public static BaseText coord(Vec3i pos, DimensionWrapper dim) { - return coord(null, pos, dim); - } - - public static BaseText coord(ChunkPos pos, DimensionWrapper dim) { - return coord(null, pos, dim); - } - - public static BaseText coord(Vec3d pos) { - return coord(null, pos); - } - - public static BaseText coord(Vec3i pos) { - return coord(null, pos); - } - - public static BaseText coord(ChunkPos pos) { - return coord(null, pos); - } - - public static Style parseCarpetStyle(String style) { - return carpet.utils.Messenger.parseStyle(style); - } -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.util; + +import club.mcams.carpet.mixin.translations.StyleAccessor; +import club.mcams.carpet.translations.AMSTranslations; +import club.mcams.carpet.translations.Translator; +import club.mcams.carpet.util.compat.DimensionWrapper; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.*; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; + +import com.google.common.collect.ImmutableMap; + +import org.jetbrains.annotations.Nullable; + +//#if MC>=11900 +//$$ import java.util.function.Supplier; +//#endif + + +/** + * Reference: Carpet TIS Addition + */ +public class Messenger { + private static final Translator translator = new Translator("util"); + + // Compound Text + public static BaseText c(Object... fields) { + //#if MC>=11900 + //$$ return (MutableText) carpet.utils.Messenger.c(fields); + //#else + return carpet.utils.Messenger.c(fields); + //#endif + } + + // Simple Text + public static BaseText s(Object text) { + //#if MC>=11900 + //$$ return Text.literal(text.toString()); + //#else + return new LiteralText(text.toString()); + //#endif + } + + // Simple Text with carpet style + public static BaseText s(Object text, String carpetStyle) { + return formatting(s(text), carpetStyle); + } + + // Simple Text with formatting + public static BaseText s(Object text, Formatting textFormatting) { + return formatting(s(text), textFormatting); + } + + // Fancy Text + public static BaseText fancy(String carpetStyle, BaseText displayText, BaseText hoverText, ClickEvent clickEvent) { + BaseText text = copy(displayText); + if (carpetStyle != null) { + text.setStyle(parseCarpetStyle(carpetStyle)); + } + if (hoverText != null) { + hover(text, hoverText); + } + if (clickEvent != null) { + click(text, clickEvent); + } + return text; + } + + public static BaseText fancy(BaseText displayText, BaseText hoverText, ClickEvent clickEvent) { + return fancy(null, displayText, hoverText, clickEvent); + } + + // Translation Text + public static BaseText tr(String key, Object... args) { + //#if MC>=11900 + //$$ return Text.translatable(key, args); + //#else + return new TranslatableText(key, args); + //#endif + } + + public static BaseText copy(BaseText text) { + return (BaseText) text.shallowCopy(); + } + + public static void tell(ServerCommandSource source, BaseText text) { + Entity entity = source.getEntity(); + text = entity instanceof ServerPlayerEntity ? + AMSTranslations.translate(text, (ServerPlayerEntity) entity) : + AMSTranslations.translate(text); + //#if MC>=12000 + //$$ source.sendFeedback((Supplier) text, false); + //#else + source.sendFeedback(text, false); + //#endif + } + + public static BaseText formatting(BaseText text, Formatting... formattings) { + text.formatted(formattings); + return text; + } + + public static BaseText formatting(BaseText text, String carpetStyle) { + Style textStyle = text.getStyle(); + StyleAccessor parsedStyle = (StyleAccessor) parseCarpetStyle(carpetStyle); + textStyle = textStyle.withColor(parsedStyle.getColorField()); + textStyle = textStyle.withBold(parsedStyle.getBoldField()); + textStyle = textStyle.withItalic(parsedStyle.getItalicField()); + ((StyleAccessor) textStyle).setUnderlinedField(parsedStyle.getUnderlineField()); + ((StyleAccessor) textStyle).setStrikethroughField(parsedStyle.getStrikethroughField()); + ((StyleAccessor) textStyle).setObfuscatedField(parsedStyle.getObfuscatedField()); + return style(text, textStyle); + } + + public static BaseText style(BaseText text, Style style) { + text.setStyle(style); + return text; + } + + public static BaseText click(BaseText text, ClickEvent clickEvent) { + style(text, text.getStyle().withClickEvent(clickEvent)); + return text; + } + + public static BaseText hover(BaseText text, HoverEvent hoverEvent) { + style(text, text.getStyle().withHoverEvent(hoverEvent)); + return text; + } + + public static BaseText hover(BaseText text, BaseText hoverText) { + return hover(text, new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); + } + + public static BaseText entity(String style, Entity entity) { + BaseText entityBaseName = (BaseText) entity.getType().getName(); + BaseText entityDisplayName = (BaseText) entity.getName(); + BaseText hoverText = Messenger.c( + translator.tr("entity_type", entityBaseName, s(EntityType.getId(entity.getType()).toString())), newLine(), + getTeleportHint(entityDisplayName) + ); + return fancy(style, entityDisplayName, hoverText, new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, TextUtil.tp(entity))); + } + + private static BaseText getTeleportHint(BaseText dest) { + return translator.tr("teleport_hint", dest); + } + + public static BaseText newLine() { + return s("\n"); + } + + private static final ImmutableMap DIMENSION_NAME = ImmutableMap.of( + DimensionWrapper.OVERWORLD, tr("createWorld.customize.preset.overworld"), + DimensionWrapper.THE_NETHER, tr("advancements.nether.root.title"), + DimensionWrapper.THE_END, tr("advancements.end.root.title") + ); + + public static BaseText dimension(DimensionWrapper dim) { + BaseText dimText = DIMENSION_NAME.get(dim); + return dimText != null ? copy(dimText) : Messenger.s(dim.getIdentifierString()); + } + + private static BaseText __coord(String style, @Nullable DimensionWrapper dim, String posStr, String command) { + BaseText hoverText = Messenger.s(""); + hoverText.append(getTeleportHint(Messenger.s(posStr))); + if (dim != null) { + hoverText.append("\n"); + hoverText.append(translator.tr("teleport_hint.dimension")); + hoverText.append(": "); + hoverText.append(dimension(dim)); + } + return fancy(style, Messenger.s(posStr), hoverText, new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)); + } + + public static BaseText coord(String style, Vec3d pos, DimensionWrapper dim) { + return __coord(style, dim, TextUtil.coord(pos), TextUtil.tp(pos, dim)); + } + + public static BaseText coord(String style, Vec3i pos, DimensionWrapper dim) { + return __coord(style, dim, TextUtil.coord(pos), TextUtil.tp(pos, dim)); + } + + public static BaseText coord(String style, ChunkPos pos, DimensionWrapper dim) { + return __coord(style, dim, TextUtil.coord(pos), TextUtil.tp(pos, dim)); + } + + public static BaseText coord(String style, Vec3d pos) { + return __coord(style, null, TextUtil.coord(pos), TextUtil.tp(pos)); + } + + public static BaseText coord(String style, Vec3i pos) { + return __coord(style, null, TextUtil.coord(pos), TextUtil.tp(pos)); + } + + public static BaseText coord(String style, ChunkPos pos) { + return __coord(style, null, TextUtil.coord(pos), TextUtil.tp(pos)); + } + + public static BaseText coord(Vec3d pos, DimensionWrapper dim) { + return coord(null, pos, dim); + } + + public static BaseText coord(Vec3i pos, DimensionWrapper dim) { + return coord(null, pos, dim); + } + + public static BaseText coord(ChunkPos pos, DimensionWrapper dim) { + return coord(null, pos, dim); + } + + public static BaseText coord(Vec3d pos) { + return coord(null, pos); + } + + public static BaseText coord(Vec3i pos) { + return coord(null, pos); + } + + public static BaseText coord(ChunkPos pos) { + return coord(null, pos); + } + + public static Style parseCarpetStyle(String style) { + return carpet.utils.Messenger.parseStyle(style); + } +} diff --git a/src/main/java/club/mcams/carpet/util/MixinUtil.java b/src/main/java/club/mcams/carpet/util/MixinUtil.java index 58e58770..238470d9 100644 --- a/src/main/java/club/mcams/carpet/util/MixinUtil.java +++ b/src/main/java/club/mcams/carpet/util/MixinUtil.java @@ -1,50 +1,50 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.util; - -import club.mcams.carpet.AmsServer; -import static club.mcams.carpet.util.Messenger.*; - -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.BaseText; - -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.MixinEnvironment; - -public class MixinUtil { - public static boolean audit(@Nullable ServerCommandSource source) { - boolean ok; - BaseText response; - try { - MixinEnvironment.getCurrentEnvironment().audit(); - response = s("Mixin environment audited successfully"); - ok = true; - } catch (Exception e) { - AmsServer.LOGGER.error("Error when auditing mixin", e); - response = Messenger.s(String.format("Mixin environment auditing failed, check console for more information (%s)", e)); - ok = false; - } - if (source != null) { - Messenger.tell(source, response); - } - return ok; - } +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.util; + +import club.mcams.carpet.AmsServer; +import static club.mcams.carpet.util.Messenger.*; + +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.BaseText; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.MixinEnvironment; + +public class MixinUtil { + public static boolean audit(@Nullable ServerCommandSource source) { + boolean ok; + BaseText response; + try { + MixinEnvironment.getCurrentEnvironment().audit(); + response = s("Mixin environment audited successfully"); + ok = true; + } catch (Exception e) { + AmsServer.LOGGER.error("Error when auditing mixin", e); + response = Messenger.s(String.format("Mixin environment auditing failed, check console for more information (%s)", e)); + ok = false; + } + if (source != null) { + Messenger.tell(source, response); + } + return ok; + } } \ No newline at end of file diff --git a/src/main/java/club/mcams/carpet/util/recipes/CraftingRule.java b/src/main/java/club/mcams/carpet/util/recipes/CraftingRule.java index e8e316a6..2b7f1141 100644 --- a/src/main/java/club/mcams/carpet/util/recipes/CraftingRule.java +++ b/src/main/java/club/mcams/carpet/util/recipes/CraftingRule.java @@ -1,37 +1,37 @@ -/* - * This file is part of the Carpet AMS Addition project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 A Minecraft Server and contributors - * - * Carpet AMS Addition is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Carpet AMS Addition is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Carpet AMS Addition. If not, see . - */ - -package club.mcams.carpet.util.recipes; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface CraftingRule { - - String name() default ""; - - String[] recipes(); - - String recipeNamespace() default "ams"; -} +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet AMS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.util.recipes; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface CraftingRule { + + String name() default ""; + + String[] recipes(); + + String recipeNamespace() default "ams"; +} diff --git a/src/main/resources/amscarpet.mixins.json b/src/main/resources/amscarpet.mixins.json index bd83b6a2..36f7261f 100644 --- a/src/main/resources/amscarpet.mixins.json +++ b/src/main/resources/amscarpet.mixins.json @@ -1,56 +1,56 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "club.mcams.carpet.mixin", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "carpet.SettingsManagerMixin", - "interaction.ThreadedAnvilChunkStorageMixin", - "rule.antiFireTotem_itemAntiExplosion.ItemEntityMixin", - "rule.bambooCollisionBoxDisable.BambooBlockMixin", - "rule.bambooModelNoOffset.BambooBlockMixin", - "rule.blockChunkLoader.BellBlockMixin", - "rule.blockChunkLoader.NoteBlockMixin", - "rule.blockChunkLoader.PistonBlockMixin", - "rule.blowUpEverything.GetBlastResistanceMixin", - "rule.boneBlockUpdateSuppressor.NeighborUpdateMixin", - "rule.creativeOneHitKill.EntityAccessorMixin", - "rule.creativeOneHitKill.PlayerEntityMixin", - "rule.creativeShulkerBoxDropsDisable.ShulkerBoxBlockMixin", - "rule.extinguishedCampfire_campfireSmokeParticleDisabled.GetPlacementStateMixin", - "rule.fakePeace.AbstractBlockStateMixin", - "rule.infiniteTrades.MerchantEntityMixin", - "rule.largeEnderChest.EnderChestBlockMixin", - "rule.largeEnderChest.PlayerEntityMixin", - "rule.largeEnderChest.SimpleInventoryAccessor", - "rule.movableBlocks.PistonBlockMixin", - "rule.netherWaterPlacement.DimensionTypeMixin", - "rule.optimizedDragonRespawn.BlockPatternTestTransformInvoker", - "rule.optimizedDragonRespawn.EnderDragonFightMixin", - "rule.safeFlight_safeVoid_invulnerable.ServerPlayerEntityMixin", - "rule.scheduledRandomTick.AbstractPlantPartBlockMixin", - "rule.scheduledRandomTick.BambooBlockMixin", - "rule.scheduledRandomTick.CactusBlockMixin", - "rule.scheduledRandomTick.ChorusFlowerBlockMixin", - "rule.scheduledRandomTick.SugarCaneBlockMixin", - "rule.sharedVillagerDiscounts.GetValueForInvoker", - "rule.sharedVillagerDiscounts.VillagerGossipsMixin", - "rule.softBlock.AbstractBlockStateMixin", - "rule.superBow.InfinityEnchantmentMixin", - "rule.weakBlocks.CollectBlocksAndDamageEntitiesMixin", - "setting.ParsedRuleAccessor", - "setting.SettingsManagerAccessor", - "translations.ClientSettingsC2SPacketAccessor", - "translations.HUDControllerMixin", - "translations.LoggerMixin", - "translations.ServerPlayerEntityMixin", - "translations.StyleAccessor", - "translations.TranslatableTextAccessor", - "translations.TranslatableTextMixin" - ], - "client": [], - "server": [], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "club.mcams.carpet.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "carpet.SettingsManagerMixin", + "interaction.ThreadedAnvilChunkStorageMixin", + "rule.antiFireTotem_itemAntiExplosion.ItemEntityMixin", + "rule.bambooCollisionBoxDisable.BambooBlockMixin", + "rule.bambooModelNoOffset.BambooBlockMixin", + "rule.blockChunkLoader.BellBlockMixin", + "rule.blockChunkLoader.NoteBlockMixin", + "rule.blockChunkLoader.PistonBlockMixin", + "rule.blowUpEverything.GetBlastResistanceMixin", + "rule.boneBlockUpdateSuppressor.NeighborUpdateMixin", + "rule.creativeOneHitKill.EntityAccessorMixin", + "rule.creativeOneHitKill.PlayerEntityMixin", + "rule.creativeShulkerBoxDropsDisable.ShulkerBoxBlockMixin", + "rule.extinguishedCampfire_campfireSmokeParticleDisabled.GetPlacementStateMixin", + "rule.fakePeace.AbstractBlockStateMixin", + "rule.infiniteTrades.MerchantEntityMixin", + "rule.largeEnderChest.EnderChestBlockMixin", + "rule.largeEnderChest.PlayerEntityMixin", + "rule.largeEnderChest.SimpleInventoryAccessor", + "rule.movableBlocks.PistonBlockMixin", + "rule.netherWaterPlacement.DimensionTypeMixin", + "rule.optimizedDragonRespawn.BlockPatternTestTransformInvoker", + "rule.optimizedDragonRespawn.EnderDragonFightMixin", + "rule.safeFlight_safeVoid_invulnerable.ServerPlayerEntityMixin", + "rule.scheduledRandomTick.AbstractPlantPartBlockMixin", + "rule.scheduledRandomTick.BambooBlockMixin", + "rule.scheduledRandomTick.CactusBlockMixin", + "rule.scheduledRandomTick.ChorusFlowerBlockMixin", + "rule.scheduledRandomTick.SugarCaneBlockMixin", + "rule.sharedVillagerDiscounts.GetValueForInvoker", + "rule.sharedVillagerDiscounts.VillagerGossipsMixin", + "rule.softBlock.AbstractBlockStateMixin", + "rule.superBow.InfinityEnchantmentMixin", + "rule.weakBlocks.CollectBlocksAndDamageEntitiesMixin", + "setting.ParsedRuleAccessor", + "setting.SettingsManagerAccessor", + "translations.ClientSettingsC2SPacketAccessor", + "translations.HUDControllerMixin", + "translations.LoggerMixin", + "translations.ServerPlayerEntityMixin", + "translations.StyleAccessor", + "translations.TranslatableTextAccessor", + "translations.TranslatableTextMixin" + ], + "client": [], + "server": [], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 04c0c8cd..a1b1520f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,31 +1,31 @@ -{ - "schemaVersion": 1, - "id": "${id}", - "version": "${version}", - "name": "${name}", - "description": "一个简陋的,东拼西凑的,及其不原版的Carpet拓展。", - "authors": [ - "1024_byteeeee", - "WenDavid", - "···" - ], - "contact": { - "homepage": "https://mcams.club/", - "sources": "https://mcams.club/" - }, - "license": "LGPL-3.0", - "icon": "assets/carpetamsaddition/icon.png", - "environment": "*", - "entrypoints": { - "main": [ - "club.mcams.carpet.AmsServerMod" - ] - }, - "mixins": [ - "amscarpet.mixins.json" - ], - "depends": { - "minecraft": "${minecraft_dependency}", - "carpet": "${carpet_dependency}" - } -} +{ + "schemaVersion": 1, + "id": "${id}", + "version": "${version}", + "name": "${name}", + "description": "一个简陋的,东拼西凑的,及其不原版的Carpet拓展。", + "authors": [ + "1024_byteeeee", + "WenDavid", + "···" + ], + "contact": { + "homepage": "https://mcams.club/", + "sources": "https://mcams.club/" + }, + "license": "LGPL-3.0", + "icon": "assets/carpetamsaddition/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "club.mcams.carpet.AmsServerMod" + ] + }, + "mixins": [ + "amscarpet.mixins.json" + ], + "depends": { + "minecraft": "${minecraft_dependency}", + "carpet": "${carpet_dependency}" + } +} diff --git a/versions/1.16.5/gradle.properties b/versions/1.16.5/gradle.properties index 6946e275..7a9f59da 100644 --- a/versions/1.16.5/gradle.properties +++ b/versions/1.16.5/gradle.properties @@ -1,17 +1,16 @@ -# Fabric Properties -# check these on https://fabricmc.net/versions.html?&version=1.16.5 -minecraft_version = 1.16.5 -yarn_mappings = 1.16.5+build.10 - -# Fabric Mod Metadata -carpet_dependency = >=1.4.38 -minecraft_dependency = 1.16.5 - -# Build Infomation -game_versions = 1.16.4\n1.16.5 - -# Mod Dependency -# check available versions on maven for the given minecraft version you are using -# https://masa.dy.fi/maven/carpet/fabric-carpet/ -carpet_core_version = 1.16.5-1.4.44+v210714 - +# Fabric Properties +# check these on https://fabricmc.net/versions.html?&version=1.16.5 +minecraft_version = 1.16.5 +yarn_mappings = 1.16.5+build.10 + +# Fabric Mod Metadata +carpet_dependency = >=1.4.38 +minecraft_dependency = 1.16.5 + +# Build Infomation +game_versions = 1.16.4\n1.16.5 + +# Mod Dependency +# check available versions on maven for the given minecraft version you are using +# https://masa.dy.fi/maven/carpet/fabric-carpet/ +carpet_core_version = 1.16.5-1.4.44+v210714 \ No newline at end of file diff --git a/versions/1.17.1/gradle.properties b/versions/1.17.1/gradle.properties index ebb5efec..8fe970a5 100644 --- a/versions/1.17.1/gradle.properties +++ b/versions/1.17.1/gradle.properties @@ -1,17 +1,16 @@ -# Fabric Properties -# check these on https://fabricmc.net/versions.html?&version=1.17.1 -minecraft_version = 1.17.1 -yarn_mappings = 1.17.1+build.65 - -# Fabric Mod Metadata -carpet_dependency = >=1.4.56 -minecraft_dependency = 1.17.1 - -# Build Infomation -game_versions = 1.17.1 - -# Mod Dependency -# check available versions on maven for the given minecraft version you are using -# https://masa.dy.fi/maven/carpet/fabric-carpet/ -carpet_core_version = 1.17.1-1.4.57+v220119 - +# Fabric Properties +# check these on https://fabricmc.net/versions.html?&version=1.17.1 +minecraft_version = 1.17.1 +yarn_mappings = 1.17.1+build.65 + +# Fabric Mod Metadata +carpet_dependency = >=1.4.56 +minecraft_dependency = 1.17.1 + +# Build Infomation +game_versions = 1.17.1 + +# Mod Dependency +# check available versions on maven for the given minecraft version you are using +# https://masa.dy.fi/maven/carpet/fabric-carpet/ +carpet_core_version = 1.17.1-1.4.57+v220119 \ No newline at end of file diff --git a/versions/1.18.2/gradle.properties b/versions/1.18.2/gradle.properties index 3ed3710b..23c11c3a 100644 --- a/versions/1.18.2/gradle.properties +++ b/versions/1.18.2/gradle.properties @@ -1,17 +1,16 @@ -# Fabric Properties -# check these on https://fabricmc.net/versions.html?&version=1.18.2 -minecraft_version = 1.18.2 -yarn_mappings = 1.18.2+build.4 - -# Fabric Mod Metadata -carpet_dependency = >=1.4.56 -minecraft_dependency = 1.18.2 - -# Build Infomation -game_versions = 1.18.2 - -# Mod Dependency -# check available versions on maven for the given minecraft version you are using -# https://masa.dy.fi/maven/carpet/fabric-carpet/ -carpet_core_version = 1.18.2-1.4.69+v220331 - +# Fabric Properties +# check these on https://fabricmc.net/versions.html?&version=1.18.2 +minecraft_version = 1.18.2 +yarn_mappings = 1.18.2+build.4 + +# Fabric Mod Metadata +carpet_dependency = >=1.4.56 +minecraft_dependency = 1.18.2 + +# Build Infomation +game_versions = 1.18.2 + +# Mod Dependency +# check available versions on maven for the given minecraft version you are using +# https://masa.dy.fi/maven/carpet/fabric-carpet/ +carpet_core_version = 1.18.2-1.4.69+v220331 \ No newline at end of file diff --git a/versions/mapping-1.17-1.16.txt b/versions/mapping-1.17-1.16.txt index 53320842..b7c13af0 100644 --- a/versions/mapping-1.17-1.16.txt +++ b/versions/mapping-1.17-1.16.txt @@ -1,3 +1,3 @@ -com.google.gson.JsonParser parseReader() com.google.gson.JsonParser parse() - +com.google.gson.JsonParser parseReader() com.google.gson.JsonParser parse() + net.minecraft.server.command.ReloadCommand tryReloadDataPacks() method_29480() \ No newline at end of file diff --git a/versions/mapping-1.18-1.17.txt b/versions/mapping-1.18-1.17.txt index 8af389f7..de5fc359 100644 --- a/versions/mapping-1.18-1.17.txt +++ b/versions/mapping-1.18-1.17.txt @@ -1,6 +1,6 @@ -net.minecraft.world.tick.OrderedTick net.minecraft.world.ScheduledTick -net.minecraft.world.tick.OrderedTick type() net.minecraft.world.ScheduledTick getObject() -block() net.minecraft.server.world.BlockEvent getBlock() -data() net.minecraft.server.world.BlockEvent getData() -pos() net.minecraft.server.world.BlockEvent getPos() +net.minecraft.world.tick.OrderedTick net.minecraft.world.ScheduledTick +net.minecraft.world.tick.OrderedTick type() net.minecraft.world.ScheduledTick getObject() +block() net.minecraft.server.world.BlockEvent getBlock() +data() net.minecraft.server.world.BlockEvent getData() +pos() net.minecraft.server.world.BlockEvent getPos() type() net.minecraft.server.world.BlockEvent getType() \ No newline at end of file diff --git a/versions/mapping-1.18-1.19.txt b/versions/mapping-1.18-1.19.txt index c91d642e..89e82322 100644 --- a/versions/mapping-1.18-1.19.txt +++ b/versions/mapping-1.18-1.19.txt @@ -1,12 +1,12 @@ -carpet.settings.ParsedRule carpet.api.settings.CarpetRule -carpet.settings.ParsedRule get() carpet.api.settings.CarpetRule value() -carpet.settings.RuleCategory carpet.api.settings.RuleCategory -carpet.settings.SettingsManager carpet.api.settings.SettingsManager -carpet.settings.Validator carpet.api.settings.Validator -carpet.api.settings.SettingsManager getRule() carpet.api.settings.SettingsManager getCarpetRule() -carpet.CarpetServer.settingsManager addRuleObserver() carpet.api.settings.SettingsManager registerRuleObserver() - -carpet.script.bundled.BundledModule carpet.script.Module - -net.minecraft.text.BaseText net.minecraft.text.MutableText +carpet.settings.ParsedRule carpet.api.settings.CarpetRule +carpet.settings.ParsedRule get() carpet.api.settings.CarpetRule value() +carpet.settings.RuleCategory carpet.api.settings.RuleCategory +carpet.settings.SettingsManager carpet.api.settings.SettingsManager +carpet.settings.Validator carpet.api.settings.Validator +carpet.api.settings.SettingsManager getRule() carpet.api.settings.SettingsManager getCarpetRule() +carpet.CarpetServer.settingsManager addRuleObserver() carpet.api.settings.SettingsManager registerRuleObserver() + +carpet.script.bundled.BundledModule carpet.script.Module + +net.minecraft.text.BaseText net.minecraft.text.MutableText net.minecraft.world.dimension.DimensionType isUltrawarm() ultrawarm() \ No newline at end of file