9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

添加显示掉落物名称

This commit is contained in:
XiaoMoMi
2025-12-06 00:58:17 +08:00
parent 5395dc4ea9
commit 465eebe15a
7 changed files with 183 additions and 3 deletions

View File

@@ -49,6 +49,10 @@ public class ItemSettings {
Color fireworkColor;
float keepOnDeathChance = 0f;
float destroyOnDeathChance = 0f;
@Nullable
String dropDisplay = Config.defaultDropDisplayFormat();
@Nullable
LegacyChatFormatter glowColor = null;
Map<CustomDataType<?>, Object> customData = new IdentityHashMap<>(4);
private ItemSettings() {}
@@ -113,6 +117,8 @@ public class ItemSettings {
newSettings.ingredientSubstitutes = settings.ingredientSubstitutes;
newSettings.keepOnDeathChance = settings.keepOnDeathChance;
newSettings.destroyOnDeathChance = settings.destroyOnDeathChance;
newSettings.glowColor = settings.glowColor;
newSettings.dropDisplay = settings.dropDisplay;
newSettings.customData = new IdentityHashMap<>(settings.customData);
return newSettings;
}
@@ -243,6 +249,16 @@ public class ItemSettings {
return this.destroyOnDeathChance;
}
@Nullable
public LegacyChatFormatter glowColor() {
return this.glowColor;
}
@Nullable
public String dropDisplay() {
return this.dropDisplay;
}
public ItemSettings fireworkColor(Color color) {
this.fireworkColor = color;
return this;
@@ -293,6 +309,11 @@ public class ItemSettings {
return this;
}
public ItemSettings dropDisplay(String showName) {
this.dropDisplay = showName;
return this;
}
public ItemSettings projectileMeta(ProjectileMeta projectileMeta) {
this.projectileMeta = projectileMeta;
return this;
@@ -353,6 +374,11 @@ public class ItemSettings {
return this;
}
public ItemSettings glowColor(LegacyChatFormatter chatFormatter) {
this.glowColor = chatFormatter;
return this;
}
@FunctionalInterface
public interface Modifier {
@@ -395,6 +421,18 @@ public class ItemSettings {
boolean bool = ResourceConfigUtils.getAsBoolean(value, "renameable");
return settings -> settings.renameable(bool);
}));
registerFactory("drop-display", (value -> {
if (value instanceof String name) {
return settings -> settings.dropDisplay(name);
} else {
boolean bool = ResourceConfigUtils.getAsBoolean(value, "drop-display");
return settings -> settings.dropDisplay(bool ? "" : null);
}
}));
registerFactory("glow-color", (value -> {
LegacyChatFormatter chatFormatter = ResourceConfigUtils.getAsEnum(value, LegacyChatFormatter.class, LegacyChatFormatter.WHITE);
return settings -> settings.glowColor(chatFormatter);
}));
registerFactory("anvil-repair-item", (value -> {
List<AnvilRepairItem> anvilRepairItemList = ResourceConfigUtils.parseConfigAsList(value, material -> {
int amount = ResourceConfigUtils.getAsInt(material.getOrDefault("amount", 0), "amount");

View File

@@ -193,6 +193,8 @@ public class Config {
protected Map<Key, Integer> item$custom_model_data_starting_value$overrides;
protected boolean item$always_use_item_model;
protected String item$default_material = "";
protected boolean item$default_drop_display$enable = false;
protected String item$default_drop_display$format = null;
protected String equipment$sacrificed_vanilla_armor$type;
protected Key equipment$sacrificed_vanilla_armor$asset_id;
@@ -471,6 +473,8 @@ public class Config {
item$custom_model_data_starting_value$default = config.getInt("item.custom-model-data-starting-value.default", 10000);
item$always_use_item_model = config.getBoolean("item.always-use-item-model", true) && VersionHelper.isOrAbove1_21_2();
item$default_material = config.getString("item.default-material", "");
item$default_drop_display$enable = config.getBoolean("item.default-drop-display.enable", false);
item$default_drop_display$format = item$default_drop_display$enable ? config.getString("item.default-drop-display.format", "<arg:count>x <name>"): null;
Section customModelDataOverridesSection = config.getSection("item.custom-model-data-starting-value.overrides");
if (customModelDataOverridesSection != null) {
@@ -1175,6 +1179,14 @@ public class Config {
return instance.resource_pack$optimization$texture$zopfli_iterations;
}
public static boolean enableDefaultDropDisplay() {
return instance.item$default_drop_display$enable;
}
public static String defaultDropDisplayFormat() {
return instance.item$default_drop_display$format;
}
public static boolean enableEntityCulling() {
return instance.client_optimization$entity_culling$enable;
}

View File

@@ -0,0 +1,34 @@
package net.momirealms.craftengine.core.plugin.text.minimessage;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.ParsingException;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CustomTagResolver implements TagResolver {
private final String name;
private final Component replacement;
public CustomTagResolver(String name, Component replacement) {
this.name = name;
this.replacement = replacement;
}
@Override
@Nullable
public Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException {
if (!has(name)) {
return null;
}
return Tag.selfClosingInserting(this.replacement);
}
@Override
public boolean has(@NotNull String name) {
return this.name.equals(name);
}
}

View File

@@ -0,0 +1,26 @@
package net.momirealms.craftengine.core.util;
public enum LegacyChatFormatter {
BLACK,
DARK_BLUE,
DARK_GREEN,
DARK_AQUA,
DARK_RED,
DARK_PURPLE,
GOLD,
GRAY,
DARK_GRAY,
BLUE,
GREEN,
AQUA,
RED,
LIGHT_PURPLE,
YELLOW,
WHITE,
OBFUSCATED,
BOLD,
STRIKETHROUGH,
UNDERLINE,
ITALIC,
RESET;
}