mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
handle default food attributes better, fixes #1404
This commit is contained in:
@@ -69,10 +69,10 @@ index 31f5ed9dd1727eee24804a384817d2b76a45676b..5fbb13ebef0ca66419f3e5006d19e4a5
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
index fb029141ff0b12ca21d49769dc3a890787b630e9..81d672b7f3cdae0f887fb978327573285f326e8e 100644
|
||||
index fb029141ff0b12ca21d49769dc3a890787b630e9..64d56bdbe943a1d37a28c0d332e3acf258bf1fe5 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
@@ -464,4 +464,56 @@ public class PurpurConfig {
|
||||
@@ -464,4 +464,75 @@ public class PurpurConfig {
|
||||
String setPattern = getString("settings.username-valid-characters", defaultPattern);
|
||||
usernameValidCharactersPattern = java.util.regex.Pattern.compile(setPattern == null || setPattern.isBlank() ? defaultPattern : setPattern);
|
||||
}
|
||||
@@ -83,6 +83,17 @@ index fb029141ff0b12ca21d49769dc3a890787b630e9..81d672b7f3cdae0f887fb97832757328
|
||||
+ config.addDefault("settings.food-properties", new HashMap<>());
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ Map<MobEffect, Map<String, Object>> effectDefaults = new HashMap<>();
|
||||
+ Map<String, Object> EFFECT_DEFAULT = Map.of(
|
||||
+ "chance", 0.0F,
|
||||
+ "duration", 0,
|
||||
+ "amplifier", 0,
|
||||
+ "ambient", false,
|
||||
+ "visible", true,
|
||||
+ "show-icon", true
|
||||
+ );
|
||||
+
|
||||
+ properties.getKeys(false).forEach(foodKey -> {
|
||||
+ FoodProperties food = Foods.ALL_PROPERTIES.get(foodKey);
|
||||
+ if (food == null) {
|
||||
@@ -97,15 +108,17 @@ index fb029141ff0b12ca21d49769dc3a890787b630e9..81d672b7f3cdae0f887fb97832757328
|
||||
+ food.setFastFood(properties.getBoolean(foodKey + ".fast-food", foodDefaults.isFastFood()));
|
||||
+ ConfigurationSection effects = properties.getConfigurationSection(foodKey + ".effects");
|
||||
+ if (effects != null) {
|
||||
+ Map<String, Object> effectDefaults = new HashMap<>();
|
||||
+ effectDefaults.clear();
|
||||
+ foodDefaults.getEffects().forEach(pair -> {
|
||||
+ effectDefaults.put("chance", pair.getSecond());
|
||||
+ MobEffectInstance effect = pair.getFirst();
|
||||
+ effectDefaults.put("duration", effect.getDuration());
|
||||
+ effectDefaults.put("amplifier", effect.getAmplifier());
|
||||
+ effectDefaults.put("ambient", effect.isAmbient());
|
||||
+ effectDefaults.put("visible", effect.isVisible());
|
||||
+ effectDefaults.put("show-icon", effect.showIcon());
|
||||
+ effectDefaults.put(effect.getEffect(), Map.of(
|
||||
+ "chance", pair.getSecond(),
|
||||
+ "duration", effect.getDuration(),
|
||||
+ "amplifier", effect.getAmplifier(),
|
||||
+ "ambient", effect.isAmbient(),
|
||||
+ "visible", effect.isVisible(),
|
||||
+ "show-icon", effect.showIcon()
|
||||
+ ));
|
||||
+ });
|
||||
+ effects.getKeys(false).forEach(effectKey -> {
|
||||
+ MobEffect effect = BuiltInRegistries.MOB_EFFECT.get(new ResourceLocation(effectKey));
|
||||
@@ -113,16 +126,22 @@ index fb029141ff0b12ca21d49769dc3a890787b630e9..81d672b7f3cdae0f887fb97832757328
|
||||
+ PurpurConfig.log(Level.SEVERE, "Invalid food property effect for " + foodKey + ": " + effectKey);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ Map<String, Object> effectDefault = effectDefaults.get(effect);
|
||||
+ if (effectDefault == null) {
|
||||
+ effectDefault = EFFECT_DEFAULT;
|
||||
+ }
|
||||
+
|
||||
+ food.getEffects().removeIf(pair -> pair.getFirst().getEffect() == effect);
|
||||
+ float chance = (float) effects.getDouble(effectKey + ".chance", ((Float) effectDefaults.get("chance")).doubleValue());
|
||||
+ int duration = effects.getInt(effectKey + ".duration", (int) effectDefaults.get("duration"));
|
||||
+ float chance = (float) effects.getDouble(effectKey + ".chance", ((Float) effectDefault.get("chance")).doubleValue());
|
||||
+ int duration = effects.getInt(effectKey + ".duration", (int) effectDefault.get("duration"));
|
||||
+ if (chance <= 0.0F || duration < 0) {
|
||||
+ return;
|
||||
+ }
|
||||
+ int amplifier = effects.getInt(effectKey + ".amplifier", (int) effectDefaults.get("amplifier"));
|
||||
+ boolean ambient = effects.getBoolean(effectKey + ".ambient", (boolean) effectDefaults.get("ambient"));
|
||||
+ boolean visible = effects.getBoolean(effectKey + ".visible", (boolean) effectDefaults.get("visible"));
|
||||
+ boolean showIcon = effects.getBoolean(effectKey + ".show-icon", (boolean) effectDefaults.get("show-icon"));
|
||||
+ int amplifier = effects.getInt(effectKey + ".amplifier", (int) effectDefault.get("amplifier"));
|
||||
+ boolean ambient = effects.getBoolean(effectKey + ".ambient", (boolean) effectDefault.get("ambient"));
|
||||
+ boolean visible = effects.getBoolean(effectKey + ".visible", (boolean) effectDefault.get("visible"));
|
||||
+ boolean showIcon = effects.getBoolean(effectKey + ".show-icon", (boolean) effectDefault.get("show-icon"));
|
||||
+ food.getEffects().add(Pair.of(new MobEffectInstance(effect, duration, amplifier, ambient, visible, showIcon), chance));
|
||||
+ });
|
||||
+ }
|
||||
|
||||
@@ -65,10 +65,10 @@ index b2f7ed77758a6c0a38cebf9b38b32508b6496fcf..ac70ab790f73e35fd5ec880f5a884da9
|
||||
boolean flag1 = packet.getSlotNum() >= 1 && packet.getSlotNum() <= 45;
|
||||
boolean flag2 = itemstack.isEmpty() || itemstack.getDamageValue() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty();
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
index 14d7a9eca55160290644bbf840665a94441ca4b4..ef338c778a483355ff59d1f36ce2ccb85b93ae93 100644
|
||||
index 751067f369457b5a4ee43f90c8783a4a36c20138..aef6b0c3e83a90bd6373992410251eaa1c914fb1 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
@@ -547,4 +547,9 @@ public class PurpurConfig {
|
||||
@@ -566,4 +566,9 @@ public class PurpurConfig {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,10 +104,10 @@ index 31918fa2eb38e42a5ea5366e559f25ea9d7d59ae..15d8e9261a89da30529ac347462c5209
|
||||
if (context.hasParam(LootContextParams.LOOTING_MOD)) {
|
||||
i = context.getParamOrNull(LootContextParams.LOOTING_MOD);
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
index ef338c778a483355ff59d1f36ce2ccb85b93ae93..736768330a0c45051a20a039d4de35cb260e7611 100644
|
||||
index aef6b0c3e83a90bd6373992410251eaa1c914fb1..91ef20d68ad386a038aca0bfe3a5c23f90eeab0d 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
@@ -552,4 +552,9 @@ public class PurpurConfig {
|
||||
@@ -571,4 +571,9 @@ public class PurpurConfig {
|
||||
private static void fixNetworkSerializedCreativeItems() {
|
||||
fixNetworkSerializedItemsInCreative = getBoolean("settings.fix-network-serialized-items-in-creative", fixNetworkSerializedItemsInCreative);
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@ index ec6c63075306f9e5389e83641d2c8a82369ddc6b..0f16deddd8cbb506ef7886f57ae640a4
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
index 736768330a0c45051a20a039d4de35cb260e7611..a3ffc1b8bd8f471c088d1d8256d67a6e2048b065 100644
|
||||
index 91ef20d68ad386a038aca0bfe3a5c23f90eeab0d..4e664a3d93cf38f136c8c6b77f930ae6b00565d3 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
@@ -557,4 +557,19 @@ public class PurpurConfig {
|
||||
@@ -576,4 +576,19 @@ public class PurpurConfig {
|
||||
private static void fixProjectileLootingTransfer() {
|
||||
fixProjectileLootingTransfer = getBoolean("settings.fix-projectile-looting-transfer", fixProjectileLootingTransfer);
|
||||
}
|
||||
|
||||
@@ -54,10 +54,10 @@ index cfbe1dae76db76cf54a4f5d72aca72d5e893859e..74cb10230d459ac9f300a9d59af504d2
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
index a3ffc1b8bd8f471c088d1d8256d67a6e2048b065..ac85d0b2a836d44ebadd50b3c80de95a85ff7f61 100644
|
||||
index 4e664a3d93cf38f136c8c6b77f930ae6b00565d3..a4e2c4fd8a1f7c5d882565677e9cc8939f5d9337 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
@@ -572,4 +572,50 @@ public class PurpurConfig {
|
||||
@@ -591,4 +591,50 @@ public class PurpurConfig {
|
||||
block.explosionResistance = blastResistance.floatValue();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ index f0703302e7dbbda88de8c648d20d87c55ed9b1e0..a913ebabaa5f443afa987b972355a8f8
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
index 96d21b8600b31b955dcc47823688425a5b1ec624..b974b59d421cf97bc9547ea75fe4643d89639bc1 100644
|
||||
index ae992fdb613f8a60b5f068a32be4a2e0f64bfee3..f03aba5c25896677d9d37e3fa010590b1ab7e3b6 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
@@ -561,6 +561,16 @@ public class PurpurConfig {
|
||||
@@ -580,6 +580,16 @@ public class PurpurConfig {
|
||||
fixProjectileLootingTransfer = getBoolean("settings.fix-projectile-looting-transfer", fixProjectileLootingTransfer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user