refactor: remove old team-object filter, split food cost into foodLevel and saturation
Some checks failed
Build / build (push) Has been cancelled

teleportTeamOnly now uses team tag (name) comparison only

foodCost split into foodCost.xxx.foodLevel and foodCost.xxx.saturation, independently configurable

supports percentage and fixed value independently for each
This commit is contained in:
LiuEnder
2026-04-26 11:46:51 +08:00
parent f8e58cc2f1
commit c2e58fbf0e
3 changed files with 54 additions and 40 deletions

View File

@@ -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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> EFFECTS_RETURN_BASIC = BUILDER
.comment("Effects for Basic Return Mirror. Format: \"effect_id,dur_sec,amplifier;...\"")

View File

@@ -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<Float> 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) {
}
}

View File

@@ -39,18 +39,12 @@ public class MirrorNetwork {
List<String> names = new ArrayList<>();
List<UUID> 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) {