diff --git a/src/main/java/com/le/teleportmirror/Config.java b/src/main/java/com/le/teleportmirror/Config.java index e23988d..1b97a47 100644 --- a/src/main/java/com/le/teleportmirror/Config.java +++ b/src/main/java/com/le/teleportmirror/Config.java @@ -32,12 +32,8 @@ public class Config { .define("allowCrossDimension.permanent", true); public static final ModConfigSpec.BooleanValue TELEPORT_TEAM_ONLY = BUILDER - .comment("Teleport Mirror can only target players on the same team object") - .define("teleportTeamOnly", true); - - public static final ModConfigSpec.BooleanValue TELEPORT_SAME_TEAM_ONLY = BUILDER - .comment("Teleport Mirror can only target players with the same team name (team tag). Default: off.") - .define("teleportSameTeamOnly", false); + .comment("Teleport Mirror can only target players with the same team name (team tag).") + .define("teleportTeamOnly", false); public static final ModConfigSpec.IntValue BASIC_DURABILITY = BUILDER .comment("Durability for Basic tier mirrors") @@ -51,21 +47,37 @@ public class Config { .comment("Durability for Advanced tier mirrors") .defineInRange("advancedDurability", 100, 0, Integer.MAX_VALUE); - public static final ModConfigSpec.ConfigValue FOOD_COST_BASIC = BUILDER - .comment("Food cost for Basic tier mirrors. \"50%\" = 50% of current food. \"10\" = fixed 10 half-shanks. Empty \"\" = no cost.") - .define("foodCost.basic", "50%"); + public static final ModConfigSpec.ConfigValue FOOD_LEVEL_BASIC = BUILDER + .comment("Food level cost for Basic tier mirrors (half-shanks). \"50%\"=percentage, \"10\"=fixed, \"\"=none.") + .define("foodCost.basic.foodLevel", "50%"); - public static final ModConfigSpec.ConfigValue FOOD_COST_INTERMEDIATE = BUILDER - .comment("Food cost for Intermediate tier mirrors. \"50%\" = 50% of current food. \"10\" = fixed 10 half-shanks. Empty \"\" = no cost.") - .define("foodCost.intermediate", "50%"); + public static final ModConfigSpec.ConfigValue SATURATION_COST_BASIC = BUILDER + .comment("Saturation cost for Basic tier mirrors. \"50%\"=percentage, \"4.0\"=fixed, \"\"=none.") + .define("foodCost.basic.saturation", "50%"); - public static final ModConfigSpec.ConfigValue FOOD_COST_ADVANCED = BUILDER - .comment("Food cost for Advanced tier mirrors. \"50%\" = 50% of current food. \"10\" = fixed 10 half-shanks. Empty \"\" = no cost.") - .define("foodCost.advanced", "50%"); + public static final ModConfigSpec.ConfigValue FOOD_LEVEL_INTERMEDIATE = BUILDER + .comment("Food level cost for Intermediate tier mirrors (half-shanks). \"50%\"=percentage, \"10\"=fixed, \"\"=none.") + .define("foodCost.intermediate.foodLevel", "50%"); - public static final ModConfigSpec.ConfigValue FOOD_COST_PERMANENT = BUILDER - .comment("Food cost for Permanent tier mirrors. \"50%\" = 50% of current food. \"10\" = fixed 10 half-shanks. Empty \"\" = no cost.") - .define("foodCost.permanent", ""); + public static final ModConfigSpec.ConfigValue SATURATION_COST_INTERMEDIATE = BUILDER + .comment("Saturation cost for Intermediate tier mirrors. \"50%\"=percentage, \"4.0\"=fixed, \"\"=none.") + .define("foodCost.intermediate.saturation", "50%"); + + public static final ModConfigSpec.ConfigValue FOOD_LEVEL_ADVANCED = BUILDER + .comment("Food level cost for Advanced tier mirrors (half-shanks). \"50%\"=percentage, \"10\"=fixed, \"\"=none.") + .define("foodCost.advanced.foodLevel", "50%"); + + public static final ModConfigSpec.ConfigValue SATURATION_COST_ADVANCED = BUILDER + .comment("Saturation cost for Advanced tier mirrors. \"50%\"=percentage, \"4.0\"=fixed, \"\"=none.") + .define("foodCost.advanced.saturation", "50%"); + + public static final ModConfigSpec.ConfigValue FOOD_LEVEL_PERMANENT = BUILDER + .comment("Food level cost for Permanent tier mirrors (half-shanks). \"50%\"=percentage, \"10\"=fixed, \"\"=none.") + .define("foodCost.permanent.foodLevel", ""); + + public static final ModConfigSpec.ConfigValue SATURATION_COST_PERMANENT = BUILDER + .comment("Saturation cost for Permanent tier mirrors. \"50%\"=percentage, \"4.0\"=fixed, \"\"=none.") + .define("foodCost.permanent.saturation", ""); public static final ModConfigSpec.ConfigValue EFFECTS_RETURN_BASIC = BUILDER .comment("Effects for Basic Return Mirror. Format: \"effect_id,dur_sec,amplifier;...\"") diff --git a/src/main/java/com/le/teleportmirror/MirrorItem.java b/src/main/java/com/le/teleportmirror/MirrorItem.java index f5ca204..aaa2c85 100644 --- a/src/main/java/com/le/teleportmirror/MirrorItem.java +++ b/src/main/java/com/le/teleportmirror/MirrorItem.java @@ -191,12 +191,21 @@ public class MirrorItem extends Item { }; } - private String getFoodCostConfig() { + private String getFoodLevelConfig() { return switch (tier) { - case BASIC -> Config.FOOD_COST_BASIC.get(); - case INTERMEDIATE -> Config.FOOD_COST_INTERMEDIATE.get(); - case ADVANCED -> Config.FOOD_COST_ADVANCED.get(); - case PERMANENT -> Config.FOOD_COST_PERMANENT.get(); + case BASIC -> Config.FOOD_LEVEL_BASIC.get(); + case INTERMEDIATE -> Config.FOOD_LEVEL_INTERMEDIATE.get(); + case ADVANCED -> Config.FOOD_LEVEL_ADVANCED.get(); + case PERMANENT -> Config.FOOD_LEVEL_PERMANENT.get(); + }; + } + + private String getSaturationConfig() { + return switch (tier) { + case BASIC -> Config.SATURATION_COST_BASIC.get(); + case INTERMEDIATE -> Config.SATURATION_COST_INTERMEDIATE.get(); + case ADVANCED -> Config.SATURATION_COST_ADVANCED.get(); + case PERMANENT -> Config.SATURATION_COST_PERMANENT.get(); }; } @@ -237,28 +246,27 @@ public class MirrorItem extends Item { } private void applyFoodCost(Player player) { - String config = getFoodCostConfig(); + FoodData foodData = player.getFoodData(); + applyCostValue(getFoodLevelConfig(), (float) foodData.getFoodLevel(), newVal -> foodData.setFoodLevel(newVal.intValue())); + applyCostValue(getSaturationConfig(), foodData.getSaturationLevel(), newVal -> foodData.setSaturation(newVal)); + } + + private void applyCostValue(String config, float currentValue, java.util.function.Consumer setter) { if (config == null || config.isBlank()) { return; } - - FoodData foodData = player.getFoodData(); String trimmed = config.trim(); - if (trimmed.endsWith("%")) { String pctStr = trimmed.substring(0, trimmed.length() - 1); try { float percentage = Float.parseFloat(pctStr) / 100f; - int cost = Math.round(foodData.getFoodLevel() * percentage); - foodData.setFoodLevel(Math.max(0, foodData.getFoodLevel() - cost)); - foodData.setSaturation(Math.max(0, foodData.getSaturationLevel() * (1f - percentage))); + setter.accept(Math.max(0, currentValue * (1f - percentage))); } catch (NumberFormatException ignored) { } } else { try { - int cost = Integer.parseInt(trimmed); - foodData.setFoodLevel(Math.max(0, foodData.getFoodLevel() - cost)); - foodData.setSaturation(Math.max(0, foodData.getSaturationLevel() - cost)); + float cost = Float.parseFloat(trimmed); + setter.accept(Math.max(0, currentValue - cost)); } catch (NumberFormatException ignored) { } } diff --git a/src/main/java/com/le/teleportmirror/MirrorNetwork.java b/src/main/java/com/le/teleportmirror/MirrorNetwork.java index 0b2bc7e..2967607 100644 --- a/src/main/java/com/le/teleportmirror/MirrorNetwork.java +++ b/src/main/java/com/le/teleportmirror/MirrorNetwork.java @@ -39,18 +39,12 @@ public class MirrorNetwork { List names = new ArrayList<>(); List uuids = new ArrayList<>(); boolean teamOnly = Config.TELEPORT_TEAM_ONLY.get(); - boolean sameTeamOnly = Config.TELEPORT_SAME_TEAM_ONLY.get(); for (ServerPlayer onlinePlayer : player.server.getPlayerList().getPlayers()) { if (onlinePlayer.getUUID().equals(player.getUUID())) { continue; } - if (teamOnly && player.getTeam() != null) { - if (onlinePlayer.getTeam() != player.getTeam()) { - continue; - } - } - if (sameTeamOnly) { + if (teamOnly) { var playerTeam = player.getTeam(); var targetTeam = onlinePlayer.getTeam(); if (playerTeam == null || targetTeam == null) {