mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-26 02:19:23 +00:00
修复属性
This commit is contained in:
@@ -3595,6 +3595,10 @@ public final class CoreReflections {
|
||||
);
|
||||
|
||||
public static final Constructor<?> constructor$TrimPattern = requireNonNull(
|
||||
VersionHelper.isOrAbove1_21_5() ?
|
||||
ReflectionUtils.getConstructor(clazz$TrimPattern, clazz$ResourceLocation, clazz$Component, boolean.class) :
|
||||
VersionHelper.isOrAbove1_20_2() ?
|
||||
ReflectionUtils.getConstructor(clazz$TrimPattern, clazz$ResourceLocation, clazz$Holder, clazz$Component, boolean.class) :
|
||||
ReflectionUtils.getConstructor(clazz$TrimPattern, clazz$ResourceLocation, clazz$Holder, clazz$Component)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public final class MAttributeHolders {
|
||||
|
||||
private static Object getById(String id) {
|
||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ATTRIBUTE, rl);
|
||||
return FastNMS.INSTANCE.method$Registry$getHolderByResourceLocation(MBuiltInRegistries.ATTRIBUTE, rl);
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -138,9 +138,16 @@ resource-pack:
|
||||
resolution:
|
||||
type: merge_atlas
|
||||
|
||||
item:
|
||||
# Add a <!i> tag on item name and lore
|
||||
non-italic-tag: false
|
||||
equipment:
|
||||
# The sacrificed-vanilla-armor argument determines which vanilla armor gets completely removed (loses all its trims)
|
||||
# when you create new armor using trim types, freeing up a slot for your custom armor.
|
||||
sacrificed-vanilla-armor:
|
||||
type: chainmail
|
||||
# CraftEngine repurposes a vanilla armor's texture slot for custom armor trims.
|
||||
# To preserve the original look, it uses trim configurations to reconstruct the default appearance.
|
||||
asset-id: minecraft:chainmail
|
||||
humanoid: minecraft:trims/entity/humanoid/chainmail
|
||||
humanoid-leggings: minecraft:trims/entity/humanoid_leggings/chainmail
|
||||
|
||||
block:
|
||||
# Enables the sound system, which prevents the client from hearing some non-custom block sounds and improves the client experience.
|
||||
|
||||
@@ -90,13 +90,6 @@ public abstract class AbstractFurnitureManager implements FurnitureManager {
|
||||
}
|
||||
EnumMap<AnchorType, CustomFurniture.Placement> placements = new EnumMap<>(AnchorType.class);
|
||||
Object placementObj = section.get("placement");
|
||||
if (placementObj == null) {
|
||||
// 防呆
|
||||
if (section.containsKey("material")) {
|
||||
plugin.itemManager().parser().parseSection(pack, path, id, section);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Map<String, Object> placementMap = MiscUtils.castToMap(ResourceConfigUtils.requireNonNullOrThrow(placementObj, "warning.config.furniture.missing_placement"), false);
|
||||
if (placementMap.isEmpty()) {
|
||||
throw new LocalizedResourceConfigException("warning.config.furniture.missing_placement");
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.context.event.EventFunctions;
|
||||
import net.momirealms.craftengine.core.plugin.context.text.TextProvider;
|
||||
import net.momirealms.craftengine.core.plugin.context.text.TextProviders;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
@@ -44,6 +45,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
protected static final Map<Key, List<Holder<Key>>> VANILLA_ITEM_TAGS = new HashMap<>();
|
||||
|
||||
private final ItemParser itemParser;
|
||||
private final EquipmentParser equipmentParser;
|
||||
protected final Map<String, ExternalItemProvider<I>> externalItemProviders = new HashMap<>();
|
||||
protected final Map<String, Function<Object, ItemDataModifier<I>>> dataFunctions = new HashMap<>();
|
||||
protected final Map<Key, CustomItem<I>> customItems = new HashMap<>();
|
||||
@@ -61,6 +63,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
protected AbstractItemManager(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
this.itemParser = new ItemParser();
|
||||
this.equipmentParser = new EquipmentParser();
|
||||
this.registerFunctions();
|
||||
this.legacyOverrides = new HashMap<>();
|
||||
this.modernOverrides = new HashMap<>();
|
||||
@@ -74,7 +77,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
@Override
|
||||
public void registerDataType(Function<Object, ItemDataModifier<I>> factory, String... alias) {
|
||||
for (String a : alias) {
|
||||
dataFunctions.put(a, factory);
|
||||
this.dataFunctions.put(a, factory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,11 +90,11 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
protected void applyDataFunctions(Map<String, Object> dataSection, Consumer<ItemDataModifier<I>> consumer) {
|
||||
if (dataSection != null) {
|
||||
for (Map.Entry<String, Object> dataEntry : dataSection.entrySet()) {
|
||||
Optional.ofNullable(dataFunctions.get(dataEntry.getKey())).ifPresent(function -> {
|
||||
Optional.ofNullable(this.dataFunctions.get(dataEntry.getKey())).ifPresent(function -> {
|
||||
try {
|
||||
consumer.accept(function.apply(dataEntry.getValue()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
plugin.logger().warn("Invalid data format", e);
|
||||
this.plugin.logger().warn("Invalid data format", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -99,8 +102,8 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigParser parser() {
|
||||
return this.itemParser;
|
||||
public ConfigParser[] parsers() {
|
||||
return new ConfigParser[]{this.itemParser, this.equipmentParser};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -261,6 +264,26 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
|
||||
protected abstract CustomItem.Builder<I> createPlatformItemBuilder(Holder<Key> id, Key material, Key clientBoundMaterial);
|
||||
|
||||
public class EquipmentParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"equipments", "equipment"};
|
||||
|
||||
@Override
|
||||
public String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int loadingSequence() {
|
||||
return LoadingSequence.EQUIPMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"items", "item"};
|
||||
|
||||
@@ -312,7 +335,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
// To get at least one model provider
|
||||
// Sets some basic model info
|
||||
if (customModelData > 0) {
|
||||
itemBuilder.dataModifier(new CustomModelDataModifier<>(customModelData));
|
||||
itemBuilder.clientBoundDataModifier(new CustomModelDataModifier<>(customModelData));
|
||||
}
|
||||
// Requires the item to have model before apply item-model
|
||||
else if (!hasItemModelSection && section.containsKey("model") && VersionHelper.isOrAbove1_21_2()) {
|
||||
@@ -320,7 +343,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
// customize or use the id
|
||||
itemModelKey = Key.from(section.getOrDefault("item-model", id.toString()).toString());
|
||||
if (ResourceLocation.isValid(itemModelKey.toString())) {
|
||||
itemBuilder.dataModifier(new ItemModelModifier<>(itemModelKey));
|
||||
itemBuilder.clientBoundDataModifier(new ItemModelModifier<>(itemModelKey));
|
||||
} else {
|
||||
itemModelKey = null;
|
||||
}
|
||||
@@ -328,7 +351,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
|
||||
if (hasItemModelSection && VersionHelper.isOrAbove1_21_2()) {
|
||||
itemModelKey = Key.from(section.get("item-model").toString());
|
||||
itemBuilder.dataModifier(new ItemModelModifier<>(itemModelKey));
|
||||
itemBuilder.clientBoundDataModifier(new ItemModelModifier<>(itemModelKey));
|
||||
}
|
||||
|
||||
// Get item data
|
||||
@@ -449,14 +472,14 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
}, "external");
|
||||
registerDataType((obj) -> {
|
||||
String name = obj.toString();
|
||||
return new CustomNameModifier<>(Config.nonItalic() ? "<!i>" + name : name);
|
||||
return new CustomNameModifier<>(name);
|
||||
}, "custom-name");
|
||||
registerDataType((obj) -> {
|
||||
String name = obj.toString();
|
||||
return new ItemNameModifier<>(Config.nonItalic() ? "<!i>" + name : name);
|
||||
return new ItemNameModifier<>(name);
|
||||
}, "item-name", "display-name");
|
||||
registerDataType((obj) -> {
|
||||
List<String> lore = MiscUtils.getAsStringList(obj).stream().map(it -> "<!i>" + it).toList();
|
||||
List<String> lore = MiscUtils.getAsStringList(obj);
|
||||
return new LoreModifier<>(lore);
|
||||
}, "lore", "display-lore", "description");
|
||||
registerDataType((obj) -> {
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface ItemManager<T> extends Manageable, ModelGenerator {
|
||||
|
||||
void registerDataType(Function<Object, ItemDataModifier<T>> factory, String... alias);
|
||||
|
||||
ConfigParser parser();
|
||||
ConfigParser[] parsers();
|
||||
|
||||
Map<Key, TreeSet<LegacyOverridesModel>> legacyItemOverrides();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.momirealms.craftengine.core.entity.Billboard;
|
||||
import net.momirealms.craftengine.core.entity.ItemDisplayContext;
|
||||
import net.momirealms.craftengine.core.entity.projectile.ProjectileMeta;
|
||||
import net.momirealms.craftengine.core.entity.projectile.ProjectileType;
|
||||
import net.momirealms.craftengine.core.item.equipment.ComponentBasedEquipment;
|
||||
import net.momirealms.craftengine.core.item.modifier.EquippableModifier;
|
||||
import net.momirealms.craftengine.core.item.modifier.FoodModifier;
|
||||
import net.momirealms.craftengine.core.item.modifier.ItemDataModifier;
|
||||
@@ -300,13 +301,8 @@ public class ItemSettings {
|
||||
registerFactory("equippable", (value -> {
|
||||
Map<String, Object> args = MiscUtils.castToMap(value, false);
|
||||
EquipmentData data = EquipmentData.fromMap(args);
|
||||
ItemEquipment itemEquipment = new ItemEquipment(data);
|
||||
for (Map.Entry<String, Object> entry : args.entrySet()) {
|
||||
EquipmentLayerType layerType = EquipmentLayerType.byId(entry.getKey());
|
||||
if (layerType != null) {
|
||||
itemEquipment.addLayer(layerType, ItemEquipment.Layer.fromConfig(entry.getValue()));
|
||||
}
|
||||
}
|
||||
ComponentBasedEquipment componentBasedEquipment = ComponentBasedEquipment.FACTORY.create(data.assetId(), args);
|
||||
ItemEquipment itemEquipment = new ItemEquipment(data, componentBasedEquipment);
|
||||
return settings -> settings.equipment(itemEquipment);
|
||||
}));
|
||||
registerFactory("can-place", (value -> {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.momirealms.craftengine.core.item.equipment;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public abstract class AbstractEquipment implements Equipment {
|
||||
protected final Key assetId;
|
||||
|
||||
protected AbstractEquipment(Key assetId) {
|
||||
this.assetId = assetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key assetId() {
|
||||
return assetId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package net.momirealms.craftengine.core.item.equipment;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.pack.misc.EquipmentLayerType;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ComponentBasedEquipment extends AbstractEquipment {
|
||||
public static final Factory FACTORY = new Factory();
|
||||
private final EnumMap<EquipmentLayerType, List<Layer>> layers;
|
||||
|
||||
public ComponentBasedEquipment(Key assetId) {
|
||||
super(assetId);
|
||||
this.layers = new EnumMap<>(EquipmentLayerType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key renderingMethod() {
|
||||
return Equipments.COMPONENT;
|
||||
}
|
||||
|
||||
public EnumMap<EquipmentLayerType, List<Layer>> layers() {
|
||||
return layers;
|
||||
}
|
||||
|
||||
public void addLayer(EquipmentLayerType layerType, List<Layer> layer) {
|
||||
this.layers.put(layerType, layer);
|
||||
}
|
||||
|
||||
public static class Factory implements EquipmentFactory {
|
||||
|
||||
@Override
|
||||
public ComponentBasedEquipment create(Key id, Map<String, Object> args) {
|
||||
ComponentBasedEquipment equipment = new ComponentBasedEquipment(id);
|
||||
for (Map.Entry<String, Object> entry : args.entrySet()) {
|
||||
EquipmentLayerType layerType = EquipmentLayerType.byId(entry.getKey());
|
||||
if (layerType != null) {
|
||||
equipment.addLayer(layerType, Layer.fromConfig(entry.getValue()));
|
||||
}
|
||||
}
|
||||
return equipment;
|
||||
}
|
||||
}
|
||||
|
||||
public record Layer(String texture, DyeableData data, boolean usePlayerTexture) implements Supplier<JsonObject> {
|
||||
|
||||
@NotNull
|
||||
public static List<Layer> fromConfig(Object obj) {
|
||||
switch (obj) {
|
||||
case String texture -> {
|
||||
return List.of(new Layer(texture, null, false));
|
||||
}
|
||||
case Map<?, ?> map -> {
|
||||
Map<String, Object> data = MiscUtils.castToMap(map, false);
|
||||
String texture = data.get("texture").toString();
|
||||
return List.of(new Layer(texture,
|
||||
DyeableData.fromObj(data.get("dyeable")),
|
||||
ResourceConfigUtils.getAsBoolean(data.getOrDefault("use-player-texture", false), "use-player-texture")
|
||||
));
|
||||
}
|
||||
case List<?> list -> {
|
||||
List<Layer> layers = new ArrayList<>();
|
||||
for (Object inner : list) {
|
||||
layers.addAll(fromConfig(inner));
|
||||
}
|
||||
return layers;
|
||||
}
|
||||
case null, default -> {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject get() {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("texture", texture);
|
||||
if (this.data != null) {
|
||||
jsonObject.add("dyeable", this.data.get());
|
||||
}
|
||||
if (this.usePlayerTexture) {
|
||||
jsonObject.addProperty("use_player_texture", true);
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public record DyeableData(@Nullable Integer colorWhenUndyed) implements Supplier<JsonObject> {
|
||||
|
||||
public static DyeableData fromObj(Object obj) {
|
||||
if (obj instanceof Map<?,?> map) {
|
||||
Map<String, Object> data = MiscUtils.castToMap(map, false);
|
||||
if (data.containsKey("color-when-undyed")) {
|
||||
return new DyeableData(ResourceConfigUtils.getAsInt(data.get("color-when-undyed"), "color-when-undyed"));
|
||||
}
|
||||
}
|
||||
return new DyeableData(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject get() {
|
||||
JsonObject dyeData = new JsonObject();
|
||||
if (this.colorWhenUndyed != null) {
|
||||
dyeData.addProperty("color_when_undyed", this.colorWhenUndyed);
|
||||
}
|
||||
return dyeData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.momirealms.craftengine.core.item.equipment;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public interface Equipment {
|
||||
|
||||
Key assetId();
|
||||
|
||||
Key renderingMethod();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.momirealms.craftengine.core.item.equipment;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface EquipmentFactory {
|
||||
|
||||
Equipment create(Key id, Map<String, Object> args);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.momirealms.craftengine.core.item.equipment;
|
||||
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
public class Equipments {
|
||||
public static final Key TRIM = Key.of("craftengine:trim");
|
||||
public static final Key COMPONENT = Key.of("craftengine:component");
|
||||
|
||||
static {
|
||||
register(TRIM, TrimBasedEquipment.FACTORY);
|
||||
}
|
||||
|
||||
public static void register(Key key, EquipmentFactory factory) {
|
||||
Holder.Reference<EquipmentFactory> holder = ((WritableRegistry<EquipmentFactory>) BuiltInRegistries.EQUIPMENT_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.EQUIPMENT_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.momirealms.craftengine.core.item.equipment;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TrimBasedEquipment extends AbstractEquipment {
|
||||
public static final Factory FACTORY = new Factory();
|
||||
private final Key humanoid;
|
||||
private final Key humanoidLeggings;
|
||||
|
||||
public TrimBasedEquipment(Key assetId, Key humanoid, Key humanoidLeggings) {
|
||||
super(assetId);
|
||||
this.humanoid = humanoid;
|
||||
this.humanoidLeggings = humanoidLeggings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key renderingMethod() {
|
||||
return Equipments.TRIM;
|
||||
}
|
||||
|
||||
public Key humanoid() {
|
||||
return humanoid;
|
||||
}
|
||||
|
||||
public Key humanoidLeggings() {
|
||||
return humanoidLeggings;
|
||||
}
|
||||
|
||||
public static class Factory implements EquipmentFactory {
|
||||
@Override
|
||||
public Equipment create(Key id, Map<String, Object> args) {
|
||||
// todo node
|
||||
String humanoidId = ResourceConfigUtils.requireNonEmptyStringOrThrow(args.get("humanoid"), "");
|
||||
String humanoidLeggingsId = ResourceConfigUtils.requireNonEmptyStringOrThrow(args.get("humanoid-leggings"), "");
|
||||
// todo 验证resource location
|
||||
return new TrimBasedEquipment(id, Key.of(humanoidId), Key.of(humanoidLeggingsId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,101 +1,29 @@
|
||||
package net.momirealms.craftengine.core.item.setting;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.item.equipment.ComponentBasedEquipment;
|
||||
import net.momirealms.craftengine.core.pack.misc.EquipmentLayerType;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ItemEquipment {
|
||||
private final EquipmentData data;
|
||||
private final EnumMap<EquipmentLayerType, List<Layer>> layers;
|
||||
private final ComponentBasedEquipment equipment;
|
||||
|
||||
public ItemEquipment(EquipmentData data) {
|
||||
public ItemEquipment(EquipmentData data, ComponentBasedEquipment equipment) {
|
||||
this.data = data;
|
||||
this.layers = new EnumMap<>(EquipmentLayerType.class);
|
||||
this.equipment = equipment;
|
||||
}
|
||||
|
||||
public void addLayer(EquipmentLayerType layerType, List<Layer> layer) {
|
||||
this.layers.put(layerType, layer);
|
||||
public void addLayer(EquipmentLayerType layerType, List<ComponentBasedEquipment.Layer> layer) {
|
||||
this.equipment.addLayer(layerType, layer);
|
||||
}
|
||||
|
||||
public EnumMap<EquipmentLayerType, List<Layer>> layers() {
|
||||
return layers;
|
||||
public EnumMap<EquipmentLayerType, List<ComponentBasedEquipment.Layer>> layers() {
|
||||
return this.equipment.layers();
|
||||
}
|
||||
|
||||
public EquipmentData data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public record Layer(String texture, DyeableData data, boolean usePlayerTexture) implements Supplier<JsonObject> {
|
||||
|
||||
@NotNull
|
||||
public static List<Layer> fromConfig(Object obj) {
|
||||
switch (obj) {
|
||||
case String texture -> {
|
||||
return List.of(new Layer(texture, null, false));
|
||||
}
|
||||
case Map<?, ?> map -> {
|
||||
Map<String, Object> data = MiscUtils.castToMap(map, false);
|
||||
String texture = data.get("texture").toString();
|
||||
return List.of(new Layer(texture,
|
||||
DyeableData.fromObj(data.get("dyeable")),
|
||||
ResourceConfigUtils.getAsBoolean(data.getOrDefault("use-player-texture", false), "use-player-texture")
|
||||
));
|
||||
}
|
||||
case List<?> list -> {
|
||||
List<Layer> layers = new ArrayList<>();
|
||||
for (Object inner : list) {
|
||||
layers.addAll(fromConfig(inner));
|
||||
}
|
||||
return layers;
|
||||
}
|
||||
case null, default -> {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject get() {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("texture", texture);
|
||||
if (this.data != null) {
|
||||
jsonObject.add("dyeable", this.data.get());
|
||||
}
|
||||
if (this.usePlayerTexture) {
|
||||
jsonObject.addProperty("use_player_texture", true);
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public record DyeableData(@Nullable Integer colorWhenUndyed) implements Supplier<JsonObject> {
|
||||
|
||||
public static DyeableData fromObj(Object obj) {
|
||||
if (obj instanceof Map<?,?> map) {
|
||||
Map<String, Object> data = MiscUtils.castToMap(map, false);
|
||||
if (data.containsKey("color-when-undyed")) {
|
||||
return new DyeableData(ResourceConfigUtils.getAsInt(data.get("color-when-undyed"), "color-when-undyed"));
|
||||
}
|
||||
}
|
||||
return new DyeableData(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject get() {
|
||||
JsonObject dyeData = new JsonObject();
|
||||
if (this.colorWhenUndyed != null) {
|
||||
dyeData.addProperty("color_when_undyed", this.colorWhenUndyed);
|
||||
}
|
||||
return dyeData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,15 @@ public final class LoadingSequence {
|
||||
public static final int LANG = 20;
|
||||
public static final int TRANSLATION = 30;
|
||||
public static final int BLOCK = 40;
|
||||
public static final int ITEM = 50;
|
||||
public static final int FURNITURE = 60;
|
||||
public static final int IMAGE = 70;
|
||||
public static final int RECIPE = 80;
|
||||
public static final int CATEGORY = 90;
|
||||
public static final int SOUND = 100;
|
||||
public static final int JUKEBOX_SONG = 110;
|
||||
public static final int VANILLA_LOOTS = 120;
|
||||
public static final int EMOJI = 130;
|
||||
public static final int ADVANCEMENT = 140;
|
||||
public static final int EQUIPMENT = 50;
|
||||
public static final int ITEM = 60;
|
||||
public static final int FURNITURE = 70;
|
||||
public static final int IMAGE = 80;
|
||||
public static final int RECIPE = 90;
|
||||
public static final int CATEGORY = 100;
|
||||
public static final int SOUND = 110;
|
||||
public static final int JUKEBOX_SONG = 120;
|
||||
public static final int VANILLA_LOOTS = 130;
|
||||
public static final int EMOJI = 140;
|
||||
public static final int ADVANCEMENT = 150;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.momirealms.craftengine.core.pack.misc;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.item.equipment.ComponentBasedEquipment;
|
||||
import net.momirealms.craftengine.core.item.setting.ItemEquipment;
|
||||
|
||||
import java.util.EnumMap;
|
||||
@@ -10,16 +11,16 @@ import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Equipment implements Supplier<JsonObject> {
|
||||
private final EnumMap<EquipmentLayerType, List<ItemEquipment.Layer>> layers;
|
||||
private final EnumMap<EquipmentLayerType, List<ComponentBasedEquipment.Layer>> layers;
|
||||
|
||||
public Equipment() {
|
||||
this.layers = new EnumMap<>(EquipmentLayerType.class);
|
||||
}
|
||||
|
||||
public void addAll(ItemEquipment equipment) {
|
||||
for (Map.Entry<EquipmentLayerType, List<ItemEquipment.Layer>> entry : equipment.layers().entrySet()) {
|
||||
List<ItemEquipment.Layer> layers = entry.getValue();
|
||||
List<ItemEquipment.Layer> previous = this.layers.put(entry.getKey(), layers);
|
||||
for (Map.Entry<EquipmentLayerType, List<ComponentBasedEquipment.Layer>> entry : equipment.layers().entrySet()) {
|
||||
List<ComponentBasedEquipment.Layer> layers = entry.getValue();
|
||||
List<ComponentBasedEquipment.Layer> previous = this.layers.put(entry.getKey(), layers);
|
||||
if (previous != null && !previous.equals(layers)) {
|
||||
// todo 是否异常
|
||||
}
|
||||
@@ -31,18 +32,18 @@ public class Equipment implements Supplier<JsonObject> {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
JsonObject layersJson = new JsonObject();
|
||||
jsonObject.add("layers", layersJson);
|
||||
for (Map.Entry<EquipmentLayerType, List<ItemEquipment.Layer>> entry : layers.entrySet()) {
|
||||
for (Map.Entry<EquipmentLayerType, List<ComponentBasedEquipment.Layer>> entry : layers.entrySet()) {
|
||||
EquipmentLayerType type = entry.getKey();
|
||||
List<ItemEquipment.Layer> layerList = entry.getValue();
|
||||
List<ComponentBasedEquipment.Layer> layerList = entry.getValue();
|
||||
setLayers(layersJson, layerList, type.id());
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
private void setLayers(JsonObject layersJson, List<ItemEquipment.Layer> layers, String key) {
|
||||
private void setLayers(JsonObject layersJson, List<ComponentBasedEquipment.Layer> layers, String key) {
|
||||
if (layers == null || layers.isEmpty()) return;
|
||||
JsonArray layersArray = new JsonArray();
|
||||
for (ItemEquipment.Layer layer : layers) {
|
||||
for (ComponentBasedEquipment.Layer layer : layers) {
|
||||
layersArray.add(layer.get());
|
||||
}
|
||||
layersJson.add(key, layersArray);
|
||||
|
||||
@@ -263,7 +263,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
// register font parser
|
||||
this.packManager.registerConfigSectionParsers(this.fontManager.parsers());
|
||||
// register item parser
|
||||
this.packManager.registerConfigSectionParser(this.itemManager.parser());
|
||||
this.packManager.registerConfigSectionParsers(this.itemManager.parsers());
|
||||
// register furniture parser
|
||||
this.packManager.registerConfigSectionParser(this.furnitureManager.parser());
|
||||
// register block parser
|
||||
|
||||
@@ -123,8 +123,6 @@ public class Config {
|
||||
protected boolean recipe$disable_vanilla_recipes$all;
|
||||
protected Set<Key> recipe$disable_vanilla_recipes$list;
|
||||
|
||||
protected boolean item$non_italic_tag;
|
||||
|
||||
protected boolean image$illegal_characters_filter$command;
|
||||
protected boolean image$illegal_characters_filter$chat;
|
||||
protected boolean image$illegal_characters_filter$anvil;
|
||||
@@ -284,9 +282,6 @@ public class Config {
|
||||
resource_pack$duplicated_files_handler = List.of();
|
||||
}
|
||||
|
||||
// item
|
||||
item$non_italic_tag = config.getBoolean("item.non-italic-tag", false);
|
||||
|
||||
// performance
|
||||
performance$max_note_block_chain_update_limit = config.getInt("performance.max-note-block-chain-update-limit", 64);
|
||||
performance$max_tripwire_chain_update_limit = config.getInt("performance.max-tripwire-chain-update-limit", 128);
|
||||
@@ -456,10 +451,6 @@ public class Config {
|
||||
return instance.recipe$disable_vanilla_recipes$list;
|
||||
}
|
||||
|
||||
public static boolean nonItalic() {
|
||||
return instance.item$non_italic_tag;
|
||||
}
|
||||
|
||||
public static boolean restoreVanillaBlocks() {
|
||||
return instance.chunk_system$restore_vanilla_blocks_on_chunk_unload && instance.chunk_system$restore_custom_blocks_on_chunk_load;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.block.properties.PropertyFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.HitBoxFactory;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.item.equipment.EquipmentFactory;
|
||||
import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeFactory;
|
||||
import net.momirealms.craftengine.core.loot.LootContext;
|
||||
@@ -68,6 +69,7 @@ public class BuiltInRegistries {
|
||||
public static final Registry<FunctionFactory<PlayerOptionalContext>> EVENT_FUNCTION_FACTORY = createRegistry(Registries.EVENT_FUNCTION_FACTORY);
|
||||
public static final Registry<ConditionFactory<PlayerOptionalContext>> EVENT_CONDITION_FACTORY = createRegistry(Registries.EVENT_CONDITION_FACTORY);
|
||||
public static final Registry<PlayerSelectorFactory<?>> PLAYER_SELECTOR_FACTORY = createRegistry(Registries.PLAYER_SELECTOR_FACTORY);
|
||||
public static final Registry<EquipmentFactory> EQUIPMENT_FACTORY = createRegistry(Registries.EQUIPMENT_FACTORY);
|
||||
|
||||
private static <T> Registry<T> createRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
return new MappedRegistry<>(key);
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.block.properties.PropertyFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.HitBoxFactory;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.item.equipment.EquipmentFactory;
|
||||
import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeFactory;
|
||||
import net.momirealms.craftengine.core.loot.LootContext;
|
||||
@@ -68,5 +69,6 @@ public class Registries {
|
||||
public static final ResourceKey<Registry<ResourcePackHostFactory>> RESOURCE_PACK_HOST_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("resource_pack_host_factory"));
|
||||
public static final ResourceKey<Registry<FunctionFactory<PlayerOptionalContext>>> EVENT_FUNCTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("event_function_factory"));
|
||||
public static final ResourceKey<Registry<ConditionFactory<PlayerOptionalContext>>> EVENT_CONDITION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("event_condition_factory"));
|
||||
public static final ResourceKey<Registry<PlayerSelectorFactory<?>>> PLAYER_SELECTOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("player_selector"));
|
||||
public static final ResourceKey<Registry<PlayerSelectorFactory<?>>> PLAYER_SELECTOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("player_selector_factory"));
|
||||
public static final ResourceKey<Registry<EquipmentFactory>> EQUIPMENT_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("equipment_factory"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user