mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-06 15:52:03 +00:00
feat(item): 添加物品invulnerable设置
- 物品: hhh我无敌了
This commit is contained in:
@@ -12,10 +12,7 @@ import net.momirealms.craftengine.core.item.setting.Helmet;
|
||||
import net.momirealms.craftengine.core.pack.misc.EquipmentGeneration;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.sound.SoundData;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
@@ -37,6 +34,7 @@ public class ItemSettings {
|
||||
Helmet helmet = null;
|
||||
FoodData foodData = null;
|
||||
Key consumeReplacement = null;
|
||||
List<DamageCause> invulnerable = List.of();
|
||||
|
||||
private ItemSettings() {}
|
||||
|
||||
@@ -74,6 +72,7 @@ public class ItemSettings {
|
||||
newSettings.helmet = settings.helmet;
|
||||
newSettings.foodData = settings.foodData;
|
||||
newSettings.consumeReplacement = settings.consumeReplacement;
|
||||
newSettings.invulnerable = settings.invulnerable;
|
||||
return newSettings;
|
||||
}
|
||||
|
||||
@@ -141,6 +140,10 @@ public class ItemSettings {
|
||||
return equipment;
|
||||
}
|
||||
|
||||
public List<DamageCause> invulnerable() {
|
||||
return invulnerable;
|
||||
}
|
||||
|
||||
public ItemSettings repairItems(List<AnvilRepairItem> items) {
|
||||
this.anvilRepairItems = items;
|
||||
return this;
|
||||
@@ -201,6 +204,11 @@ public class ItemSettings {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSettings invulnerable(List<DamageCause> invulnerable) {
|
||||
this.invulnerable = invulnerable;
|
||||
return this;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Modifier {
|
||||
|
||||
@@ -293,6 +301,16 @@ 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);
|
||||
}
|
||||
}).toList();
|
||||
return settings -> settings.invulnerable(list);
|
||||
}));
|
||||
}
|
||||
|
||||
private static void registerFactory(String id, ItemSettings.Modifier.Factory factory) {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum DamageCause {
|
||||
BLOCK_EXPLOSION,
|
||||
CAMPFIRE,
|
||||
CONTACT,
|
||||
CRAMMING,
|
||||
CUSTOM,
|
||||
DROWNING,
|
||||
DRYOUT,
|
||||
ENTITY_ATTACK,
|
||||
ENTITY_EXPLOSION,
|
||||
ENTITY_SWEEP_ATTACK,
|
||||
FALL,
|
||||
FALLING_BLOCK,
|
||||
FIRE,
|
||||
FIRE_TICK,
|
||||
FLY_INTO_WALL,
|
||||
FREEZE,
|
||||
HOT_FLOOR,
|
||||
KILL,
|
||||
LAVA,
|
||||
LIGHTNING,
|
||||
MAGIC,
|
||||
MELTING,
|
||||
POISON,
|
||||
PROJECTILE,
|
||||
SONIC_BOOM,
|
||||
STARVATION,
|
||||
SUFFOCATION,
|
||||
SUICIDE,
|
||||
THORNS,
|
||||
VOID,
|
||||
WITHER,
|
||||
WORLD_BORDER,
|
||||
@Deprecated
|
||||
@SuppressWarnings("all")
|
||||
DRAGON_BREATH;
|
||||
|
||||
public static final Map<String, DamageCause> BY_NAME = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (DamageCause cause : values()) {
|
||||
BY_NAME.put(cause.name().toLowerCase(Locale.ROOT), 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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user