mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
客户端侧material
This commit is contained in:
@@ -21,12 +21,12 @@ import java.util.Map;
|
||||
public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
|
||||
private final Material material;
|
||||
|
||||
public BukkitCustomItem(Holder<Key> id, Key materialKey, Material material,
|
||||
public BukkitCustomItem(Holder<Key> id, Material material, Key materialKey, Key clientBoundMaterialKey,
|
||||
List<ItemBehavior> behaviors,
|
||||
List<ItemDataModifier<ItemStack>> modifiers, List<ItemDataModifier<ItemStack>> clientBoundModifiers,
|
||||
ItemSettings settings,
|
||||
Map<EventTrigger, List<Function<PlayerOptionalContext>>> events) {
|
||||
super(id, materialKey, behaviors, modifiers, clientBoundModifiers, settings, events);
|
||||
super(id, materialKey, clientBoundMaterialKey, behaviors, modifiers, clientBoundModifiers, settings, events);
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
@@ -57,8 +57,9 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
|
||||
|
||||
public static class BuilderImpl implements Builder<ItemStack> {
|
||||
private Holder<Key> id;
|
||||
private Key materialKey;
|
||||
private final Key materialKey;
|
||||
private final Material material;
|
||||
private Key clientBoundMaterialKey;
|
||||
private final Map<EventTrigger, List<Function<PlayerOptionalContext>>> events = new EnumMap<>(EventTrigger.class);
|
||||
private final List<ItemBehavior> behaviors = new ArrayList<>(4);
|
||||
private final List<ItemDataModifier<ItemStack>> modifiers = new ArrayList<>(4);
|
||||
@@ -77,8 +78,8 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<ItemStack> material(Key material) {
|
||||
this.materialKey = material;
|
||||
public Builder<ItemStack> clientBoundMaterial(Key clientBoundMaterialKey) {
|
||||
this.clientBoundMaterialKey = clientBoundMaterialKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -133,7 +134,7 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
|
||||
@Override
|
||||
public CustomItem<ItemStack> build() {
|
||||
this.modifiers.addAll(this.settings.modifiers());
|
||||
return new BukkitCustomItem(this.id, this.materialKey, this.material, List.copyOf(this.behaviors),
|
||||
return new BukkitCustomItem(this.id, this.material, this.materialKey, this.clientBoundMaterialKey, List.copyOf(this.behaviors),
|
||||
List.copyOf(this.modifiers), List.copyOf(this.clientBoundModifiers), this.settings, this.events);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,9 +200,12 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CustomItem.Builder<ItemStack> createPlatformItemBuilder(Holder<Key> id, Key materialId) {
|
||||
protected CustomItem.Builder<ItemStack> createPlatformItemBuilder(Holder<Key> id, Key materialId, Key clientBoundMaterialId) {
|
||||
Material material = ResourceConfigUtils.requireNonNullOrThrow(Registry.MATERIAL.get(KeyUtils.toNamespacedKey(materialId)), () -> new LocalizedResourceConfigException("warning.config.item.invalid_material", materialId.toString()));
|
||||
return BukkitCustomItem.builder(material).material(materialId).id(id);
|
||||
if (!clientBoundMaterialId.equals(materialId)) {
|
||||
ResourceConfigUtils.requireNonNullOrThrow(Registry.MATERIAL.get(KeyUtils.toNamespacedKey(clientBoundMaterialId)), () -> new LocalizedResourceConfigException("warning.config.item.invalid_material", clientBoundMaterialId.toString()));
|
||||
}
|
||||
return BukkitCustomItem.builder(material).id(id).clientBoundMaterial(clientBoundMaterialId);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -29,7 +29,20 @@ public class LegacyNetworkItemHandler implements NetworkItemHandler<ItemStack> {
|
||||
|
||||
@Override
|
||||
public Optional<Item<ItemStack>> c2s(Item<ItemStack> wrapped) {
|
||||
if (!wrapped.hasTag(NETWORK_ITEM_TAG)) return Optional.empty();
|
||||
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
|
||||
boolean hasDifferentMaterial = false;
|
||||
if (optionalCustomItem.isPresent()) {
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
if (!customItem.material().equals(wrapped.vanillaId())) {
|
||||
wrapped = wrapped.transmuteCopy(customItem.material());
|
||||
hasDifferentMaterial = true;
|
||||
}
|
||||
}
|
||||
if (!wrapped.hasTag(NETWORK_ITEM_TAG)) {
|
||||
if (hasDifferentMaterial) {
|
||||
return Optional.of(wrapped);
|
||||
}
|
||||
}
|
||||
CompoundTag networkData = (CompoundTag) wrapped.getNBTTag(NETWORK_ITEM_TAG);
|
||||
if (networkData == null) return Optional.empty();
|
||||
wrapped.removeTag(NETWORK_ITEM_TAG);
|
||||
@@ -46,12 +59,16 @@ public class LegacyNetworkItemHandler implements NetworkItemHandler<ItemStack> {
|
||||
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
|
||||
if (optionalCustomItem.isEmpty()) {
|
||||
if (!Config.interceptItem()) return Optional.empty();
|
||||
return new OtherItem(wrapped).process();
|
||||
return new OtherItem(wrapped, false).process();
|
||||
} else {
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
boolean hasDifferentMaterial = !wrapped.vanillaId().equals(customItem.clientBoundMaterial());
|
||||
if (hasDifferentMaterial) {
|
||||
wrapped = wrapped.transmuteCopy(customItem.clientBoundMaterial());
|
||||
}
|
||||
if (!customItem.hasClientBoundDataModifier()) {
|
||||
if (!Config.interceptItem()) return Optional.empty();
|
||||
return new OtherItem(wrapped).process();
|
||||
if (!Config.interceptItem() && !hasDifferentMaterial) return Optional.empty();
|
||||
return new OtherItem(wrapped, hasDifferentMaterial).process();
|
||||
} else {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
Tag argumentTag = wrapped.getNBTTag(ArgumentModifier.ARGUMENTS_TAG);
|
||||
@@ -77,7 +94,12 @@ public class LegacyNetworkItemHandler implements NetworkItemHandler<ItemStack> {
|
||||
processLore(wrapped, tag::put);
|
||||
}
|
||||
}
|
||||
if (tag.isEmpty()) return Optional.empty();
|
||||
if (tag.isEmpty()) {
|
||||
if (hasDifferentMaterial) {
|
||||
return Optional.of(wrapped);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
wrapped.setTag(tag, NETWORK_ITEM_TAG);
|
||||
return Optional.of(wrapped);
|
||||
}
|
||||
@@ -130,9 +152,11 @@ public class LegacyNetworkItemHandler implements NetworkItemHandler<ItemStack> {
|
||||
private final Item<ItemStack> item;
|
||||
private boolean globalChanged = false;
|
||||
private CompoundTag networkTag;
|
||||
private final boolean forceReturn;
|
||||
|
||||
public OtherItem(Item<ItemStack> item) {
|
||||
public OtherItem(Item<ItemStack> item, boolean forceReturn) {
|
||||
this.item = item;
|
||||
this.forceReturn = forceReturn;
|
||||
}
|
||||
|
||||
public Optional<Item<ItemStack>> process() {
|
||||
@@ -145,6 +169,8 @@ public class LegacyNetworkItemHandler implements NetworkItemHandler<ItemStack> {
|
||||
if (this.globalChanged) {
|
||||
this.item.setTag(this.networkTag, NETWORK_ITEM_TAG);
|
||||
return Optional.of(this.item);
|
||||
} else if (this.forceReturn) {
|
||||
return Optional.of(this.item);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -30,8 +30,22 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
public Optional<Item<ItemStack>> c2s(Item<ItemStack> wrapped) {
|
||||
Tag customData = wrapped.getNBTComponent(ComponentTypes.CUSTOM_DATA);
|
||||
if (!(customData instanceof CompoundTag compoundTag)) return Optional.empty();
|
||||
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
|
||||
boolean hasDifferentMaterial = false;
|
||||
if (optionalCustomItem.isPresent()) {
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
if (!customItem.material().equals(wrapped.vanillaId())) {
|
||||
wrapped = wrapped.transmuteCopy(customItem.material());
|
||||
hasDifferentMaterial = true;
|
||||
}
|
||||
}
|
||||
CompoundTag networkData = compoundTag.getCompound(NETWORK_ITEM_TAG);
|
||||
if (networkData == null) return Optional.empty();
|
||||
if (networkData == null) {
|
||||
if (hasDifferentMaterial) {
|
||||
return Optional.of(wrapped);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
compoundTag.remove(NETWORK_ITEM_TAG);
|
||||
for (Map.Entry<String, Tag> entry : networkData.entrySet()) {
|
||||
if (entry.getValue() instanceof CompoundTag tag) {
|
||||
@@ -48,12 +62,16 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
|
||||
if (optionalCustomItem.isEmpty()) {
|
||||
if (!Config.interceptItem()) return Optional.empty();
|
||||
return new OtherItem(wrapped).process();
|
||||
return new OtherItem(wrapped, false).process();
|
||||
} else {
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
boolean hasDifferentMaterial = !wrapped.vanillaId().equals(customItem.clientBoundMaterial());
|
||||
if (hasDifferentMaterial) {
|
||||
wrapped = wrapped.transmuteCopy(customItem.clientBoundMaterial());
|
||||
}
|
||||
if (!customItem.hasClientBoundDataModifier()) {
|
||||
if (!Config.interceptItem()) return Optional.empty();
|
||||
return new OtherItem(wrapped).process();
|
||||
if (!Config.interceptItem() && !hasDifferentMaterial) return Optional.empty();
|
||||
return new OtherItem(wrapped, hasDifferentMaterial).process();
|
||||
} else {
|
||||
CompoundTag customData = Optional.ofNullable(wrapped.getNBTComponent(ComponentTypes.CUSTOM_DATA)).map(CompoundTag.class::cast).orElse(new CompoundTag());
|
||||
CompoundTag arguments = customData.getCompound(ArgumentModifier.ARGUMENTS_TAG);
|
||||
@@ -86,7 +104,10 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
else processLegacyLore(wrapped, () -> tag);
|
||||
}
|
||||
}
|
||||
if (tag.isEmpty()) return Optional.empty();
|
||||
if (tag.isEmpty()) {
|
||||
if (hasDifferentMaterial) return Optional.of(wrapped);
|
||||
return Optional.empty();
|
||||
}
|
||||
customData.put(NETWORK_ITEM_TAG, tag);
|
||||
wrapped.setNBTComponent(ComponentTypes.CUSTOM_DATA, customData);
|
||||
return Optional.of(wrapped);
|
||||
@@ -203,11 +224,13 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
|
||||
static class OtherItem {
|
||||
private final Item<ItemStack> item;
|
||||
private final boolean forceReturn;
|
||||
private boolean globalChanged = false;
|
||||
private CompoundTag tag;
|
||||
|
||||
public OtherItem(Item<ItemStack> item) {
|
||||
public OtherItem(Item<ItemStack> item, boolean forceReturn) {
|
||||
this.item = item;
|
||||
this.forceReturn = forceReturn;
|
||||
}
|
||||
|
||||
public Optional<Item<ItemStack>> process() {
|
||||
@@ -231,6 +254,8 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
customData.put(NETWORK_ITEM_TAG, getOrCreateTag());
|
||||
this.item.setNBTComponent(ComponentKeys.CUSTOM_DATA, customData);
|
||||
return Optional.of(this.item);
|
||||
} else if (this.forceReturn) {
|
||||
return Optional.of(this.item);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.saicone.rtag.item.ItemTagStream;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.util.ItemTags;
|
||||
import net.momirealms.craftengine.core.item.ItemFactory;
|
||||
|
||||
@@ -5,8 +5,10 @@ import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
|
||||
import net.momirealms.craftengine.bukkit.util.EnchantmentUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.core.item.Enchantment;
|
||||
import net.momirealms.craftengine.core.item.Trim;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
@@ -507,9 +509,9 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
protected ComponentItemWrapper mergeCopy(ComponentItemWrapper item1, ComponentItemWrapper item2) {
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = item2.getLiteralObject();
|
||||
Object itemStack3 = FastNMS.INSTANCE.method$ItemStack$transmuteCopy(itemStack1, itemStack2);
|
||||
Object itemStack3 = FastNMS.INSTANCE.method$ItemStack$transmuteCopy(itemStack1, FastNMS.INSTANCE.method$ItemStack$getItem(itemStack2), item2.count());
|
||||
FastNMS.INSTANCE.method$ItemStack$applyComponents(itemStack3, FastNMS.INSTANCE.method$ItemStack$getComponentsPatch(itemStack2));
|
||||
return new ComponentItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack3), item2.count());
|
||||
return new ComponentItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack3));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -519,7 +521,14 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
try {
|
||||
FastNMS.INSTANCE.method$ItemStack$applyComponents(itemStack1, FastNMS.INSTANCE.method$ItemStack$getComponentsPatch(itemStack2));
|
||||
} catch (Exception e) {
|
||||
plugin.logger().warn("Failed to merge item", e);
|
||||
this.plugin.logger().warn("Failed to merge item", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentItemWrapper transmuteCopy(ComponentItemWrapper item1, Key item, int amount) {
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = FastNMS.INSTANCE.method$ItemStack$transmuteCopy(itemStack1, FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(item)), amount);
|
||||
return new ComponentItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack2));
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import com.saicone.rtag.tag.TagBase;
|
||||
import com.saicone.rtag.tag.TagCompound;
|
||||
import com.saicone.rtag.tag.TagList;
|
||||
import net.momirealms.craftengine.bukkit.item.LegacyItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.core.item.Enchantment;
|
||||
import net.momirealms.craftengine.core.item.Trim;
|
||||
import net.momirealms.craftengine.core.item.modifier.IdModifier;
|
||||
@@ -319,4 +322,11 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
|
||||
// update wrapped item
|
||||
item1.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LegacyItemWrapper transmuteCopy(LegacyItemWrapper item, Key newItem, int amount) {
|
||||
Object newItemStack = FastNMS.INSTANCE.constructor$ItemStack(FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(newItem)), amount);
|
||||
ItemObject.setCustomDataTag(newItemStack, TagCompound.clone(ItemObject.getCustomDataTag(item.getLiteralObject())));
|
||||
return new LegacyItemWrapper(new RtagItem(ItemObject.asCraftMirror(newItemStack)), amount);
|
||||
}
|
||||
}
|
||||
@@ -791,6 +791,7 @@ public class RecipeEventListener implements Listener {
|
||||
return new Pair<>(first, second);
|
||||
}
|
||||
|
||||
// 不是完美的解决方案,仍然需要更多的探讨
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onCraft(CraftItemEvent event) {
|
||||
org.bukkit.inventory.Recipe recipe = event.getRecipe();
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Optional;
|
||||
public abstract class AbstractCustomItem<I> implements CustomItem<I> {
|
||||
protected final Holder<Key> id;
|
||||
protected final Key material;
|
||||
protected final Key clientBoundMaterial;
|
||||
protected final ItemDataModifier<I>[] modifiers;
|
||||
protected final Map<String, ItemDataModifier<I>> modifierMap;
|
||||
protected final ItemDataModifier<I>[] clientBoundModifiers;
|
||||
@@ -27,7 +28,7 @@ public abstract class AbstractCustomItem<I> implements CustomItem<I> {
|
||||
protected final Map<EventTrigger, List<Function<PlayerOptionalContext>>> events;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractCustomItem(Holder<Key> id, Key material,
|
||||
public AbstractCustomItem(Holder<Key> id, Key material, Key clientBoundMaterial,
|
||||
List<ItemBehavior> behaviors,
|
||||
List<ItemDataModifier<I>> modifiers,
|
||||
List<ItemDataModifier<I>> clientBoundModifiers,
|
||||
@@ -35,6 +36,7 @@ public abstract class AbstractCustomItem<I> implements CustomItem<I> {
|
||||
Map<EventTrigger, List<Function<PlayerOptionalContext>>> events) {
|
||||
this.id = id;
|
||||
this.material = material;
|
||||
this.clientBoundMaterial = clientBoundMaterial;
|
||||
this.events = events;
|
||||
// unchecked cast
|
||||
this.modifiers = modifiers.toArray(new ItemDataModifier[0]);
|
||||
@@ -74,6 +76,11 @@ public abstract class AbstractCustomItem<I> implements CustomItem<I> {
|
||||
return this.material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key clientBoundMaterial() {
|
||||
return this.clientBoundMaterial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDataModifier<I>[] dataModifiers() {
|
||||
return this.modifiers;
|
||||
|
||||
@@ -424,6 +424,11 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
|
||||
return new AbstractItem<>(this.factory, this.factory.mergeCopy(this.item, (W) ((AbstractItem) another).item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractItem<W, I> transmuteCopy(Key another, int count) {
|
||||
return new AbstractItem<>(this.factory, this.factory.transmuteCopy(this.item, another, count));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public void merge(Item<I> another) {
|
||||
|
||||
@@ -259,7 +259,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
return VANILLA_ITEMS.contains(item);
|
||||
}
|
||||
|
||||
protected abstract CustomItem.Builder<I> createPlatformItemBuilder(Holder<Key> id, Key material);
|
||||
protected abstract CustomItem.Builder<I> createPlatformItemBuilder(Holder<Key> id, Key material, Key clientBoundMaterial);
|
||||
|
||||
public class ItemParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"items", "item"};
|
||||
@@ -297,6 +297,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
|
||||
boolean isVanillaItem = isVanillaItem(id);
|
||||
Key material = Key.from(isVanillaItem ? id.value() : ResourceConfigUtils.requireNonEmptyStringOrThrow(section.get("material"), "warning.config.item.missing_material").toLowerCase(Locale.ENGLISH));
|
||||
Key clientBoundMaterial = section.containsKey("client-bound-material") ? Key.from(section.get("client-bound-material").toString().toLowerCase(Locale.ENGLISH)) : material;
|
||||
int customModelData = ResourceConfigUtils.getAsInt(section.getOrDefault("custom-model-data", 0), "custom-model-data");
|
||||
if (customModelData < 0) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.invalid_custom_model_data", String.valueOf(customModelData));
|
||||
@@ -307,7 +308,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
|
||||
Key itemModelKey = null;
|
||||
|
||||
CustomItem.Builder<I> itemBuilder = createPlatformItemBuilder(holder, material);
|
||||
CustomItem.Builder<I> itemBuilder = createPlatformItemBuilder(holder, material, clientBoundMaterial);
|
||||
boolean hasItemModelSection = section.containsKey("item-model");
|
||||
|
||||
// To get at least one model provider
|
||||
@@ -392,7 +393,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
legacyOverridesModels = new TreeSet<>(legacyItemModel.overrides());
|
||||
} else {
|
||||
legacyOverridesModels = new TreeSet<>();
|
||||
processModelRecursively(modernModel, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData);
|
||||
processModelRecursively(modernModel, new LinkedHashMap<>(), legacyOverridesModels, clientBoundMaterial, customModelData);
|
||||
if (legacyOverridesModels.isEmpty()) {
|
||||
TranslationManager.instance().log("warning.config.item.legacy_model.cannot_convert", path.toString(), id.asString());
|
||||
}
|
||||
@@ -403,18 +404,18 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
if (customModelData != 0) {
|
||||
// use custom model data
|
||||
// check conflict
|
||||
Map<Integer, Key> conflict = AbstractItemManager.this.cmdConflictChecker.computeIfAbsent(material, k -> new HashMap<>());
|
||||
Map<Integer, Key> conflict = AbstractItemManager.this.cmdConflictChecker.computeIfAbsent(clientBoundMaterial, k -> new HashMap<>());
|
||||
if (conflict.containsKey(customModelData)) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.custom_model_data_conflict", String.valueOf(customModelData), conflict.get(customModelData).toString());
|
||||
}
|
||||
conflict.put(customModelData, id);
|
||||
// Parse models
|
||||
if (isModernFormatRequired() && modernModel != null) {
|
||||
TreeMap<Integer, ItemModel> map = AbstractItemManager.this.modernOverrides.computeIfAbsent(material, k -> new TreeMap<>());
|
||||
TreeMap<Integer, ItemModel> map = AbstractItemManager.this.modernOverrides.computeIfAbsent(clientBoundMaterial, k -> new TreeMap<>());
|
||||
map.put(customModelData, modernModel);
|
||||
}
|
||||
if (needsLegacyCompatibility() && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) {
|
||||
TreeSet<LegacyOverridesModel> lom = AbstractItemManager.this.legacyOverrides.computeIfAbsent(material, k -> new TreeSet<>());
|
||||
TreeSet<LegacyOverridesModel> lom = AbstractItemManager.this.legacyOverrides.computeIfAbsent(clientBoundMaterial, k -> new TreeSet<>());
|
||||
lom.addAll(legacyOverridesModels);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.momirealms.craftengine.core.plugin.context.function.Function;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -21,6 +22,8 @@ public interface CustomItem<I> extends BuildableItem<I> {
|
||||
|
||||
Key material();
|
||||
|
||||
Key clientBoundMaterial();
|
||||
|
||||
ItemDataModifier<I>[] dataModifiers();
|
||||
|
||||
Map<String, ItemDataModifier<I>> dataModifierMap();
|
||||
@@ -51,7 +54,7 @@ public interface CustomItem<I> extends BuildableItem<I> {
|
||||
interface Builder<I> {
|
||||
Builder<I> id(Holder<Key> id);
|
||||
|
||||
Builder<I> material(Key material);
|
||||
Builder<I> clientBoundMaterial(Key clientBoundMaterialKey);
|
||||
|
||||
Builder<I> dataModifier(ItemDataModifier<I> modifier);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.core.item;
|
||||
import com.google.gson.JsonElement;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
|
||||
import net.momirealms.craftengine.core.item.modifier.ItemDataModifier;
|
||||
import net.momirealms.craftengine.core.item.setting.EquipmentData;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
@@ -178,7 +179,17 @@ public interface Item<I> {
|
||||
|
||||
Item<I> mergeCopy(Item<?> another);
|
||||
|
||||
Item<I> transmuteCopy(Key another, int count);
|
||||
|
||||
default Item<I> transmuteCopy(Key another) {
|
||||
return transmuteCopy(another, this.count());
|
||||
}
|
||||
|
||||
void merge(Item<I> another);
|
||||
|
||||
default Item<I> apply(ItemDataModifier<I> modifier, ItemBuildContext context) {
|
||||
return modifier.apply(this, context);
|
||||
}
|
||||
|
||||
byte[] toByteArray();
|
||||
}
|
||||
|
||||
@@ -194,4 +194,6 @@ public abstract class ItemFactory<W extends ItemWrapper<I>, I> {
|
||||
protected abstract void setJsonComponent(W item, Object type, JsonElement value);
|
||||
|
||||
protected abstract void setNBTComponent(W item, Object type, Tag value);
|
||||
|
||||
protected abstract W transmuteCopy(W item, Key newItem, int amount);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ArgumentModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
CompoundTag customData = (CompoundTag) Optional.ofNullable(item.getNBTComponent(ComponentKeys.CUSTOM_DATA)).orElse(new CompoundTag());
|
||||
CompoundTag argumentTag = new CompoundTag();
|
||||
@@ -42,5 +42,6 @@ public class ArgumentModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
item.setTag(processed, ARGUMENTS_TAG);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ComponentModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
for (Pair<Key, Object> entry : this.arguments) {
|
||||
item.setComponent(entry.left(), entry.right());
|
||||
}
|
||||
@@ -75,10 +75,11 @@ public class ComponentModifier<I> implements ItemDataModifier<I> {
|
||||
item.setComponent(ComponentKeys.CUSTOM_DATA, this.customData);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
for (Pair<Key, Object> entry : this.arguments) {
|
||||
Tag previous = item.getNBTComponent(entry.left());
|
||||
if (previous != null) {
|
||||
@@ -87,5 +88,6 @@ public class ComponentModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put(entry.left().asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,13 @@ public class CustomModelDataModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.customModelData(argument);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.CUSTOM_MODEL_DATA);
|
||||
if (previous != null) {
|
||||
@@ -42,5 +43,6 @@ public class CustomModelDataModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put("CustomModelData", NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,13 @@ public class CustomNameModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.customNameComponent(AdventureHelper.miniMessage().deserialize(this.argument, context.tagResolvers()));
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.CUSTOM_NAME);
|
||||
if (previous != null) {
|
||||
@@ -43,5 +44,6 @@ public class CustomNameModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put("display.Name", NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,13 @@ public class DyedColorModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.dyedColor(this.color);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.DYED_COLOR);
|
||||
if (previous != null) {
|
||||
@@ -42,5 +43,6 @@ public class DyedColorModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put("display.color", NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,17 +28,18 @@ public class DynamicLoreModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
String displayContext = Optional.ofNullable(item.getJavaTag("craftengine:display_context")).orElse(this.defaultContext).toString();
|
||||
List<String> lore = this.displayContexts.get(displayContext);
|
||||
if (lore == null) {
|
||||
lore = this.displayContexts.get(this.defaultContext);
|
||||
}
|
||||
item.loreComponent(lore.stream().map(it -> AdventureHelper.miniMessage().deserialize(it, context.tagResolvers())).toList());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.LORE);
|
||||
if (previous != null) {
|
||||
@@ -54,5 +55,6 @@ public class DynamicLoreModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put("display.Lore", NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,16 +20,17 @@ public class EnchantmentModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
if (item.vanillaId().equals(ItemKeys.ENCHANTED_BOOK)) {
|
||||
item.setStoredEnchantments(this.enchantments);
|
||||
} else {
|
||||
item.setEnchantments(this.enchantments);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (item.vanillaId().equals(ItemKeys.ENCHANTED_BOOK)) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.STORED_ENCHANTMENTS);
|
||||
@@ -63,5 +64,6 @@ public class EnchantmentModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ public class EquippableModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.equippable(this.data);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,14 @@ public class ExternalModifier<I> implements ItemDataModifier<I> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
I another = this.provider.build(id, context);
|
||||
if (another == null) {
|
||||
CraftEngine.instance().logger().warn("'" + id + "' could not be found in " + provider.plugin());
|
||||
return;
|
||||
return item;
|
||||
}
|
||||
Item<I> anotherWrapped = (Item<I>) CraftEngine.instance().itemManager().wrap(another);
|
||||
item.merge(anotherWrapped);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,21 +26,23 @@ public class FoodModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.setJavaComponent(ComponentKeys.FOOD, Map.of(
|
||||
"nutrition", this.nutrition,
|
||||
"saturation", this.saturation,
|
||||
"can_always_eat", this.canAlwaysEat
|
||||
));
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.FOOD);
|
||||
if (previous != null) {
|
||||
networkData.put(ComponentKeys.FOOD.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous));
|
||||
} else {
|
||||
networkData.put(ComponentKeys.FOOD.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ public class IdModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.customId(this.argument);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ public interface ItemDataModifier<I> {
|
||||
|
||||
String name();
|
||||
|
||||
void apply(Item<I> item, ItemBuildContext context);
|
||||
Item<I> apply(Item<I> item, ItemBuildContext context);
|
||||
|
||||
default void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
default Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,19 @@ public class ItemModelModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.itemModel(this.data.toString());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.ITEM_MODEL);
|
||||
if (previous != null) {
|
||||
networkData.put(ComponentKeys.ITEM_MODEL.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous));
|
||||
} else {
|
||||
networkData.put(ComponentKeys.ITEM_MODEL.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,13 @@ public class ItemNameModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.itemNameComponent(AdventureHelper.miniMessage().deserialize(this.argument, context.tagResolvers()));
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.ITEM_NAME);
|
||||
if (previous != null) {
|
||||
@@ -43,5 +44,6 @@ public class ItemNameModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put("display.Name", NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ public class JukeboxSongModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.jukeboxSong(this.song);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,13 @@ public class LoreModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.loreComponent(this.argument.stream().map(it -> AdventureHelper.miniMessage().deserialize(it, context.tagResolvers())).toList());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.LORE);
|
||||
if (previous != null) {
|
||||
@@ -45,5 +46,6 @@ public class LoreModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put("display.Lore", NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,19 +26,21 @@ public class RemoveComponentModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
for (String argument : this.arguments) {
|
||||
item.removeComponent(argument);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
for (String component : this.arguments) {
|
||||
Tag previous = item.getNBTComponent(component);
|
||||
if (previous != null) {
|
||||
networkData.put(component, NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,17 +28,18 @@ public class TagsModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
for (Map.Entry<String, Object> entry : this.arguments.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
item.setTag(value, key);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
// TODO NOT PERFECT
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
for (Map.Entry<String, Object> entry : this.arguments.entrySet()) {
|
||||
Tag previous = item.getNBTTag(entry.getKey());
|
||||
if (previous != null) {
|
||||
@@ -47,6 +48,7 @@ public class TagsModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put(entry.getKey(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private static Map<String, Object> mapToMap(final Map<String, Object> source) {
|
||||
|
||||
@@ -21,17 +21,19 @@ public class TooltipStyleModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.tooltipStyle(argument.toString());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.TOOLTIP_STYLE);
|
||||
if (previous != null) {
|
||||
networkData.put(ComponentKeys.TOOLTIP_STYLE.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous));
|
||||
} else {
|
||||
networkData.put(ComponentKeys.TOOLTIP_STYLE.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@ public class TrimModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.trim(new Trim(this.material, this.pattern));
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.TRIM);
|
||||
if (previous != null) {
|
||||
@@ -41,5 +42,6 @@ public class TrimModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put("Trim", NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,13 @@ public class UnbreakableModifier<I> implements ItemDataModifier<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.unbreakable(this.argument);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getNBTComponent(ComponentKeys.UNBREAKABLE);
|
||||
if (previous != null) {
|
||||
@@ -42,5 +43,6 @@ public class UnbreakableModifier<I> implements ItemDataModifier<I> {
|
||||
networkData.put("Unbreakable", NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,6 @@ public class SelfHostHttpServer {
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
CraftEngine.instance().logger().warn("Channel error", cause);
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.4
|
||||
anti_grief_version=0.17
|
||||
nms_helper_version=0.67.7
|
||||
nms_helper_version=0.67.9
|
||||
evalex_version=3.5.0
|
||||
reactive_streams_version=1.0.4
|
||||
amazon_awssdk_version=2.31.23
|
||||
|
||||
Reference in New Issue
Block a user