mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 12:29:15 +00:00
准备merchant所需的类
This commit is contained in:
@@ -7,6 +7,7 @@ import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||
import org.bukkit.inventory.AnvilInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.Merchant;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LegacyInventoryUtils {
|
||||
@@ -68,6 +69,10 @@ public class LegacyInventoryUtils {
|
||||
player.openWorkbench(null, true);
|
||||
}
|
||||
|
||||
public static void openMerchant(Player player, Merchant merchant) {
|
||||
player.openMerchant(merchant, true);
|
||||
}
|
||||
|
||||
public static Player getPlayerFromInventoryEvent(InventoryEvent event) {
|
||||
return (Player) event.getView().getPlayer();
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
Object armorTrim = FastNMS.INSTANCE.constructor$ArmorTrim(optionalMaterial.get(), optionalPattern.get());
|
||||
Object previousTrim;
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
previousTrim = base.getExactComponent(ComponentKeys.TRIM);
|
||||
previousTrim = base.getExactComponent(DataComponentKeys.TRIM);
|
||||
} else {
|
||||
try {
|
||||
previousTrim = VersionHelper.isOrAbove1_20_2() ?
|
||||
@@ -424,7 +424,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
}
|
||||
Item<ItemStack> newItem = base.copyWithCount(1);
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
newItem.setExactComponent(ComponentKeys.TRIM, armorTrim);
|
||||
newItem.setExactComponent(DataComponentKeys.TRIM, armorTrim);
|
||||
} else {
|
||||
try {
|
||||
CoreReflections.method$ArmorTrim$setTrim.invoke(null, FastNMS.INSTANCE.registryAccess(), newItem.getLiteralObject(), armorTrim);
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
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.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
public class ComponentTypes {
|
||||
public static final Object CUSTOM_MODEL_DATA = getComponentType(ComponentKeys.CUSTOM_MODEL_DATA);
|
||||
public static final Object CUSTOM_NAME = getComponentType(ComponentKeys.CUSTOM_NAME);
|
||||
public static final Object ITEM_NAME = getComponentType(ComponentKeys.ITEM_NAME);
|
||||
public static final Object LORE = getComponentType(ComponentKeys.LORE);
|
||||
public static final Object DAMAGE = getComponentType(ComponentKeys.DAMAGE);
|
||||
public static final Object MAX_DAMAGE = getComponentType(ComponentKeys.MAX_DAMAGE);
|
||||
public static final Object ENCHANTMENT_GLINT_OVERRIDE = getComponentType(ComponentKeys.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
public static final Object ENCHANTMENTS = getComponentType(ComponentKeys.ENCHANTMENTS);
|
||||
public static final Object STORED_ENCHANTMENTS = getComponentType(ComponentKeys.STORED_ENCHANTMENTS);
|
||||
public static final Object UNBREAKABLE = getComponentType(ComponentKeys.UNBREAKABLE);
|
||||
public static final Object MAX_STACK_SIZE = getComponentType(ComponentKeys.MAX_STACK_SIZE);
|
||||
public static final Object EQUIPPABLE = getComponentType(ComponentKeys.EQUIPPABLE);
|
||||
public static final Object ITEM_MODEL = getComponentType(ComponentKeys.ITEM_MODEL);
|
||||
public static final Object TOOLTIP_STYLE = getComponentType(ComponentKeys.TOOLTIP_STYLE);
|
||||
public static final Object JUKEBOX_PLAYABLE = getComponentType(ComponentKeys.JUKEBOX_PLAYABLE);
|
||||
public static final Object TRIM = getComponentType(ComponentKeys.TRIM);
|
||||
public static final Object REPAIR_COST = getComponentType(ComponentKeys.REPAIR_COST);
|
||||
public static final Object CUSTOM_DATA = getComponentType(ComponentKeys.CUSTOM_DATA);
|
||||
public static final Object PROFILE = getComponentType(ComponentKeys.PROFILE);
|
||||
public static final Object DYED_COLOR = getComponentType(ComponentKeys.DYED_COLOR);
|
||||
public static final Object DEATH_PROTECTION = getComponentType(ComponentKeys.DEATH_PROTECTION);
|
||||
public static final Object FIREWORK_EXPLOSION = getComponentType(ComponentKeys.FIREWORK_EXPLOSION);
|
||||
public static final Object BUNDLE_CONTENTS = getComponentType(ComponentKeys.BUNDLE_CONTENTS);
|
||||
public static final Object CONTAINER = getComponentType(ComponentKeys.CONTAINER);
|
||||
public static final Object BLOCK_STATE = getComponentType(ComponentKeys.BLOCK_STATE);
|
||||
|
||||
private ComponentTypes() {}
|
||||
|
||||
private static Object getComponentType(Key key) {
|
||||
if (!VersionHelper.isOrAbove1_20_5()) return null;
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.DATA_COMPONENT_TYPE, KeyUtils.toResourceLocation(key));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
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.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
public final class DataComponentPredicateTypes {
|
||||
private DataComponentPredicateTypes() {}
|
||||
|
||||
public static Object byId(Key key) {
|
||||
if (!VersionHelper.isOrAbove1_21_5()) return null;
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.DATA_COMPONENT_PREDICATE_TYPE, KeyUtils.toResourceLocation(key));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
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.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
public final class DataComponentTypes {
|
||||
public static final Object CUSTOM_MODEL_DATA = byId(DataComponentKeys.CUSTOM_MODEL_DATA);
|
||||
public static final Object CUSTOM_NAME = byId(DataComponentKeys.CUSTOM_NAME);
|
||||
public static final Object ITEM_NAME = byId(DataComponentKeys.ITEM_NAME);
|
||||
public static final Object LORE = byId(DataComponentKeys.LORE);
|
||||
public static final Object DAMAGE = byId(DataComponentKeys.DAMAGE);
|
||||
public static final Object MAX_DAMAGE = byId(DataComponentKeys.MAX_DAMAGE);
|
||||
public static final Object ENCHANTMENT_GLINT_OVERRIDE = byId(DataComponentKeys.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
public static final Object ENCHANTMENTS = byId(DataComponentKeys.ENCHANTMENTS);
|
||||
public static final Object STORED_ENCHANTMENTS = byId(DataComponentKeys.STORED_ENCHANTMENTS);
|
||||
public static final Object UNBREAKABLE = byId(DataComponentKeys.UNBREAKABLE);
|
||||
public static final Object MAX_STACK_SIZE = byId(DataComponentKeys.MAX_STACK_SIZE);
|
||||
public static final Object EQUIPPABLE = byId(DataComponentKeys.EQUIPPABLE);
|
||||
public static final Object ITEM_MODEL = byId(DataComponentKeys.ITEM_MODEL);
|
||||
public static final Object TOOLTIP_STYLE = byId(DataComponentKeys.TOOLTIP_STYLE);
|
||||
public static final Object JUKEBOX_PLAYABLE = byId(DataComponentKeys.JUKEBOX_PLAYABLE);
|
||||
public static final Object TRIM = byId(DataComponentKeys.TRIM);
|
||||
public static final Object REPAIR_COST = byId(DataComponentKeys.REPAIR_COST);
|
||||
public static final Object CUSTOM_DATA = byId(DataComponentKeys.CUSTOM_DATA);
|
||||
public static final Object PROFILE = byId(DataComponentKeys.PROFILE);
|
||||
public static final Object DYED_COLOR = byId(DataComponentKeys.DYED_COLOR);
|
||||
public static final Object DEATH_PROTECTION = byId(DataComponentKeys.DEATH_PROTECTION);
|
||||
public static final Object FIREWORK_EXPLOSION = byId(DataComponentKeys.FIREWORK_EXPLOSION);
|
||||
public static final Object BUNDLE_CONTENTS = byId(DataComponentKeys.BUNDLE_CONTENTS);
|
||||
public static final Object CONTAINER = byId(DataComponentKeys.CONTAINER);
|
||||
public static final Object BLOCK_STATE = byId(DataComponentKeys.BLOCK_STATE);
|
||||
|
||||
private DataComponentTypes() {}
|
||||
|
||||
public static Object byId(Key key) {
|
||||
if (!VersionHelper.isOrAbove1_20_5()) return null;
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.DATA_COMPONENT_TYPE, KeyUtils.toResourceLocation(key));
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
boolean forceReturn = false;
|
||||
|
||||
// 处理收纳袋
|
||||
if (wrapped.hasComponent(ComponentTypes.BUNDLE_CONTENTS)) {
|
||||
Object bundleContents = wrapped.getExactComponent(ComponentTypes.BUNDLE_CONTENTS);
|
||||
if (wrapped.hasComponent(DataComponentTypes.BUNDLE_CONTENTS)) {
|
||||
Object bundleContents = wrapped.getExactComponent(DataComponentTypes.BUNDLE_CONTENTS);
|
||||
List<Object> newItems = new ArrayList<>();
|
||||
boolean changed = false;
|
||||
for (Object previousItem : FastNMS.INSTANCE.method$BundleContents$items(bundleContents)) {
|
||||
@@ -48,14 +48,14 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
wrapped.setExactComponent(ComponentTypes.BUNDLE_CONTENTS, FastNMS.INSTANCE.constructor$BundleContents(newItems));
|
||||
wrapped.setExactComponent(DataComponentTypes.BUNDLE_CONTENTS, FastNMS.INSTANCE.constructor$BundleContents(newItems));
|
||||
forceReturn = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理潜影盒等
|
||||
if (wrapped.hasComponent(ComponentTypes.CONTAINER)) {
|
||||
Object containerContents = wrapped.getExactComponent(ComponentTypes.CONTAINER);
|
||||
if (wrapped.hasComponent(DataComponentTypes.CONTAINER)) {
|
||||
Object containerContents = wrapped.getExactComponent(DataComponentTypes.CONTAINER);
|
||||
List<Object> newItems = new ArrayList<>();
|
||||
boolean changed = false;
|
||||
for (Object previousItem : FastNMS.INSTANCE.field$ItemContainerContents$items(containerContents)) {
|
||||
@@ -68,7 +68,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
wrapped.setExactComponent(ComponentTypes.CONTAINER, FastNMS.INSTANCE.method$ItemContainerContents$fromItems(newItems));
|
||||
wrapped.setExactComponent(DataComponentTypes.CONTAINER, FastNMS.INSTANCE.method$ItemContainerContents$fromItems(newItems));
|
||||
forceReturn = true;
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
}
|
||||
|
||||
// 获取custom data
|
||||
Tag customData = wrapped.getSparrowNBTComponent(ComponentTypes.CUSTOM_DATA);
|
||||
Tag customData = wrapped.getSparrowNBTComponent(DataComponentTypes.CUSTOM_DATA);
|
||||
if (customData instanceof CompoundTag compoundTag) {
|
||||
CompoundTag networkData = compoundTag.getCompound(NETWORK_ITEM_TAG);
|
||||
if (networkData != null) {
|
||||
@@ -100,9 +100,9 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
}
|
||||
|
||||
// 如果清空了,则直接移除这个组件
|
||||
if (compoundTag.isEmpty()) wrapped.resetComponent(ComponentTypes.CUSTOM_DATA);
|
||||
if (compoundTag.isEmpty()) wrapped.resetComponent(DataComponentTypes.CUSTOM_DATA);
|
||||
// 否则设置为新的
|
||||
else wrapped.setNBTComponent(ComponentTypes.CUSTOM_DATA, compoundTag);
|
||||
else wrapped.setNBTComponent(DataComponentTypes.CUSTOM_DATA, compoundTag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,8 +114,8 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
boolean forceReturn = false;
|
||||
|
||||
// 处理收纳袋
|
||||
if (wrapped.hasComponent(ComponentTypes.BUNDLE_CONTENTS)) {
|
||||
Object bundleContents = wrapped.getExactComponent(ComponentTypes.BUNDLE_CONTENTS);
|
||||
if (wrapped.hasComponent(DataComponentTypes.BUNDLE_CONTENTS)) {
|
||||
Object bundleContents = wrapped.getExactComponent(DataComponentTypes.BUNDLE_CONTENTS);
|
||||
List<Object> newItems = new ArrayList<>();
|
||||
boolean changed = false;
|
||||
for (Object previousItem : FastNMS.INSTANCE.method$BundleContents$items(bundleContents)) {
|
||||
@@ -128,14 +128,14 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
wrapped.setExactComponent(ComponentTypes.BUNDLE_CONTENTS, FastNMS.INSTANCE.constructor$BundleContents(newItems));
|
||||
wrapped.setExactComponent(DataComponentTypes.BUNDLE_CONTENTS, FastNMS.INSTANCE.constructor$BundleContents(newItems));
|
||||
forceReturn = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理潜影盒等
|
||||
if (wrapped.hasComponent(ComponentTypes.CONTAINER)) {
|
||||
Object containerContents = wrapped.getExactComponent(ComponentTypes.CONTAINER);
|
||||
if (wrapped.hasComponent(DataComponentTypes.CONTAINER)) {
|
||||
Object containerContents = wrapped.getExactComponent(DataComponentTypes.CONTAINER);
|
||||
List<Object> newItems = new ArrayList<>();
|
||||
for (Object previousItem : FastNMS.INSTANCE.field$ItemContainerContents$items(containerContents)) {
|
||||
boolean changed = false;
|
||||
@@ -147,7 +147,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
newItems.add(previousItem);
|
||||
}
|
||||
if (changed) {
|
||||
wrapped.setExactComponent(ComponentTypes.CONTAINER, FastNMS.INSTANCE.method$ItemContainerContents$fromItems(newItems));
|
||||
wrapped.setExactComponent(DataComponentTypes.CONTAINER, FastNMS.INSTANCE.method$ItemContainerContents$fromItems(newItems));
|
||||
forceReturn = true;
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
return new OtherItem(wrapped, forceReturn).process(NetworkTextReplaceContext.of(player));
|
||||
}
|
||||
// 获取custom data
|
||||
CompoundTag customData = Optional.ofNullable(wrapped.getSparrowNBTComponent(ComponentTypes.CUSTOM_DATA))
|
||||
CompoundTag customData = Optional.ofNullable(wrapped.getSparrowNBTComponent(DataComponentTypes.CUSTOM_DATA))
|
||||
.map(CompoundTag.class::cast)
|
||||
.orElseGet(CompoundTag::new);
|
||||
CompoundTag arguments = customData.getCompound(ArgumentsModifier.ARGUMENTS_TAG);
|
||||
@@ -206,15 +206,15 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
}
|
||||
// 如果拦截物品的描述名称等
|
||||
if (Config.interceptItem()) {
|
||||
if (!tag.containsKey(ComponentIds.ITEM_NAME)) {
|
||||
if (!tag.containsKey(DataComponentIds.ITEM_NAME)) {
|
||||
if (VersionHelper.isOrAbove1_21_5()) processModernItemName(wrapped, () -> tag, context);
|
||||
else processLegacyItemName(wrapped, () -> tag, context);
|
||||
}
|
||||
if (!tag.containsKey(ComponentIds.CUSTOM_NAME)) {
|
||||
if (!tag.containsKey(DataComponentIds.CUSTOM_NAME)) {
|
||||
if (VersionHelper.isOrAbove1_21_5()) processModernCustomName(wrapped, () -> tag, context);
|
||||
else processLegacyCustomName(wrapped, () -> tag, context);
|
||||
}
|
||||
if (!tag.containsKey(ComponentIds.LORE)) {
|
||||
if (!tag.containsKey(DataComponentIds.LORE)) {
|
||||
if (VersionHelper.isOrAbove1_21_5()) processModernLore(wrapped, () -> tag, context);
|
||||
else processLegacyLore(wrapped, () -> tag, context);
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
// 如果tag不空,则需要返回
|
||||
if (!tag.isEmpty()) {
|
||||
customData.put(NETWORK_ITEM_TAG, tag);
|
||||
wrapped.setNBTComponent(ComponentTypes.CUSTOM_DATA, customData);
|
||||
wrapped.setNBTComponent(DataComponentTypes.CUSTOM_DATA, customData);
|
||||
forceReturn = true;
|
||||
}
|
||||
return forceReturn ? Optional.of(wrapped) : Optional.empty();
|
||||
@@ -249,7 +249,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
for (String line : lore) {
|
||||
listTag.add(new StringTag(line));
|
||||
}
|
||||
tag.get().put(ComponentIds.LORE, NetworkItemHandler.pack(Operation.ADD, listTag));
|
||||
tag.get().put(DataComponentIds.LORE, NetworkItemHandler.pack(Operation.ADD, listTag));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -263,7 +263,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
Map<String, ComponentProvider> tokens = CraftEngine.instance().fontManager().matchTags(line);
|
||||
if (!tokens.isEmpty()) {
|
||||
item.customNameJson(AdventureHelper.componentToJson(AdventureHelper.replaceText(AdventureHelper.jsonToComponent(line), tokens, context)));
|
||||
tag.get().put(ComponentIds.CUSTOM_NAME, NetworkItemHandler.pack(Operation.ADD, new StringTag(line)));
|
||||
tag.get().put(DataComponentIds.CUSTOM_NAME, NetworkItemHandler.pack(Operation.ADD, new StringTag(line)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -277,7 +277,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
Map<String, ComponentProvider> tokens = CraftEngine.instance().fontManager().matchTags(line);
|
||||
if (!tokens.isEmpty()) {
|
||||
item.itemNameJson(AdventureHelper.componentToJson(AdventureHelper.replaceText(AdventureHelper.jsonToComponent(line), tokens, context)));
|
||||
tag.get().put(ComponentIds.ITEM_NAME, NetworkItemHandler.pack(Operation.ADD, new StringTag(line)));
|
||||
tag.get().put(DataComponentIds.ITEM_NAME, NetworkItemHandler.pack(Operation.ADD, new StringTag(line)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -285,31 +285,31 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
}
|
||||
|
||||
public static boolean processModernItemName(Item<ItemStack> item, Supplier<CompoundTag> tag, Context context) {
|
||||
Tag nameTag = item.getSparrowNBTComponent(ComponentTypes.ITEM_NAME);
|
||||
Tag nameTag = item.getSparrowNBTComponent(DataComponentTypes.ITEM_NAME);
|
||||
if (nameTag == null) return false;
|
||||
Map<String, ComponentProvider> tokens = CraftEngine.instance().fontManager().matchTags(nameTag);
|
||||
if (!tokens.isEmpty()) {
|
||||
item.setNBTComponent(ComponentKeys.ITEM_NAME, AdventureHelper.componentToNbt(AdventureHelper.replaceText(AdventureHelper.nbtToComponent(nameTag), tokens, context)));
|
||||
tag.get().put(ComponentIds.ITEM_NAME, NetworkItemHandler.pack(Operation.ADD, nameTag));
|
||||
item.setNBTComponent(DataComponentKeys.ITEM_NAME, AdventureHelper.componentToNbt(AdventureHelper.replaceText(AdventureHelper.nbtToComponent(nameTag), tokens, context)));
|
||||
tag.get().put(DataComponentIds.ITEM_NAME, NetworkItemHandler.pack(Operation.ADD, nameTag));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean processModernCustomName(Item<ItemStack> item, Supplier<CompoundTag> tag, Context context) {
|
||||
Tag nameTag = item.getSparrowNBTComponent(ComponentTypes.CUSTOM_NAME);
|
||||
Tag nameTag = item.getSparrowNBTComponent(DataComponentTypes.CUSTOM_NAME);
|
||||
if (nameTag == null) return false;
|
||||
Map<String, ComponentProvider> tokens = CraftEngine.instance().fontManager().matchTags(nameTag);
|
||||
if (!tokens.isEmpty()) {
|
||||
item.setNBTComponent(ComponentKeys.CUSTOM_NAME, AdventureHelper.componentToNbt(AdventureHelper.replaceText(AdventureHelper.nbtToComponent(nameTag), tokens, context)));
|
||||
tag.get().put(ComponentIds.CUSTOM_NAME, NetworkItemHandler.pack(Operation.ADD, nameTag));
|
||||
item.setNBTComponent(DataComponentKeys.CUSTOM_NAME, AdventureHelper.componentToNbt(AdventureHelper.replaceText(AdventureHelper.nbtToComponent(nameTag), tokens, context)));
|
||||
tag.get().put(DataComponentIds.CUSTOM_NAME, NetworkItemHandler.pack(Operation.ADD, nameTag));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean processModernLore(Item<ItemStack> item, Supplier<CompoundTag> tagSupplier, Context context) {
|
||||
Tag loreTag = item.getSparrowNBTComponent(ComponentTypes.LORE);
|
||||
Tag loreTag = item.getSparrowNBTComponent(DataComponentTypes.LORE);
|
||||
boolean changed = false;
|
||||
if (!(loreTag instanceof ListTag listTag)) {
|
||||
return false;
|
||||
@@ -325,8 +325,8 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
item.setNBTComponent(ComponentKeys.LORE, newLore);
|
||||
tagSupplier.get().put(ComponentIds.LORE, NetworkItemHandler.pack(Operation.ADD, listTag));
|
||||
item.setNBTComponent(DataComponentKeys.LORE, newLore);
|
||||
tagSupplier.get().put(DataComponentIds.LORE, NetworkItemHandler.pack(Operation.ADD, listTag));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -360,11 +360,11 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler<ItemSt
|
||||
this.globalChanged = true;
|
||||
}
|
||||
if (this.globalChanged) {
|
||||
CompoundTag customData = Optional.ofNullable(this.item.getSparrowNBTComponent(ComponentTypes.CUSTOM_DATA))
|
||||
CompoundTag customData = Optional.ofNullable(this.item.getSparrowNBTComponent(DataComponentTypes.CUSTOM_DATA))
|
||||
.map(CompoundTag.class::cast)
|
||||
.orElseGet(CompoundTag::new);
|
||||
customData.put(NETWORK_ITEM_TAG, getOrCreateTag());
|
||||
this.item.setNBTComponent(ComponentKeys.CUSTOM_DATA, customData);
|
||||
this.item.setNBTComponent(DataComponentKeys.CUSTOM_DATA, customData);
|
||||
return Optional.of(this.item);
|
||||
} else if (this.forceReturn) {
|
||||
return Optional.of(this.item);
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.momirealms.craftengine.bukkit.item.factory;
|
||||
import com.google.gson.JsonElement;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.DataComponentTypes;
|
||||
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;
|
||||
@@ -11,7 +11,7 @@ import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOp
|
||||
import net.momirealms.craftengine.bukkit.util.EnchantmentUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.core.attribute.AttributeModifier;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.data.Enchantment;
|
||||
import net.momirealms.craftengine.core.item.data.FireworkExplosion;
|
||||
import net.momirealms.craftengine.core.item.data.Trim;
|
||||
@@ -49,7 +49,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Object getJavaTag(ComponentItemWrapper item, Object... path) {
|
||||
Map<String, Object> rootMap = (Map<String, Object>) item.getJavaComponent(ComponentTypes.CUSTOM_DATA).orElse(null);
|
||||
Map<String, Object> rootMap = (Map<String, Object>) item.getJavaComponent(DataComponentTypes.CUSTOM_DATA).orElse(null);
|
||||
if (rootMap == null) return null;
|
||||
Object currentObj = rootMap;
|
||||
for (int i = 0; i < path.length; i++) {
|
||||
@@ -70,7 +70,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Override
|
||||
protected Object getExactTag(ComponentItemWrapper item, Object... path) {
|
||||
Object customData = getExactComponent(item, ComponentTypes.CUSTOM_DATA);
|
||||
Object customData = getExactComponent(item, DataComponentTypes.CUSTOM_DATA);
|
||||
if (customData == null) return null;
|
||||
Object currentTag = FastNMS.INSTANCE.method$CustomData$getUnsafe(customData);
|
||||
for (int i = 0; i < path.length; i++) {
|
||||
@@ -90,7 +90,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
|
||||
@Override
|
||||
protected Tag getTag(ComponentItemWrapper item, Object... path) {
|
||||
CompoundTag rootTag = (CompoundTag) item.getSparrowNBTComponent(ComponentTypes.CUSTOM_DATA).orElse(null);
|
||||
CompoundTag rootTag = (CompoundTag) item.getSparrowNBTComponent(DataComponentTypes.CUSTOM_DATA).orElse(null);
|
||||
if (rootTag == null) return null;
|
||||
Tag currentTag = rootTag;
|
||||
for (int i = 0; i < path.length; i++) {
|
||||
@@ -123,7 +123,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
valueTag = MRegistryOps.JAVA.convertTo(MRegistryOps.SPARROW_NBT, value);
|
||||
}
|
||||
|
||||
CompoundTag rootTag = (CompoundTag) item.getSparrowNBTComponent(ComponentTypes.CUSTOM_DATA).orElseGet(CompoundTag::new);
|
||||
CompoundTag rootTag = (CompoundTag) item.getSparrowNBTComponent(DataComponentTypes.CUSTOM_DATA).orElseGet(CompoundTag::new);
|
||||
|
||||
if (path == null || path.length == 0) {
|
||||
if (valueTag instanceof CompoundTag) {
|
||||
@@ -151,7 +151,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
currentTag.put(finalKey, valueTag);
|
||||
}
|
||||
|
||||
item.setSparrowNBTComponent(ComponentTypes.CUSTOM_DATA, rootTag);
|
||||
item.setSparrowNBTComponent(DataComponentTypes.CUSTOM_DATA, rootTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,14 +161,14 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
|
||||
@Override
|
||||
protected boolean removeTag(ComponentItemWrapper item, Object... path) {
|
||||
CompoundTag rootTag = (CompoundTag) item.getSparrowNBTComponent(ComponentTypes.CUSTOM_DATA).orElse(null);
|
||||
CompoundTag rootTag = (CompoundTag) item.getSparrowNBTComponent(DataComponentTypes.CUSTOM_DATA).orElse(null);
|
||||
if (rootTag == null || path == null || path.length == 0) return false;
|
||||
|
||||
if (path.length == 1) {
|
||||
String key = path[0].toString();
|
||||
if (rootTag.containsKey(key)) {
|
||||
rootTag.remove(key);
|
||||
item.setSparrowNBTComponent(ComponentTypes.CUSTOM_DATA, rootTag);
|
||||
item.setSparrowNBTComponent(DataComponentTypes.CUSTOM_DATA, rootTag);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -191,7 +191,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
String finalKey = path[path.length - 1].toString();
|
||||
if (parentTag.containsKey(finalKey)) {
|
||||
parentTag.remove(finalKey);
|
||||
item.setSparrowNBTComponent(ComponentTypes.CUSTOM_DATA, rootTag);
|
||||
item.setSparrowNBTComponent(DataComponentTypes.CUSTOM_DATA, rootTag);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -280,115 +280,115 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
@Override
|
||||
protected void customModelData(ComponentItemWrapper item, Integer data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.CUSTOM_MODEL_DATA);
|
||||
item.resetComponent(DataComponentTypes.CUSTOM_MODEL_DATA);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.CUSTOM_MODEL_DATA, data);
|
||||
item.setJavaComponent(DataComponentTypes.CUSTOM_MODEL_DATA, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(ComponentItemWrapper item) {
|
||||
return item.getJavaComponent(ComponentTypes.CUSTOM_MODEL_DATA);
|
||||
return item.getJavaComponent(DataComponentTypes.CUSTOM_MODEL_DATA);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customNameJson(ComponentItemWrapper item, String json) {
|
||||
if (json == null) {
|
||||
item.resetComponent(ComponentTypes.CUSTOM_NAME);
|
||||
item.resetComponent(DataComponentTypes.CUSTOM_NAME);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.CUSTOM_NAME, json);
|
||||
item.setJavaComponent(DataComponentTypes.CUSTOM_NAME, json);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> customNameJson(ComponentItemWrapper item) {
|
||||
return item.getJavaComponent(ComponentTypes.CUSTOM_NAME);
|
||||
return item.getJavaComponent(DataComponentTypes.CUSTOM_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemNameJson(ComponentItemWrapper item, String json) {
|
||||
if (json == null) {
|
||||
item.resetComponent(ComponentTypes.ITEM_NAME);
|
||||
item.resetComponent(DataComponentTypes.ITEM_NAME);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.ITEM_NAME, json);
|
||||
item.setJavaComponent(DataComponentTypes.ITEM_NAME, json);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemNameJson(ComponentItemWrapper item) {
|
||||
return item.getJavaComponent(ComponentTypes.ITEM_NAME);
|
||||
return item.getJavaComponent(DataComponentTypes.ITEM_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void skull(ComponentItemWrapper item, String skullData) {
|
||||
if (skullData == null) {
|
||||
item.resetComponent(ComponentTypes.PROFILE);
|
||||
item.resetComponent(DataComponentTypes.PROFILE);
|
||||
} else {
|
||||
Map<String, Object> profile = Map.of("properties", List.of(Map.of("name", "textures", "value", skullData)));
|
||||
item.setJavaComponent(ComponentTypes.PROFILE, profile);
|
||||
item.setJavaComponent(DataComponentTypes.PROFILE, profile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<List<String>> loreJson(ComponentItemWrapper item) {
|
||||
return item.getJavaComponent(ComponentTypes.LORE);
|
||||
return item.getJavaComponent(DataComponentTypes.LORE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loreJson(ComponentItemWrapper item, List<String> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
item.resetComponent(ComponentTypes.LORE);
|
||||
item.resetComponent(DataComponentTypes.LORE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.LORE, lore);
|
||||
item.setJavaComponent(DataComponentTypes.LORE, lore);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean unbreakable(ComponentItemWrapper item) {
|
||||
return item.hasComponent(ComponentTypes.UNBREAKABLE);
|
||||
return item.hasComponent(DataComponentTypes.UNBREAKABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unbreakable(ComponentItemWrapper item, boolean unbreakable) {
|
||||
if (unbreakable) {
|
||||
item.setJavaComponent(ComponentTypes.UNBREAKABLE, Map.of());
|
||||
item.setJavaComponent(DataComponentTypes.UNBREAKABLE, Map.of());
|
||||
} else {
|
||||
item.resetComponent(ComponentTypes.UNBREAKABLE);
|
||||
item.resetComponent(DataComponentTypes.UNBREAKABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Boolean> glint(ComponentItemWrapper item) {
|
||||
return Optional.ofNullable((Boolean) item.getComponentExact(ComponentTypes.ENCHANTMENT_GLINT_OVERRIDE));
|
||||
return Optional.ofNullable((Boolean) item.getComponentExact(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void glint(ComponentItemWrapper item, Boolean glint) {
|
||||
if (glint == null) {
|
||||
item.resetComponent(ComponentTypes.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
item.resetComponent(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, glint);
|
||||
item.setJavaComponent(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, glint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> damage(ComponentItemWrapper item) {
|
||||
return item.getJavaComponent(ComponentTypes.DAMAGE);
|
||||
return item.getJavaComponent(DataComponentTypes.DAMAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void damage(ComponentItemWrapper item, Integer damage) {
|
||||
if (damage == null) {
|
||||
item.resetComponent(ComponentTypes.DAMAGE);
|
||||
item.resetComponent(DataComponentTypes.DAMAGE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.DAMAGE, damage);
|
||||
item.setJavaComponent(DataComponentTypes.DAMAGE, damage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Color> dyedColor(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.DYED_COLOR)) return Optional.empty();
|
||||
Object javaObj = getJavaComponent(item, ComponentTypes.DYED_COLOR);
|
||||
if (!item.hasComponent(DataComponentTypes.DYED_COLOR)) return Optional.empty();
|
||||
Object javaObj = getJavaComponent(item, DataComponentTypes.DYED_COLOR);
|
||||
if (javaObj instanceof Integer integer) {
|
||||
return Optional.of(Color.fromDecimal(integer));
|
||||
} else if (javaObj instanceof Map<?, ?> map) {
|
||||
@@ -400,30 +400,30 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
@Override
|
||||
protected void dyedColor(ComponentItemWrapper item, Color color) {
|
||||
if (color == null) {
|
||||
item.resetComponent(ComponentTypes.DYED_COLOR);
|
||||
item.resetComponent(DataComponentTypes.DYED_COLOR);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.DYED_COLOR, color.color());
|
||||
item.setJavaComponent(DataComponentTypes.DYED_COLOR, color.color());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int maxDamage(ComponentItemWrapper item) {
|
||||
Optional<Integer> damage = item.getJavaComponent(ComponentTypes.MAX_DAMAGE);
|
||||
Optional<Integer> damage = item.getJavaComponent(DataComponentTypes.MAX_DAMAGE);
|
||||
return damage.orElseGet(() -> (int) item.getItem().getType().getMaxDurability());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void maxDamage(ComponentItemWrapper item, Integer damage) {
|
||||
if (damage == null) {
|
||||
item.resetComponent(ComponentTypes.MAX_DAMAGE);
|
||||
item.resetComponent(DataComponentTypes.MAX_DAMAGE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.MAX_DAMAGE, damage);
|
||||
item.setJavaComponent(DataComponentTypes.MAX_DAMAGE, damage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Enchantment> getEnchantment(ComponentItemWrapper item, Key key) {
|
||||
Object enchant = item.getComponentExact(ComponentTypes.ENCHANTMENTS);
|
||||
Object enchant = item.getComponentExact(DataComponentTypes.ENCHANTMENTS);
|
||||
if (enchant == null) return Optional.empty();
|
||||
try {
|
||||
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
|
||||
@@ -439,26 +439,26 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
@Override
|
||||
protected void enchantments(ComponentItemWrapper item, List<Enchantment> enchantments) {
|
||||
if (enchantments == null || enchantments.isEmpty()) {
|
||||
item.resetComponent(ComponentTypes.ENCHANTMENTS);
|
||||
item.resetComponent(DataComponentTypes.ENCHANTMENTS);
|
||||
} else {
|
||||
Map<String, Integer> enchants = new HashMap<>();
|
||||
for (Enchantment enchantment : enchantments) {
|
||||
enchants.put(enchantment.id().toString(), enchantment.level());
|
||||
}
|
||||
item.setJavaComponent(ComponentTypes.ENCHANTMENTS, enchants);
|
||||
item.setJavaComponent(DataComponentTypes.ENCHANTMENTS, enchants);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storedEnchantments(ComponentItemWrapper item, List<Enchantment> enchantments) {
|
||||
if (enchantments == null || enchantments.isEmpty()) {
|
||||
item.resetComponent(ComponentTypes.STORED_ENCHANTMENTS);
|
||||
item.resetComponent(DataComponentTypes.STORED_ENCHANTMENTS);
|
||||
} else {
|
||||
Map<String, Integer> enchants = new HashMap<>();
|
||||
for (Enchantment enchantment : enchantments) {
|
||||
enchants.put(enchantment.id().toString(), enchantment.level());
|
||||
}
|
||||
item.setJavaComponent(ComponentTypes.STORED_ENCHANTMENTS, enchants);
|
||||
item.setJavaComponent(DataComponentTypes.STORED_ENCHANTMENTS, enchants);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,39 +469,39 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
|
||||
@Override
|
||||
protected int maxStackSize(ComponentItemWrapper item) {
|
||||
Optional<Integer> stackSize = item.getJavaComponent(ComponentTypes.MAX_STACK_SIZE);
|
||||
Optional<Integer> stackSize = item.getJavaComponent(DataComponentTypes.MAX_STACK_SIZE);
|
||||
return stackSize.orElseGet(() -> item.getItem().getType().getMaxStackSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void maxStackSize(ComponentItemWrapper item, Integer maxStackSize) {
|
||||
if (maxStackSize == null) {
|
||||
item.resetComponent(ComponentTypes.MAX_STACK_SIZE);
|
||||
item.resetComponent(DataComponentTypes.MAX_STACK_SIZE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.MAX_STACK_SIZE, maxStackSize);
|
||||
item.setJavaComponent(DataComponentTypes.MAX_STACK_SIZE, maxStackSize);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repairCost(ComponentItemWrapper item, Integer data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.REPAIR_COST);
|
||||
item.resetComponent(DataComponentTypes.REPAIR_COST);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.REPAIR_COST, data);
|
||||
item.setJavaComponent(DataComponentTypes.REPAIR_COST, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> repairCost(ComponentItemWrapper item) {
|
||||
return item.getJavaComponent(ComponentTypes.REPAIR_COST);
|
||||
return item.getJavaComponent(DataComponentTypes.REPAIR_COST);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void trim(ComponentItemWrapper item, Trim trim) {
|
||||
if (trim == null) {
|
||||
item.resetComponent(ComponentTypes.TRIM);
|
||||
item.resetComponent(DataComponentTypes.TRIM);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.TRIM, Map.of(
|
||||
item.setJavaComponent(DataComponentTypes.TRIM, Map.of(
|
||||
"pattern", trim.pattern().asString(),
|
||||
"material", trim.material().asString()
|
||||
));
|
||||
@@ -510,7 +510,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
|
||||
@Override
|
||||
protected Optional<Trim> trim(ComponentItemWrapper item) {
|
||||
Optional<Object> trim = item.getJavaComponent(ComponentTypes.TRIM);
|
||||
Optional<Object> trim = item.getJavaComponent(DataComponentTypes.TRIM);
|
||||
if (trim.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -522,7 +522,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Optional<FireworkExplosion> fireworkExplosion(ComponentItemWrapper item) {
|
||||
Optional<Object> optionalExplosion = item.getJavaComponent(ComponentTypes.FIREWORK_EXPLOSION);
|
||||
Optional<Object> optionalExplosion = item.getJavaComponent(DataComponentTypes.FIREWORK_EXPLOSION);
|
||||
if (optionalExplosion.isEmpty()) return Optional.empty();
|
||||
Map<String, Object> explosions = MiscUtils.castToMap(optionalExplosion.get(), false);
|
||||
FireworkExplosion.Shape shape = Optional.ofNullable(FireworkExplosion.Shape.byName((String) explosions.get("shape"))).orElse(FireworkExplosion.Shape.SMALL_BALL);
|
||||
@@ -542,9 +542,9 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
@Override
|
||||
protected void fireworkExplosion(ComponentItemWrapper item, FireworkExplosion explosion) {
|
||||
if (explosion == null) {
|
||||
item.resetComponent(ComponentTypes.FIREWORK_EXPLOSION);
|
||||
item.resetComponent(DataComponentTypes.FIREWORK_EXPLOSION);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.FIREWORK_EXPLOSION, Map.of(
|
||||
item.setJavaComponent(DataComponentTypes.FIREWORK_EXPLOSION, Map.of(
|
||||
"shape", explosion.shape().getName(),
|
||||
"has_trail", explosion.hasTrail(),
|
||||
"has_twinkle", explosion.hasTwinkle(),
|
||||
@@ -590,7 +590,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
|
||||
@Override
|
||||
protected void attributeModifiers(ComponentItemWrapper item, List<AttributeModifier> modifierList) {
|
||||
CompoundTag compoundTag = (CompoundTag) item.getSparrowNBTComponent(ComponentKeys.ATTRIBUTE_MODIFIERS).orElseGet(CompoundTag::new);
|
||||
CompoundTag compoundTag = (CompoundTag) item.getSparrowNBTComponent(DataComponentKeys.ATTRIBUTE_MODIFIERS).orElseGet(CompoundTag::new);
|
||||
ListTag modifiers = new ListTag();
|
||||
compoundTag.put("modifiers", modifiers);
|
||||
for (AttributeModifier modifier : modifierList) {
|
||||
@@ -607,16 +607,16 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
modifierTag.putString("operation", modifier.operation().id());
|
||||
modifiers.add(modifierTag);
|
||||
}
|
||||
item.setSparrowNBTComponent(ComponentKeys.ATTRIBUTE_MODIFIERS, compoundTag);
|
||||
item.setSparrowNBTComponent(DataComponentKeys.ATTRIBUTE_MODIFIERS, compoundTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Map<String, String>> blockState(ComponentItemWrapper item) {
|
||||
return item.getJavaComponent(ComponentTypes.BLOCK_STATE);
|
||||
return item.getJavaComponent(DataComponentTypes.BLOCK_STATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blockState(ComponentItemWrapper item, Map<String, String> state) {
|
||||
item.setJavaComponent(ComponentTypes.BLOCK_STATE, state);
|
||||
item.setJavaComponent(DataComponentTypes.BLOCK_STATE, state);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.DataComponentTypes;
|
||||
import net.momirealms.craftengine.core.item.data.JukeboxPlayable;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ComponentItemFactory1_21 extends ComponentItemFactory1_20_5 {
|
||||
|
||||
@Override
|
||||
protected Optional<JukeboxPlayable> jukeboxSong(ComponentItemWrapper item) {
|
||||
Optional<Map<String, Object>> map = item.getJavaComponent(ComponentTypes.JUKEBOX_PLAYABLE);
|
||||
Optional<Map<String, Object>> map = item.getJavaComponent(DataComponentTypes.JUKEBOX_PLAYABLE);
|
||||
return map.map(song -> new JukeboxPlayable(
|
||||
(String) song.get("song"),
|
||||
(boolean) song.getOrDefault("show_in_tooltip", true))
|
||||
@@ -25,7 +25,7 @@ public class ComponentItemFactory1_21 extends ComponentItemFactory1_20_5 {
|
||||
|
||||
@Override
|
||||
protected void jukeboxSong(ComponentItemWrapper item, JukeboxPlayable data) {
|
||||
item.setJavaComponent(ComponentTypes.JUKEBOX_PLAYABLE, Map.of(
|
||||
item.setJavaComponent(DataComponentTypes.JUKEBOX_PLAYABLE, Map.of(
|
||||
"song", data.song(),
|
||||
"show_in_tooltip", true
|
||||
));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.DataComponentTypes;
|
||||
import net.momirealms.craftengine.core.entity.EquipmentSlot;
|
||||
import net.momirealms.craftengine.core.item.setting.EquipmentData;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
@@ -21,43 +21,43 @@ public class ComponentItemFactory1_21_2 extends ComponentItemFactory1_21 {
|
||||
@Override
|
||||
protected void tooltipStyle(ComponentItemWrapper item, String data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.TOOLTIP_STYLE);
|
||||
item.resetComponent(DataComponentTypes.TOOLTIP_STYLE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.TOOLTIP_STYLE, data);
|
||||
item.setJavaComponent(DataComponentTypes.TOOLTIP_STYLE, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> tooltipStyle(ComponentItemWrapper item) {
|
||||
return item.getJavaComponent(ComponentTypes.TOOLTIP_STYLE);
|
||||
return item.getJavaComponent(DataComponentTypes.TOOLTIP_STYLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemModel(ComponentItemWrapper item, String data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.ITEM_MODEL);
|
||||
item.resetComponent(DataComponentTypes.ITEM_MODEL);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.ITEM_MODEL, data);
|
||||
item.setJavaComponent(DataComponentTypes.ITEM_MODEL, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemModel(ComponentItemWrapper item) {
|
||||
return item.getJavaComponent(ComponentTypes.ITEM_MODEL);
|
||||
return item.getJavaComponent(DataComponentTypes.ITEM_MODEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void equippable(ComponentItemWrapper item, EquipmentData data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.EQUIPPABLE);
|
||||
item.resetComponent(DataComponentTypes.EQUIPPABLE);
|
||||
} else {
|
||||
item.setSparrowNBTComponent(ComponentTypes.EQUIPPABLE, data.toNBT());
|
||||
item.setSparrowNBTComponent(DataComponentTypes.EQUIPPABLE, data.toNBT());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<EquipmentData> equippable(ComponentItemWrapper item) {
|
||||
Optional<Object> optionalData = item.getJavaComponent(ComponentTypes.EQUIPPABLE);
|
||||
Optional<Object> optionalData = item.getJavaComponent(DataComponentTypes.EQUIPPABLE);
|
||||
if (optionalData.isEmpty()) return Optional.empty();
|
||||
Map<String, Object> data = MiscUtils.castToMap(optionalData.get(), false);
|
||||
String slot = data.get("slot").toString();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.DataComponentTypes;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,7 +16,7 @@ public class ComponentItemFactory1_21_4 extends ComponentItemFactory1_21_2 {
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(ComponentItemWrapper item) {
|
||||
Optional<Object> optional = item.getJavaComponent(ComponentTypes.CUSTOM_MODEL_DATA);
|
||||
Optional<Object> optional = item.getJavaComponent(DataComponentTypes.CUSTOM_MODEL_DATA);
|
||||
if (optional.isEmpty()) return Optional.empty();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) optional.get();
|
||||
@@ -29,9 +29,9 @@ public class ComponentItemFactory1_21_4 extends ComponentItemFactory1_21_2 {
|
||||
@Override
|
||||
protected void customModelData(ComponentItemWrapper item, Integer data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.CUSTOM_MODEL_DATA);
|
||||
item.resetComponent(DataComponentTypes.CUSTOM_MODEL_DATA);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.CUSTOM_MODEL_DATA, Map.of("floats", List.of(data.floatValue())));
|
||||
item.setJavaComponent(DataComponentTypes.CUSTOM_MODEL_DATA, Map.of("floats", List.of(data.floatValue())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.DataComponentTypes;
|
||||
import net.momirealms.craftengine.core.attribute.AttributeModifier;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.data.JukeboxPlayable;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
@@ -30,23 +30,23 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
|
||||
@Override
|
||||
protected void customNameJson(ComponentItemWrapper item, String json) {
|
||||
if (json == null) {
|
||||
item.resetComponent(ComponentTypes.CUSTOM_NAME);
|
||||
item.resetComponent(DataComponentTypes.CUSTOM_NAME);
|
||||
} else {
|
||||
item.setSparrowNBTComponent(ComponentTypes.CUSTOM_NAME, AdventureHelper.componentToNbt(AdventureHelper.jsonToComponent(json)));
|
||||
item.setSparrowNBTComponent(DataComponentTypes.CUSTOM_NAME, AdventureHelper.componentToNbt(AdventureHelper.jsonToComponent(json)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> customNameJson(ComponentItemWrapper item) {
|
||||
return item.getJsonComponent(ComponentTypes.CUSTOM_NAME).map(it -> GsonHelper.get().toJson(it));
|
||||
return item.getJsonComponent(DataComponentTypes.CUSTOM_NAME).map(it -> GsonHelper.get().toJson(it));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customNameComponent(ComponentItemWrapper item, Component component) {
|
||||
if (component == null) {
|
||||
item.resetComponent(ComponentTypes.CUSTOM_NAME);
|
||||
item.resetComponent(DataComponentTypes.CUSTOM_NAME);
|
||||
} else {
|
||||
item.setSparrowNBTComponent(ComponentTypes.CUSTOM_NAME, AdventureHelper.componentToNbt(component));
|
||||
item.setSparrowNBTComponent(DataComponentTypes.CUSTOM_NAME, AdventureHelper.componentToNbt(component));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,30 +58,30 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
|
||||
@Override
|
||||
protected void itemNameJson(ComponentItemWrapper item, String json) {
|
||||
if (json == null) {
|
||||
item.resetComponent(ComponentTypes.ITEM_NAME);
|
||||
item.resetComponent(DataComponentTypes.ITEM_NAME);
|
||||
} else {
|
||||
item.setSparrowNBTComponent(ComponentTypes.ITEM_NAME, AdventureHelper.componentToNbt(AdventureHelper.jsonToComponent(json)));
|
||||
item.setSparrowNBTComponent(DataComponentTypes.ITEM_NAME, AdventureHelper.componentToNbt(AdventureHelper.jsonToComponent(json)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemNameComponent(ComponentItemWrapper item, Component component) {
|
||||
if (component == null) {
|
||||
item.resetComponent(ComponentTypes.ITEM_NAME);
|
||||
item.resetComponent(DataComponentTypes.ITEM_NAME);
|
||||
} else {
|
||||
item.setSparrowNBTComponent(ComponentTypes.ITEM_NAME, AdventureHelper.componentToNbt(component));
|
||||
item.setSparrowNBTComponent(DataComponentTypes.ITEM_NAME, AdventureHelper.componentToNbt(component));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemNameJson(ComponentItemWrapper item) {
|
||||
return item.getJsonComponent(ComponentTypes.ITEM_NAME).map(it -> GsonHelper.get().toJson(it));
|
||||
return item.getJsonComponent(DataComponentTypes.ITEM_NAME).map(it -> GsonHelper.get().toJson(it));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<List<String>> loreJson(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.LORE)) return Optional.empty();
|
||||
Optional<JsonElement> json = item.getJsonComponent(ComponentTypes.LORE);
|
||||
if (!item.hasComponent(DataComponentTypes.LORE)) return Optional.empty();
|
||||
Optional<JsonElement> json = item.getJsonComponent(DataComponentTypes.LORE);
|
||||
if (json.isEmpty()) return Optional.empty();
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (JsonElement jsonElement : (JsonArray) json.get()) {
|
||||
@@ -93,40 +93,40 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
|
||||
@Override
|
||||
protected void loreComponent(ComponentItemWrapper item, List<Component> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
item.resetComponent(ComponentTypes.LORE);
|
||||
item.resetComponent(DataComponentTypes.LORE);
|
||||
} else {
|
||||
List<Tag> loreTags = new ArrayList<>();
|
||||
for (Component component : lore) {
|
||||
loreTags.add(AdventureHelper.componentToTag(component));
|
||||
}
|
||||
item.setSparrowNBTComponent(ComponentTypes.LORE, new ListTag(loreTags));
|
||||
item.setSparrowNBTComponent(DataComponentTypes.LORE, new ListTag(loreTags));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loreJson(ComponentItemWrapper item, List<String> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
item.resetComponent(ComponentTypes.LORE);
|
||||
item.resetComponent(DataComponentTypes.LORE);
|
||||
} else {
|
||||
List<Tag> loreTags = new ArrayList<>();
|
||||
for (String json : lore) {
|
||||
loreTags.add(AdventureHelper.componentToTag(AdventureHelper.jsonToComponent(json)));
|
||||
}
|
||||
item.setSparrowNBTComponent(ComponentTypes.LORE, new ListTag(loreTags));
|
||||
item.setSparrowNBTComponent(DataComponentTypes.LORE, new ListTag(loreTags));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<JukeboxPlayable> jukeboxSong(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.JUKEBOX_PLAYABLE)) return Optional.empty();
|
||||
String song = (String) item.getJavaComponent(ComponentTypes.JUKEBOX_PLAYABLE).orElse(null);
|
||||
if (!item.hasComponent(DataComponentTypes.JUKEBOX_PLAYABLE)) return Optional.empty();
|
||||
String song = (String) item.getJavaComponent(DataComponentTypes.JUKEBOX_PLAYABLE).orElse(null);
|
||||
if (song == null) return Optional.empty();
|
||||
return Optional.of(new JukeboxPlayable(song, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void jukeboxSong(ComponentItemWrapper item, JukeboxPlayable data) {
|
||||
item.setJavaComponent(ComponentTypes.JUKEBOX_PLAYABLE, data.song());
|
||||
item.setJavaComponent(DataComponentTypes.JUKEBOX_PLAYABLE, data.song());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,6 +151,6 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
|
||||
}
|
||||
modifiers.add(modifierTag);
|
||||
}
|
||||
item.setSparrowNBTComponent(ComponentKeys.ATTRIBUTE_MODIFIERS, modifiers);
|
||||
item.setSparrowNBTComponent(DataComponentKeys.ATTRIBUTE_MODIFIERS, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.destroystokyo.paper.event.inventory.PrepareResultEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.DataComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.bukkit.CraftBukkitReflections;
|
||||
@@ -329,11 +329,11 @@ public class RecipeEventListener implements Listener {
|
||||
|
||||
Item<ItemStack> wrappedResult = BukkitItemManager.instance().wrap(event.getResult());
|
||||
if (!firstCustomItem.settings().canEnchant()) {
|
||||
Object previousEnchantment = wrappedFirst.getExactComponent(ComponentTypes.ENCHANTMENTS);
|
||||
Object previousEnchantment = wrappedFirst.getExactComponent(DataComponentTypes.ENCHANTMENTS);
|
||||
if (previousEnchantment != null) {
|
||||
wrappedResult.setExactComponent(ComponentTypes.ENCHANTMENTS, previousEnchantment);
|
||||
wrappedResult.setExactComponent(DataComponentTypes.ENCHANTMENTS, previousEnchantment);
|
||||
} else {
|
||||
wrappedResult.resetComponent(ComponentTypes.ENCHANTMENTS);
|
||||
wrappedResult.resetComponent(DataComponentTypes.ENCHANTMENTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -440,7 +440,7 @@ public class RecipeEventListener implements Listener {
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.logger().warn("Failed to get hover name", e);
|
||||
}
|
||||
} else if (VersionHelper.isOrAbove1_20_5() && wrappedFirst.hasComponent(ComponentTypes.CUSTOM_NAME)) {
|
||||
} else if (VersionHelper.isOrAbove1_20_5() && wrappedFirst.hasComponent(DataComponentTypes.CUSTOM_NAME)) {
|
||||
repairCost += 1;
|
||||
wrappedFirst.customNameJson(null);
|
||||
} else if (!VersionHelper.isOrAbove1_20_5() && wrappedFirst.hasTag("display", "Name")) {
|
||||
|
||||
@@ -87,7 +87,7 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
super.sharedClassPathAppender = sharedClassPathAppender;
|
||||
super.privateClassPathAppender = privateClassPathAppender;
|
||||
super.logger = logger;
|
||||
super.platform = new BukkitPlatform();
|
||||
super.platform = new BukkitPlatform(this);
|
||||
super.scheduler = new BukkitSchedulerAdapter(this);
|
||||
Class<?> compatibilityClass = ReflectionUtils.getClazz(COMPATIBILITY_CLASS);
|
||||
if (compatibilityClass != null) {
|
||||
|
||||
@@ -2,11 +2,18 @@ package net.momirealms.craftengine.bukkit.plugin;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.bukkit.CraftBukkitReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
|
||||
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LegacyInventoryUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.ParticleUtils;
|
||||
import net.momirealms.craftengine.bukkit.world.particle.BukkitParticleType;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.trade.MerchantOffer;
|
||||
import net.momirealms.craftengine.core.plugin.Platform;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -16,10 +23,19 @@ import net.momirealms.sparrow.nbt.CompoundTag;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Merchant;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BukkitPlatform implements Platform {
|
||||
private final BukkitCraftEngine plugin;
|
||||
|
||||
public BukkitPlatform(BukkitCraftEngine plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCommand(String command) {
|
||||
@@ -76,4 +92,26 @@ public class BukkitPlatform implements Platform {
|
||||
}
|
||||
return new BukkitParticleType(particle, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <I> void openMerchant(Player player, Component title, List<MerchantOffer<I>> offers) {
|
||||
Merchant merchant = Bukkit.createMerchant();
|
||||
List<MerchantRecipe> recipes = merchant.getRecipes();
|
||||
for (MerchantOffer<I> offer : offers) {
|
||||
MerchantRecipe merchantRecipe = new MerchantRecipe((ItemStack) offer.result().getItem(), 0, Integer.MAX_VALUE, offer.xp() > 0, offer.xp(), 0);
|
||||
merchantRecipe.addIngredient((ItemStack) offer.cost1().getItem());
|
||||
offer.cost2().ifPresent(it -> merchantRecipe.addIngredient((ItemStack) it.getItem()));
|
||||
recipes.add(merchantRecipe);
|
||||
}
|
||||
merchant.setRecipes(recipes);
|
||||
if (title != null) {
|
||||
try {
|
||||
Object minecraftMerchant = CraftBukkitReflections.method$CraftMerchant$getMerchant.invoke(merchant);
|
||||
CraftBukkitReflections.field$MinecraftMerchant$title.set(minecraftMerchant, ComponentUtils.adventureToMinecraft(title));
|
||||
} catch (ReflectiveOperationException e) {
|
||||
this.plugin.logger().warn("Failed to update merchant title", e);
|
||||
}
|
||||
}
|
||||
LegacyInventoryUtils.openMerchant((org.bukkit.entity.Player) player.platformPlayer(), merchant);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.momirealms.craftengine.bukkit.plugin.command.feature;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.DataComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
@@ -95,7 +95,7 @@ public class TotemAnimationCommand extends BukkitCommandFeature<CommandSender> {
|
||||
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(player);
|
||||
Item<ItemStack> item = customItem.buildItem(serverPlayer);
|
||||
if (VersionHelper.isOrAbove1_21_2()) {
|
||||
item.setJavaComponent(ComponentTypes.DEATH_PROTECTION, Map.of());
|
||||
item.setJavaComponent(DataComponentTypes.DEATH_PROTECTION, Map.of());
|
||||
}
|
||||
PlayerUtils.sendTotemAnimation(serverPlayer, item, soundData, removeSound);
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
public class BukkitGuiManager implements GuiManager, Listener {
|
||||
// private static final boolean useNewOpenInventory = ReflectionUtils.getDeclaredMethod(InventoryView.class, void.class, new String[]{"open"}) != null;
|
||||
private static BukkitGuiManager instance;
|
||||
private final BukkitCraftEngine plugin;
|
||||
|
||||
@@ -43,31 +43,18 @@ public class BukkitGuiManager implements GuiManager, Listener {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
// @SuppressWarnings("UnstableApiUsage")
|
||||
@Override
|
||||
public void openInventory(net.momirealms.craftengine.core.entity.player.Player player, GuiType guiType) {
|
||||
Player bukkitPlayer = (Player) player.platformPlayer();
|
||||
// if (useNewOpenInventory) {
|
||||
// switch (guiType) {
|
||||
// case ANVIL -> MenuType.ANVIL.create(bukkitPlayer).open();
|
||||
// case LOOM -> MenuType.LOOM.create(bukkitPlayer).open();
|
||||
// case ENCHANTMENT -> MenuType.ENCHANTMENT.create(bukkitPlayer).open();
|
||||
// case CRAFTING -> MenuType.CRAFTING.create(bukkitPlayer).open();
|
||||
// case CARTOGRAPHY -> MenuType.CARTOGRAPHY_TABLE.create(bukkitPlayer).open();
|
||||
// case SMITHING -> MenuType.SMITHING.create(bukkitPlayer).open();
|
||||
// case GRINDSTONE -> MenuType.GRINDSTONE.create(bukkitPlayer).open();
|
||||
// }
|
||||
// } else {
|
||||
switch (guiType) {
|
||||
case ANVIL -> LegacyInventoryUtils.openAnvil(bukkitPlayer);
|
||||
case LOOM -> LegacyInventoryUtils.openLoom(bukkitPlayer);
|
||||
case GRINDSTONE -> LegacyInventoryUtils.openGrindstone(bukkitPlayer);
|
||||
case SMITHING -> LegacyInventoryUtils.openSmithingTable(bukkitPlayer);
|
||||
case CRAFTING -> LegacyInventoryUtils.openWorkbench(bukkitPlayer);
|
||||
case ENCHANTMENT -> LegacyInventoryUtils.openEnchanting(bukkitPlayer);
|
||||
case CARTOGRAPHY -> LegacyInventoryUtils.openCartographyTable(bukkitPlayer);
|
||||
}
|
||||
// }
|
||||
switch (guiType) {
|
||||
case ANVIL -> LegacyInventoryUtils.openAnvil(bukkitPlayer);
|
||||
case LOOM -> LegacyInventoryUtils.openLoom(bukkitPlayer);
|
||||
case GRINDSTONE -> LegacyInventoryUtils.openGrindstone(bukkitPlayer);
|
||||
case SMITHING -> LegacyInventoryUtils.openSmithingTable(bukkitPlayer);
|
||||
case CRAFTING -> LegacyInventoryUtils.openWorkbench(bukkitPlayer);
|
||||
case ENCHANTMENT -> LegacyInventoryUtils.openEnchanting(bukkitPlayer);
|
||||
case CARTOGRAPHY -> LegacyInventoryUtils.openCartographyTable(bukkitPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.DataComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.util.ItemTags;
|
||||
@@ -245,7 +245,7 @@ public final class RecipeInjector {
|
||||
|
||||
private static boolean isDamageableItem(Item<ItemStack> item) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
return item.hasComponent(ComponentTypes.MAX_DAMAGE) && item.hasComponent(ComponentTypes.DAMAGE);
|
||||
return item.hasComponent(DataComponentTypes.MAX_DAMAGE) && item.hasComponent(DataComponentTypes.DAMAGE);
|
||||
} else {
|
||||
return FastNMS.INSTANCE.method$Item$canBeDepleted(FastNMS.INSTANCE.method$ItemStack$getItem(item.getLiteralObject()));
|
||||
}
|
||||
|
||||
@@ -372,4 +372,24 @@ public final class CraftBukkitReflections {
|
||||
public static final Class<?> clazz$MinecraftInventory = requireNonNull(
|
||||
ReflectionUtils.getClazz(BukkitReflectionUtils.assembleCBClass("inventory.CraftInventoryCustom$MinecraftInventory"))
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$CraftMerchant = requireNonNull(
|
||||
ReflectionUtils.getClazz(BukkitReflectionUtils.assembleCBClass("inventory.CraftMerchant"))
|
||||
);
|
||||
|
||||
public static final Method method$CraftMerchant$getMerchant = requireNonNull(
|
||||
ReflectionUtils.getMethod(clazz$CraftMerchant, CoreReflections.clazz$Merchant)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$CraftMerchantCustom = requireNonNull(
|
||||
ReflectionUtils.getClazz(BukkitReflectionUtils.assembleCBClass("inventory.CraftMerchantCustom"))
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$CraftMerchantCustom$MinecraftMerchant = requireNonNull(
|
||||
ReflectionUtils.getClazz(BukkitReflectionUtils.assembleCBClass("inventory.CraftMerchantCustom$MinecraftMerchant"))
|
||||
);
|
||||
|
||||
public static final Field field$MinecraftMerchant$title = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(clazz$CraftMerchantCustom$MinecraftMerchant, CoreReflections.clazz$Component, 0)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -629,6 +629,17 @@ public final class CoreReflections {
|
||||
BukkitReflectionUtils.assembleMCClass("core.component.DataComponentType")
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$TypedDataComponent = ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("core.component.TypedDataComponent")
|
||||
);
|
||||
|
||||
// 1.21.5+
|
||||
public static final Class<?> clazz$DataComponentPredicate$Type = MiscUtils.requireNonNullIf(ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("core.component.predicates.DataComponentPredicate$Type")
|
||||
), VersionHelper.isOrAbove1_21_5());
|
||||
|
||||
|
||||
|
||||
public static final Method method$Registry$getId = requireNonNull(
|
||||
ReflectionUtils.getMethod(clazz$Registry, int.class, Object.class)
|
||||
);
|
||||
@@ -4470,4 +4481,14 @@ public final class CoreReflections {
|
||||
"world.item.trading.ItemCost"
|
||||
), VersionHelper.isOrAbove1_20_5()
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$MerchantOffer = requireNonNull(BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||
"world.item.trading.MerchantRecipe",
|
||||
"world.item.trading.MerchantOffer"
|
||||
));
|
||||
|
||||
public static final Class<?> clazz$Merchant = requireNonNull(BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||
"world.item.trading.IMerchant",
|
||||
"world.item.trading.Merchant"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.ReflectionInitException;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
@@ -21,6 +22,7 @@ public final class MBuiltInRegistries {
|
||||
public static final Object RECIPE_TYPE;
|
||||
public static final Object PARTICLE_TYPE;
|
||||
public static final Object DATA_COMPONENT_TYPE;
|
||||
public static final Object DATA_COMPONENT_PREDICATE_TYPE;
|
||||
public static final Object LOOT_POOL_ENTRY_TYPE;
|
||||
public static final Object GAME_EVENT;
|
||||
|
||||
@@ -37,6 +39,7 @@ public final class MBuiltInRegistries {
|
||||
Object registries$Fluid = null;
|
||||
Object registries$RecipeType = null;
|
||||
Object registries$DataComponentType = null;
|
||||
Object registries$DataComponentPredicateType = null;
|
||||
Object registries$LootPoolEntryType = null;
|
||||
Object registries$GameEvent = null;
|
||||
for (Field field : fields) {
|
||||
@@ -51,8 +54,10 @@ public final class MBuiltInRegistries {
|
||||
registries$EntityType = field.get(null);
|
||||
} else if (rawType == CoreReflections.clazz$RecipeType) {
|
||||
registries$RecipeType = field.get(null);
|
||||
} else if (rawType == CoreReflections.clazz$DataComponentType && registries$DataComponentType == null) {
|
||||
} else if (VersionHelper.isOrAbove1_20_5() && rawType == CoreReflections.clazz$DataComponentType && registries$DataComponentType == null) {
|
||||
registries$DataComponentType = field.get(null);
|
||||
} else if (VersionHelper.isOrAbove1_21_5() && rawType == CoreReflections.clazz$DataComponentPredicate$Type) {
|
||||
registries$DataComponentPredicateType = field.get(null);
|
||||
}
|
||||
} else {
|
||||
if (type == CoreReflections.clazz$Block) {
|
||||
@@ -87,6 +92,7 @@ public final class MBuiltInRegistries {
|
||||
LOOT_POOL_ENTRY_TYPE = requireNonNull(registries$LootPoolEntryType);
|
||||
DATA_COMPONENT_TYPE = registries$DataComponentType;
|
||||
GAME_EVENT = requireNonNull(registries$GameEvent);
|
||||
DATA_COMPONENT_PREDICATE_TYPE = registries$DataComponentPredicateType;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new ReflectionInitException("Failed to init BuiltInRegistries", e);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.item.DataComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
@@ -64,7 +64,7 @@ public final class PlayerUtils {
|
||||
Item<?> previousMainHandItem = player.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
boolean isMainHandTotem;
|
||||
if (VersionHelper.isOrAbove1_21_2()) {
|
||||
isMainHandTotem = previousMainHandItem.hasComponent(ComponentTypes.DEATH_PROTECTION);
|
||||
isMainHandTotem = previousMainHandItem.hasComponent(DataComponentTypes.DEATH_PROTECTION);
|
||||
} else {
|
||||
isMainHandTotem = previousMainHandItem.id().equals(ItemKeys.TOTEM_OF_UNDYING);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item;
|
||||
|
||||
public final class ComponentIds {
|
||||
private ComponentIds() {}
|
||||
public final class DataComponentIds {
|
||||
private DataComponentIds() {}
|
||||
|
||||
public static final String ITEM_NAME = "minecraft:item_name";
|
||||
public static final String CUSTOM_NAME = "minecraft:custom_name";
|
||||
@@ -2,8 +2,8 @@ package net.momirealms.craftengine.core.item;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public final class ComponentKeys {
|
||||
private ComponentKeys() {}
|
||||
public final class DataComponentKeys {
|
||||
private DataComponentKeys() {}
|
||||
|
||||
public static final Key ATTRIBUTE_MODIFIERS = Key.of("minecraft", "attribute_modifiers");
|
||||
public static final Key BANNER_PATTERN = Key.of("minecraft", "banner_patterns");
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.momirealms.craftengine.core.item;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public final class DataComponentPredicateKeys {
|
||||
private DataComponentPredicateKeys() {}
|
||||
|
||||
public static final Key DAMAGE = Key.of("minecraft", "damage");
|
||||
public static final Key ENCHANTMENTS = Key.of("minecraft", "enchantments");
|
||||
public static final Key STORED_ENCHANTMENTS = Key.of("minecraft", "stored_enchantments");
|
||||
public static final Key POTIONS = Key.of("minecraft", "potion_contents");
|
||||
public static final Key CUSTOM_DATA = Key.of("minecraft", "custom_data");
|
||||
public static final Key CONTAINER = Key.of("minecraft", "container");
|
||||
public static final Key BUNDLE_CONTENTS = Key.of("minecraft", "bundle_contents");
|
||||
public static final Key FIREWORK_EXPLOSION = Key.of("minecraft", "firework_explosion");
|
||||
public static final Key FIREWORKS = Key.of("minecraft", "fireworks");
|
||||
public static final Key WRITABLE_BOOK = Key.of("minecraft", "writable_book_content");
|
||||
public static final Key WRITTEN_BOOK = Key.of("minecraft", "written_book_content");
|
||||
public static final Key ATTRIBUTE_MODIFIERS = Key.of("minecraft", "attribute_modifiers");
|
||||
public static final Key ARMOR_TRIM = Key.of("minecraft", "trim");
|
||||
public static final Key JUKEBOX_PLAYABLE = Key.of("minecraft", "jukebox_playable");
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.equipment;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.modifier.HideTooltipModifier;
|
||||
import net.momirealms.craftengine.core.item.modifier.ItemDataModifier;
|
||||
import net.momirealms.craftengine.core.item.modifier.TrimModifier;
|
||||
@@ -42,7 +42,7 @@ public class TrimBasedEquipment extends AbstractEquipment {
|
||||
public <I> List<ItemDataModifier<I>> modifiers() {
|
||||
return List.of(
|
||||
new TrimModifier<>(Key.of(AbstractPackManager.NEW_TRIM_MATERIAL), this.assetId),
|
||||
new HideTooltipModifier<>(List.of(ComponentKeys.TRIM))
|
||||
new HideTooltipModifier<>(List.of(DataComponentKeys.TRIM))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -37,13 +37,13 @@ public class ArgumentsModifier<I> implements ItemDataModifier<I> {
|
||||
@Override
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
CompoundTag customData = (CompoundTag) Optional.ofNullable(item.getSparrowNBTComponent(ComponentKeys.CUSTOM_DATA)).orElseGet(CompoundTag::new);
|
||||
CompoundTag customData = (CompoundTag) Optional.ofNullable(item.getSparrowNBTComponent(DataComponentKeys.CUSTOM_DATA)).orElseGet(CompoundTag::new);
|
||||
CompoundTag argumentTag = new CompoundTag();
|
||||
for (Map.Entry<String, TextProvider> entry : this.arguments.entrySet()) {
|
||||
argumentTag.put(entry.getKey(), new StringTag(entry.getValue().get(context)));
|
||||
}
|
||||
customData.put(ARGUMENTS_TAG, argumentTag);
|
||||
item.setNBTComponent(ComponentKeys.CUSTOM_DATA, customData);
|
||||
item.setNBTComponent(DataComponentKeys.CUSTOM_DATA, customData);
|
||||
} else {
|
||||
Map<String, String> processed = new HashMap<>();
|
||||
for (Map.Entry<String, TextProvider> entry : this.arguments.entrySet()) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.momirealms.craftengine.core.item.modifier;
|
||||
import net.momirealms.craftengine.core.attribute.AttributeModifier;
|
||||
import net.momirealms.craftengine.core.attribute.Attributes;
|
||||
import net.momirealms.craftengine.core.attribute.Attributes1_21;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -115,7 +115,7 @@ public class AttributeModifiersModifier<I> implements SimpleNetworkItemDataModif
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.ATTRIBUTE_MODIFIERS;
|
||||
return DataComponentKeys.ATTRIBUTE_MODIFIERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.block.BlockStateWrapper;
|
||||
import net.momirealms.craftengine.core.block.CustomBlockStateWrapper;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -47,7 +47,7 @@ public class BlockStateModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.BLOCK_STATE;
|
||||
return DataComponentKeys.BLOCK_STATE;
|
||||
}
|
||||
|
||||
public static class Factory<I> implements ItemDataModifierFactory<I> {
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ComponentsModifier<I> implements ItemDataModifier<I> {
|
||||
List<Pair<Key, Tag>> pairs = new ArrayList<>(arguments.size());
|
||||
for (Map.Entry<String, Object> entry : arguments.entrySet()) {
|
||||
Key key = Key.of(entry.getKey());
|
||||
if (key.equals(ComponentKeys.CUSTOM_DATA)) {
|
||||
if (key.equals(DataComponentKeys.CUSTOM_DATA)) {
|
||||
this.customData = (CompoundTag) parseValue(entry.getValue());
|
||||
} else {
|
||||
pairs.add(new Pair<>(key, parseValue(entry.getValue())));
|
||||
@@ -58,14 +58,14 @@ public class ComponentsModifier<I> implements ItemDataModifier<I> {
|
||||
item.setNBTComponent(entry.left(), entry.right());
|
||||
}
|
||||
if (this.customData != null) {
|
||||
CompoundTag tag = (CompoundTag) item.getTag(ComponentKeys.CUSTOM_DATA);
|
||||
CompoundTag tag = (CompoundTag) item.getTag(DataComponentKeys.CUSTOM_DATA);
|
||||
if (tag != null) {
|
||||
for (Map.Entry<String, Tag> entry : this.customData.entrySet()) {
|
||||
tag.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
item.setComponent(ComponentKeys.CUSTOM_DATA, tag);
|
||||
item.setComponent(DataComponentKeys.CUSTOM_DATA, tag);
|
||||
} else {
|
||||
item.setComponent(ComponentKeys.CUSTOM_DATA, this.customData);
|
||||
item.setComponent(DataComponentKeys.CUSTOM_DATA, this.customData);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -33,7 +33,7 @@ public class CustomModelDataModifier<I> implements SimpleNetworkItemDataModifier
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.CUSTOM_MODEL_DATA;
|
||||
return DataComponentKeys.CUSTOM_MODEL_DATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -45,7 +45,7 @@ public class CustomNameModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.CUSTOM_NAME;
|
||||
return DataComponentKeys.CUSTOM_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -35,7 +35,7 @@ public class DyedColorModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.DYED_COLOR;
|
||||
return DataComponentKeys.DYED_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ public class EnchantmentsModifier<I> implements SimpleNetworkItemDataModifier<I>
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return item.vanillaId().equals(ItemKeys.ENCHANTED_BOOK) ? ComponentKeys.STORED_ENCHANTMENTS : ComponentKeys.ENCHANTMENTS;
|
||||
return item.vanillaId().equals(ItemKeys.ENCHANTED_BOOK) ? DataComponentKeys.STORED_ENCHANTMENTS : DataComponentKeys.ENCHANTMENTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.setting.EquipmentData;
|
||||
@@ -42,6 +42,6 @@ public class EquippableAssetIdModifier<I> implements SimpleNetworkItemDataModifi
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.EQUIPPABLE;
|
||||
return DataComponentKeys.EQUIPPABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -35,7 +35,7 @@ public class EquippableModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.EQUIPPABLE;
|
||||
return DataComponentKeys.EQUIPPABLE;
|
||||
}
|
||||
|
||||
public static class Factory<I> implements ItemDataModifierFactory<I> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -41,7 +41,7 @@ public class FoodModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.setJavaComponent(ComponentKeys.FOOD, Map.of(
|
||||
item.setJavaComponent(DataComponentKeys.FOOD, Map.of(
|
||||
"nutrition", this.nutrition,
|
||||
"saturation", this.saturation,
|
||||
"can_always_eat", this.canAlwaysEat
|
||||
@@ -51,7 +51,7 @@ public class FoodModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.FOOD;
|
||||
return DataComponentKeys.FOOD;
|
||||
}
|
||||
|
||||
public static class Factory<I> implements ItemDataModifierFactory<I> {
|
||||
|
||||
@@ -19,34 +19,34 @@ public class HideTooltipModifier<I> implements ItemDataModifier<I> {
|
||||
public static final Factory<?> FACTORY = new Factory<>();
|
||||
public static final Map<Key, Integer> TO_LEGACY;
|
||||
public static final List<Key> COMPONENTS = List.of(
|
||||
ComponentKeys.UNBREAKABLE,
|
||||
ComponentKeys.ENCHANTMENTS,
|
||||
ComponentKeys.STORED_ENCHANTMENTS,
|
||||
ComponentKeys.CAN_PLACE_ON,
|
||||
ComponentKeys.CAN_BREAK,
|
||||
ComponentKeys.ATTRIBUTE_MODIFIERS,
|
||||
ComponentKeys.DYED_COLOR,
|
||||
ComponentKeys.TRIM,
|
||||
ComponentKeys.JUKEBOX_PLAYABLE
|
||||
DataComponentKeys.UNBREAKABLE,
|
||||
DataComponentKeys.ENCHANTMENTS,
|
||||
DataComponentKeys.STORED_ENCHANTMENTS,
|
||||
DataComponentKeys.CAN_PLACE_ON,
|
||||
DataComponentKeys.CAN_BREAK,
|
||||
DataComponentKeys.ATTRIBUTE_MODIFIERS,
|
||||
DataComponentKeys.DYED_COLOR,
|
||||
DataComponentKeys.TRIM,
|
||||
DataComponentKeys.JUKEBOX_PLAYABLE
|
||||
);
|
||||
static {
|
||||
ImmutableMap.Builder<Key, Integer> builder = ImmutableMap.builder();
|
||||
builder.put(ComponentKeys.ENCHANTMENTS, 1);
|
||||
builder.put(ComponentKeys.ATTRIBUTE_MODIFIERS, 2);
|
||||
builder.put(ComponentKeys.UNBREAKABLE, 4);
|
||||
builder.put(ComponentKeys.CAN_BREAK, 8);
|
||||
builder.put(ComponentKeys.CAN_PLACE_ON, 16);
|
||||
builder.put(ComponentKeys.STORED_ENCHANTMENTS, 32);
|
||||
builder.put(ComponentKeys.POTION_CONTENTS, 32);
|
||||
builder.put(ComponentKeys.WRITTEN_BOOK_CONTENT, 32);
|
||||
builder.put(ComponentKeys.FIREWORKS, 32);
|
||||
builder.put(ComponentKeys.FIREWORK_EXPLOSION, 32);
|
||||
builder.put(ComponentKeys.BUNDLE_CONTENTS, 32);
|
||||
builder.put(ComponentKeys.MAP_ID, 32);
|
||||
builder.put(ComponentKeys.MAP_COLOR, 32);
|
||||
builder.put(ComponentKeys.MAP_DECORATIONS, 32);
|
||||
builder.put(ComponentKeys.DYED_COLOR, 64);
|
||||
builder.put(ComponentKeys.TRIM, 128);
|
||||
builder.put(DataComponentKeys.ENCHANTMENTS, 1);
|
||||
builder.put(DataComponentKeys.ATTRIBUTE_MODIFIERS, 2);
|
||||
builder.put(DataComponentKeys.UNBREAKABLE, 4);
|
||||
builder.put(DataComponentKeys.CAN_BREAK, 8);
|
||||
builder.put(DataComponentKeys.CAN_PLACE_ON, 16);
|
||||
builder.put(DataComponentKeys.STORED_ENCHANTMENTS, 32);
|
||||
builder.put(DataComponentKeys.POTION_CONTENTS, 32);
|
||||
builder.put(DataComponentKeys.WRITTEN_BOOK_CONTENT, 32);
|
||||
builder.put(DataComponentKeys.FIREWORKS, 32);
|
||||
builder.put(DataComponentKeys.FIREWORK_EXPLOSION, 32);
|
||||
builder.put(DataComponentKeys.BUNDLE_CONTENTS, 32);
|
||||
builder.put(DataComponentKeys.MAP_ID, 32);
|
||||
builder.put(DataComponentKeys.MAP_COLOR, 32);
|
||||
builder.put(DataComponentKeys.MAP_DECORATIONS, 32);
|
||||
builder.put(DataComponentKeys.DYED_COLOR, 64);
|
||||
builder.put(DataComponentKeys.TRIM, 128);
|
||||
TO_LEGACY = builder.build();
|
||||
}
|
||||
|
||||
@@ -98,11 +98,11 @@ public class HideTooltipModifier<I> implements ItemDataModifier<I> {
|
||||
@Override
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_21_5()) {
|
||||
Tag previous = item.getSparrowNBTComponent(ComponentKeys.TOOLTIP_DISPLAY);
|
||||
Tag previous = item.getSparrowNBTComponent(DataComponentKeys.TOOLTIP_DISPLAY);
|
||||
if (previous != null) {
|
||||
networkData.put(ComponentKeys.TOOLTIP_DISPLAY.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous));
|
||||
networkData.put(DataComponentKeys.TOOLTIP_DISPLAY.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous));
|
||||
} else {
|
||||
networkData.put(ComponentKeys.TOOLTIP_DISPLAY.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
networkData.put(DataComponentKeys.TOOLTIP_DISPLAY.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
} else if (VersionHelper.isOrAbove1_20_5()) {
|
||||
for (Key component : this.components) {
|
||||
@@ -210,9 +210,9 @@ public class HideTooltipModifier<I> implements ItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<W> item) {
|
||||
Map<String, Object> data = MiscUtils.castToMap(item.getJavaComponent(ComponentKeys.TOOLTIP_DISPLAY), true);
|
||||
Map<String, Object> data = MiscUtils.castToMap(item.getJavaComponent(DataComponentKeys.TOOLTIP_DISPLAY), true);
|
||||
if (data == null) {
|
||||
item.setJavaComponent(ComponentKeys.TOOLTIP_DISPLAY, Map.of("hidden_components", this.components));
|
||||
item.setJavaComponent(DataComponentKeys.TOOLTIP_DISPLAY, Map.of("hidden_components", this.components));
|
||||
} else {
|
||||
if (data.get("hidden_components") instanceof List<?> list) {
|
||||
List<String> hiddenComponents = list.stream().map(Object::toString).toList();
|
||||
@@ -222,11 +222,11 @@ public class HideTooltipModifier<I> implements ItemDataModifier<I> {
|
||||
).distinct().toList();
|
||||
Map<String, Object> newData = new HashMap<>(data);
|
||||
newData.put("hidden_components", mergedComponents);
|
||||
item.setJavaComponent(ComponentKeys.TOOLTIP_DISPLAY, newData);
|
||||
item.setJavaComponent(DataComponentKeys.TOOLTIP_DISPLAY, newData);
|
||||
} else {
|
||||
Map<String, Object> newData = new HashMap<>(data);
|
||||
newData.put("hidden_components", this.components);
|
||||
item.setJavaComponent(ComponentKeys.TOOLTIP_DISPLAY, newData);
|
||||
item.setJavaComponent(DataComponentKeys.TOOLTIP_DISPLAY, newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -31,7 +31,7 @@ public class ItemModelModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.ITEM_MODEL;
|
||||
return DataComponentKeys.ITEM_MODEL;
|
||||
}
|
||||
|
||||
public static class Factory<I> implements ItemDataModifierFactory<I> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -36,7 +36,7 @@ public class ItemNameModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.ITEM_NAME;
|
||||
return DataComponentKeys.ITEM_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -29,9 +29,9 @@ public class ItemVersionModifier<I> implements ItemDataModifier<I> {
|
||||
@Override
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
CompoundTag customData = (CompoundTag) Optional.ofNullable(item.getSparrowNBTComponent(ComponentKeys.CUSTOM_DATA)).orElseGet(CompoundTag::new);
|
||||
CompoundTag customData = (CompoundTag) Optional.ofNullable(item.getSparrowNBTComponent(DataComponentKeys.CUSTOM_DATA)).orElseGet(CompoundTag::new);
|
||||
customData.putInt(VERSION_TAG, this.version);
|
||||
item.setNBTComponent(ComponentKeys.CUSTOM_DATA, customData);
|
||||
item.setNBTComponent(DataComponentKeys.CUSTOM_DATA, customData);
|
||||
} else {
|
||||
item.setTag(this.version, VERSION_TAG);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -30,7 +30,7 @@ public class MaxDamageModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.MAX_DAMAGE;
|
||||
return DataComponentKeys.MAX_DAMAGE;
|
||||
}
|
||||
|
||||
public static class Factory<I> implements ItemDataModifierFactory<I> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -19,7 +19,7 @@ public class OverwritableItemNameModifier<I> implements SimpleNetworkItemDataMod
|
||||
@Override
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
if (VersionHelper.COMPONENT_RELEASE) {
|
||||
if (item.hasNonDefaultComponent(ComponentKeys.ITEM_NAME)) {
|
||||
if (item.hasNonDefaultComponent(DataComponentKeys.ITEM_NAME)) {
|
||||
return item;
|
||||
}
|
||||
} else {
|
||||
@@ -37,7 +37,7 @@ public class OverwritableItemNameModifier<I> implements SimpleNetworkItemDataMod
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.ITEM_NAME;
|
||||
return DataComponentKeys.ITEM_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -30,9 +30,9 @@ public class PDCModifier<I> implements ItemDataModifier<I> {
|
||||
@Override
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
CompoundTag customData = (CompoundTag) Optional.ofNullable(item.getSparrowNBTComponent(ComponentKeys.CUSTOM_DATA)).orElseGet(CompoundTag::new);
|
||||
CompoundTag customData = (CompoundTag) Optional.ofNullable(item.getSparrowNBTComponent(DataComponentKeys.CUSTOM_DATA)).orElseGet(CompoundTag::new);
|
||||
customData.put(BUKKIT_PDC, this.data);
|
||||
item.setNBTComponent(ComponentKeys.CUSTOM_DATA, customData);
|
||||
item.setNBTComponent(DataComponentKeys.CUSTOM_DATA, customData);
|
||||
} else {
|
||||
item.setTag(this.data, BUKKIT_PDC);
|
||||
}
|
||||
|
||||
@@ -39,11 +39,11 @@ public class TagsModifier<I> implements ItemDataModifier<I> {
|
||||
@Override
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
Tag previous = item.getSparrowNBTComponent(ComponentKeys.CUSTOM_DATA);
|
||||
Tag previous = item.getSparrowNBTComponent(DataComponentKeys.CUSTOM_DATA);
|
||||
if (previous != null) {
|
||||
networkData.put(ComponentKeys.CUSTOM_DATA.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous));
|
||||
networkData.put(DataComponentKeys.CUSTOM_DATA.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous));
|
||||
} else {
|
||||
networkData.put(ComponentKeys.CUSTOM_DATA.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
networkData.put(DataComponentKeys.CUSTOM_DATA.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE));
|
||||
}
|
||||
} else {
|
||||
for (Map.Entry<String, Object> entry : this.arguments.entrySet()) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -32,7 +32,7 @@ public class TooltipStyleModifier<I> implements SimpleNetworkItemDataModifier<I>
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.TOOLTIP_STYLE;
|
||||
return DataComponentKeys.TOOLTIP_STYLE;
|
||||
}
|
||||
|
||||
public static class Factory<I> implements ItemDataModifierFactory<I> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -43,7 +43,7 @@ public class TrimModifier<I> implements SimpleNetworkItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.TRIM;
|
||||
return DataComponentKeys.TRIM;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -34,7 +34,7 @@ public class UnbreakableModifier<I> implements SimpleNetworkItemDataModifier<I>
|
||||
|
||||
@Override
|
||||
public @Nullable Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.UNBREAKABLE;
|
||||
return DataComponentKeys.UNBREAKABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier.lore;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -45,7 +45,7 @@ public final class DynamicLoreModifier<I> implements SimpleNetworkItemDataModifi
|
||||
|
||||
@Override
|
||||
public Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.LORE;
|
||||
return DataComponentKeys.LORE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item.modifier.lore;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -30,7 +30,7 @@ public sealed interface LoreModifier<I> extends SimpleNetworkItemDataModifier<I>
|
||||
@Override
|
||||
@Nullable
|
||||
default Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.LORE;
|
||||
return DataComponentKeys.LORE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.modifier.lore;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.DataComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
@@ -27,7 +27,7 @@ public final class OverwritableLoreModifier<I> implements SimpleNetworkItemDataM
|
||||
@Override
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
if (VersionHelper.COMPONENT_RELEASE) {
|
||||
if (item.hasNonDefaultComponent(ComponentKeys.LORE)) {
|
||||
if (item.hasNonDefaultComponent(DataComponentKeys.LORE)) {
|
||||
return item;
|
||||
}
|
||||
} else {
|
||||
@@ -40,7 +40,7 @@ public final class OverwritableLoreModifier<I> implements SimpleNetworkItemDataM
|
||||
|
||||
@Override
|
||||
public Key componentType(Item<I> item, ItemBuildContext context) {
|
||||
return ComponentKeys.LORE;
|
||||
return DataComponentKeys.LORE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,7 +64,7 @@ public final class OverwritableLoreModifier<I> implements SimpleNetworkItemDataM
|
||||
@Override
|
||||
public Item<I> prepareNetworkItem(Item<I> item, ItemBuildContext context, CompoundTag networkData) {
|
||||
if (VersionHelper.COMPONENT_RELEASE) {
|
||||
if (item.hasNonDefaultComponent(ComponentKeys.LORE)) {
|
||||
if (item.hasNonDefaultComponent(DataComponentKeys.LORE)) {
|
||||
return item;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package net.momirealms.craftengine.core.plugin;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.trade.MerchantOffer;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleType;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Platform {
|
||||
|
||||
void dispatchCommand(String command);
|
||||
@@ -21,4 +26,6 @@ public interface Platform {
|
||||
World getWorld(String name);
|
||||
|
||||
ParticleType getParticleType(Key name);
|
||||
|
||||
<I> void openMerchant(Player player, Component title, List<MerchantOffer<I>> offers);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user