mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-26 02:19:23 +00:00
改进伤害免疫
This commit is contained in:
@@ -35,7 +35,7 @@ public class ItemSettings {
|
||||
FoodData foodData = null;
|
||||
Key consumeReplacement = null;
|
||||
Key craftRemainder = null;
|
||||
List<DamageCause> invulnerable = List.of();
|
||||
List<DamageSource> invulnerable = List.of();
|
||||
|
||||
private ItemSettings() {}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class ItemSettings {
|
||||
return equipment;
|
||||
}
|
||||
|
||||
public List<DamageCause> invulnerable() {
|
||||
public List<DamageSource> invulnerable() {
|
||||
return invulnerable;
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class ItemSettings {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSettings invulnerable(List<DamageCause> invulnerable) {
|
||||
public ItemSettings invulnerable(List<DamageSource> invulnerable) {
|
||||
this.invulnerable = invulnerable;
|
||||
return this;
|
||||
}
|
||||
@@ -321,12 +321,12 @@ public class ItemSettings {
|
||||
return settings -> settings.foodData(data);
|
||||
}));
|
||||
registerFactory("invulnerable", (value -> {
|
||||
List<DamageCause> list = MiscUtils.getAsStringList(value).stream().map(it -> {
|
||||
try {
|
||||
return DamageCause.byName(it);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.settings.invulnerable-unknown", it);
|
||||
List<DamageSource> list = MiscUtils.getAsStringList(value).stream().map(it -> {
|
||||
DamageSource source = DamageSource.byName(it);
|
||||
if (source == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.settings.invulnerable.invalid_damage_source", it, EnumUtils.toString(DamageSource.values()));
|
||||
}
|
||||
return source;
|
||||
}).toList();
|
||||
return settings -> settings.invulnerable(list);
|
||||
}));
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum DamageCause {
|
||||
public enum DamageSource {
|
||||
BLOCK_EXPLOSION,
|
||||
CAMPFIRE,
|
||||
CONTACT,
|
||||
@@ -37,22 +39,19 @@ public enum DamageCause {
|
||||
THORNS,
|
||||
VOID,
|
||||
WITHER,
|
||||
WORLD_BORDER,
|
||||
@Deprecated
|
||||
@SuppressWarnings("all")
|
||||
DRAGON_BREATH;
|
||||
WORLD_BORDER;
|
||||
|
||||
public static final Map<String, DamageCause> BY_NAME = new HashMap<>();
|
||||
public static final Map<String, DamageSource> BY_NAME = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (DamageCause cause : values()) {
|
||||
BY_NAME.put(cause.name().toLowerCase(Locale.ROOT), cause);
|
||||
for (DamageSource cause : values()) {
|
||||
BY_NAME.put(cause.name().toLowerCase(Locale.ENGLISH), cause);
|
||||
BY_NAME.put(cause.name(), cause);
|
||||
}
|
||||
}
|
||||
|
||||
public static DamageCause byName(String name) {
|
||||
return Optional.ofNullable(BY_NAME.get(name)).orElseThrow(() -> new IllegalArgumentException("Unknown damage cause: " + name));
|
||||
@Nullable
|
||||
public static DamageSource byName(String name) {
|
||||
return BY_NAME.get(name);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user