refactor: remove old team-object filter, split food cost into foodLevel and saturation
Some checks failed
Build / build (push) Has been cancelled
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:
@@ -32,12 +32,8 @@ public class Config {
|
|||||||
.define("allowCrossDimension.permanent", true);
|
.define("allowCrossDimension.permanent", true);
|
||||||
|
|
||||||
public static final ModConfigSpec.BooleanValue TELEPORT_TEAM_ONLY = BUILDER
|
public static final ModConfigSpec.BooleanValue TELEPORT_TEAM_ONLY = BUILDER
|
||||||
.comment("Teleport Mirror can only target players on the same team object")
|
.comment("Teleport Mirror can only target players with the same team name (team tag).")
|
||||||
.define("teleportTeamOnly", true);
|
.define("teleportTeamOnly", false);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
public static final ModConfigSpec.IntValue BASIC_DURABILITY = BUILDER
|
public static final ModConfigSpec.IntValue BASIC_DURABILITY = BUILDER
|
||||||
.comment("Durability for Basic tier mirrors")
|
.comment("Durability for Basic tier mirrors")
|
||||||
@@ -51,21 +47,37 @@ public class Config {
|
|||||||
.comment("Durability for Advanced tier mirrors")
|
.comment("Durability for Advanced tier mirrors")
|
||||||
.defineInRange("advancedDurability", 100, 0, Integer.MAX_VALUE);
|
.defineInRange("advancedDurability", 100, 0, Integer.MAX_VALUE);
|
||||||
|
|
||||||
public static final ModConfigSpec.ConfigValue<String> FOOD_COST_BASIC = BUILDER
|
public static final ModConfigSpec.ConfigValue<String> FOOD_LEVEL_BASIC = BUILDER
|
||||||
.comment("Food cost for Basic tier mirrors. \"50%\" = 50% of current food. \"10\" = fixed 10 half-shanks. Empty \"\" = no cost.")
|
.comment("Food level cost for Basic tier mirrors (half-shanks). \"50%\"=percentage, \"10\"=fixed, \"\"=none.")
|
||||||
.define("foodCost.basic", "50%");
|
.define("foodCost.basic.foodLevel", "50%");
|
||||||
|
|
||||||
public static final ModConfigSpec.ConfigValue<String> FOOD_COST_INTERMEDIATE = BUILDER
|
public static final ModConfigSpec.ConfigValue<String> SATURATION_COST_BASIC = BUILDER
|
||||||
.comment("Food cost for Intermediate tier mirrors. \"50%\" = 50% of current food. \"10\" = fixed 10 half-shanks. Empty \"\" = no cost.")
|
.comment("Saturation cost for Basic tier mirrors. \"50%\"=percentage, \"4.0\"=fixed, \"\"=none.")
|
||||||
.define("foodCost.intermediate", "50%");
|
.define("foodCost.basic.saturation", "50%");
|
||||||
|
|
||||||
public static final ModConfigSpec.ConfigValue<String> FOOD_COST_ADVANCED = BUILDER
|
public static final ModConfigSpec.ConfigValue<String> FOOD_LEVEL_INTERMEDIATE = BUILDER
|
||||||
.comment("Food cost for Advanced tier mirrors. \"50%\" = 50% of current food. \"10\" = fixed 10 half-shanks. Empty \"\" = no cost.")
|
.comment("Food level cost for Intermediate tier mirrors (half-shanks). \"50%\"=percentage, \"10\"=fixed, \"\"=none.")
|
||||||
.define("foodCost.advanced", "50%");
|
.define("foodCost.intermediate.foodLevel", "50%");
|
||||||
|
|
||||||
public static final ModConfigSpec.ConfigValue<String> FOOD_COST_PERMANENT = BUILDER
|
public static final ModConfigSpec.ConfigValue<String> SATURATION_COST_INTERMEDIATE = BUILDER
|
||||||
.comment("Food cost for Permanent tier mirrors. \"50%\" = 50% of current food. \"10\" = fixed 10 half-shanks. Empty \"\" = no cost.")
|
.comment("Saturation cost for Intermediate tier mirrors. \"50%\"=percentage, \"4.0\"=fixed, \"\"=none.")
|
||||||
.define("foodCost.permanent", "");
|
.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
|
public static final ModConfigSpec.ConfigValue<String> EFFECTS_RETURN_BASIC = BUILDER
|
||||||
.comment("Effects for Basic Return Mirror. Format: \"effect_id,dur_sec,amplifier;...\"")
|
.comment("Effects for Basic Return Mirror. Format: \"effect_id,dur_sec,amplifier;...\"")
|
||||||
|
|||||||
@@ -191,12 +191,21 @@ public class MirrorItem extends Item {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFoodCostConfig() {
|
private String getFoodLevelConfig() {
|
||||||
return switch (tier) {
|
return switch (tier) {
|
||||||
case BASIC -> Config.FOOD_COST_BASIC.get();
|
case BASIC -> Config.FOOD_LEVEL_BASIC.get();
|
||||||
case INTERMEDIATE -> Config.FOOD_COST_INTERMEDIATE.get();
|
case INTERMEDIATE -> Config.FOOD_LEVEL_INTERMEDIATE.get();
|
||||||
case ADVANCED -> Config.FOOD_COST_ADVANCED.get();
|
case ADVANCED -> Config.FOOD_LEVEL_ADVANCED.get();
|
||||||
case PERMANENT -> Config.FOOD_COST_PERMANENT.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) {
|
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()) {
|
if (config == null || config.isBlank()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FoodData foodData = player.getFoodData();
|
|
||||||
String trimmed = config.trim();
|
String trimmed = config.trim();
|
||||||
|
|
||||||
if (trimmed.endsWith("%")) {
|
if (trimmed.endsWith("%")) {
|
||||||
String pctStr = trimmed.substring(0, trimmed.length() - 1);
|
String pctStr = trimmed.substring(0, trimmed.length() - 1);
|
||||||
try {
|
try {
|
||||||
float percentage = Float.parseFloat(pctStr) / 100f;
|
float percentage = Float.parseFloat(pctStr) / 100f;
|
||||||
int cost = Math.round(foodData.getFoodLevel() * percentage);
|
setter.accept(Math.max(0, currentValue * (1f - percentage)));
|
||||||
foodData.setFoodLevel(Math.max(0, foodData.getFoodLevel() - cost));
|
|
||||||
foodData.setSaturation(Math.max(0, foodData.getSaturationLevel() * (1f - percentage)));
|
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int cost = Integer.parseInt(trimmed);
|
float cost = Float.parseFloat(trimmed);
|
||||||
foodData.setFoodLevel(Math.max(0, foodData.getFoodLevel() - cost));
|
setter.accept(Math.max(0, currentValue - cost));
|
||||||
foodData.setSaturation(Math.max(0, foodData.getSaturationLevel() - cost));
|
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,18 +39,12 @@ public class MirrorNetwork {
|
|||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
List<UUID> uuids = new ArrayList<>();
|
List<UUID> uuids = new ArrayList<>();
|
||||||
boolean teamOnly = Config.TELEPORT_TEAM_ONLY.get();
|
boolean teamOnly = Config.TELEPORT_TEAM_ONLY.get();
|
||||||
boolean sameTeamOnly = Config.TELEPORT_SAME_TEAM_ONLY.get();
|
|
||||||
|
|
||||||
for (ServerPlayer onlinePlayer : player.server.getPlayerList().getPlayers()) {
|
for (ServerPlayer onlinePlayer : player.server.getPlayerList().getPlayers()) {
|
||||||
if (onlinePlayer.getUUID().equals(player.getUUID())) {
|
if (onlinePlayer.getUUID().equals(player.getUUID())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (teamOnly && player.getTeam() != null) {
|
if (teamOnly) {
|
||||||
if (onlinePlayer.getTeam() != player.getTeam()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sameTeamOnly) {
|
|
||||||
var playerTeam = player.getTeam();
|
var playerTeam = player.getTeam();
|
||||||
var targetTeam = onlinePlayer.getTeam();
|
var targetTeam = onlinePlayer.getTeam();
|
||||||
if (playerTeam == null || targetTeam == null) {
|
if (playerTeam == null || targetTeam == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user