From d165d83d9b0425867c2f70876c600f4931a3090b Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sun, 6 Jul 2025 05:21:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0attribute-modifiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukkit/item/ComponentItemWrapper.java | 12 +- .../bukkit/item/ModernNetworkItemHandler.java | 12 +- .../item/factory/BukkitItemFactory.java | 7 +- .../factory/ComponentItemFactory1_20_5.java | 7 +- .../handler/CommonItemPacketHandler.java | 2 - .../src/main/resources/translations/en.yml | 5 + .../src/main/resources/translations/zh_cn.yml | 5 + .../core/attribute/AttributeModifier.java | 81 ++++++++ .../core/attribute/Attributes.java | 43 ++++ .../core/attribute/Attributes1_21.java | 37 ++++ .../craftengine/core/item/AbstractItem.java | 7 +- .../core/item/AbstractItemManager.java | 33 +++ .../craftengine/core/item/Item.java | 4 +- .../craftengine/core/item/ItemFactory.java | 4 +- .../core/item/modifier/ArgumentModifier.java | 2 +- .../modifier/AttributeModifiersModifier.java | 193 ++++++++++++++++++ .../core/item/modifier/ComponentModifier.java | 2 +- .../modifier/CustomModelDataModifier.java | 2 +- .../item/modifier/CustomNameModifier.java | 2 +- .../core/item/modifier/DyedColorModifier.java | 2 +- .../item/modifier/DynamicLoreModifier.java | 2 +- .../item/modifier/EnchantmentModifier.java | 4 +- .../modifier/EquippableAssetIdModifier.java | 2 +- .../core/item/modifier/FoodModifier.java | 2 +- .../item/modifier/HideTooltipModifier.java | 6 +- .../core/item/modifier/ItemModelModifier.java | 2 +- .../core/item/modifier/ItemNameModifier.java | 2 +- .../core/item/modifier/LoreModifier.java | 2 +- .../modifier/RemoveComponentModifier.java | 2 +- .../item/modifier/TooltipStyleModifier.java | 2 +- .../core/item/modifier/TrimModifier.java | 2 +- .../item/modifier/UnbreakableModifier.java | 2 +- .../craftengine/core/util/UUIDUtils.java | 14 ++ gradle.properties | 4 +- 34 files changed, 474 insertions(+), 36 deletions(-) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/attribute/AttributeModifier.java create mode 100644 core/src/main/java/net/momirealms/craftengine/core/attribute/Attributes.java create mode 100644 core/src/main/java/net/momirealms/craftengine/core/attribute/Attributes1_21.java create mode 100644 core/src/main/java/net/momirealms/craftengine/core/item/modifier/AttributeModifiersModifier.java diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ComponentItemWrapper.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ComponentItemWrapper.java index 4414f8e54..4e5f82e8b 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ComponentItemWrapper.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ComponentItemWrapper.java @@ -72,8 +72,18 @@ public class ComponentItemWrapper implements ItemWrapper { return getComponentInternal(type, MRegistryOps.NBT); } + @SuppressWarnings({"rawtypes", "unchecked"}) public Optional getSparrowNBTComponent(Object type) { - return getComponentInternal(type, MRegistryOps.SPARROW_NBT); + Object componentType = ensureDataComponentType(type); + Codec codec = FastNMS.INSTANCE.method$DataComponentType$codec(componentType); + try { + Object componentData = FastNMS.INSTANCE.method$ItemStack$getComponent(getLiteralObject(), componentType); + if (componentData == null) return Optional.empty(); + DataResult result = codec.encodeStart(MRegistryOps.SPARROW_NBT, componentData); + return result.result().map(Tag::copy); + } catch (Throwable t) { + throw new RuntimeException("Cannot read component " + type.toString(), t); + } } @SuppressWarnings({"rawtypes", "unchecked"}) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ModernNetworkItemHandler.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ModernNetworkItemHandler.java index 26a76df2e..b94a64568 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ModernNetworkItemHandler.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ModernNetworkItemHandler.java @@ -29,7 +29,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler> c2s(Item wrapped) { - Tag customData = wrapped.getNBTComponent(ComponentTypes.CUSTOM_DATA); + Tag customData = wrapped.getSparrowNBTComponent(ComponentTypes.CUSTOM_DATA); if (!(customData instanceof CompoundTag compoundTag)) return Optional.empty(); Optional> optionalCustomItem = wrapped.getCustomItem(); boolean hasDifferentMaterial = false; @@ -75,7 +75,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler item, Supplier tag) { - Tag nameTag = item.getNBTComponent(ComponentTypes.ITEM_NAME); + Tag nameTag = item.getSparrowNBTComponent(ComponentTypes.ITEM_NAME); if (nameTag == null) return false; String tagStr = nameTag.getAsString(); Map tokens = CraftEngine.instance().fontManager().matchTags(tagStr); @@ -189,7 +189,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler item, Supplier tag) { - Tag nameTag = item.getNBTComponent(ComponentTypes.CUSTOM_NAME); + Tag nameTag = item.getSparrowNBTComponent(ComponentTypes.CUSTOM_NAME); if (nameTag == null) return false; String tagStr = nameTag.getAsString(); Map tokens = CraftEngine.instance().fontManager().matchTags(tagStr); @@ -202,7 +202,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler item, Supplier tagSupplier) { - Tag loreTag = item.getNBTComponent(ComponentTypes.LORE); + Tag loreTag = item.getSparrowNBTComponent(ComponentTypes.LORE); boolean changed = false; if (!(loreTag instanceof ListTag listTag)) { return false; @@ -254,7 +254,7 @@ public final class ModernNetworkItemHandler implements NetworkItemHandler> extend } @Override - protected Tag getNBTComponent(W item, Object type) { + public Object getNBTComponent(W item, Object type) { + throw new UnsupportedOperationException("This feature is only available on 1.20.5+"); + } + + @Override + protected Tag getSparrowNBTComponent(W item, Object type) { throw new UnsupportedOperationException("This feature is only available on 1.20.5+"); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/factory/ComponentItemFactory1_20_5.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/factory/ComponentItemFactory1_20_5.java index 41461ead5..f361b57e2 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/factory/ComponentItemFactory1_20_5.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/factory/ComponentItemFactory1_20_5.java @@ -227,7 +227,12 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactoryIssue warning.config.item.settings.equipment.missing_asset_id: "Issue found in file - The item '' is missing the required 'asset-id' argument for 'equipment' settings." warning.config.item.settings.equipment.invalid_asset_id: "Issue found in file - The item '' is using an invalid 'asset-id' argument for 'equipment' settings. This might be because you haven't created this equipment configuration or misspelled the asset-id." warning.config.item.settings.projectile.missing_item: "Issue found in file - The item '' is missing the required 'item' argument for 'projectile' settings." +warning.config.item.data.attribute_modifiers.missing_type: "Issue found in file - The item '' is missing the required 'type' argument for 'attribute-modifiers' data." +warning.config.item.data.attribute_modifiers.missing_amount: "Issue found in file - The item '' is missing the required 'amount' argument for 'attribute-modifiers' data." +warning.config.item.data.attribute_modifiers.missing_operation: "Issue found in file - The item '' is missing the required 'operation' argument for 'attribute-modifiers' data." +warning.config.item.data.attribute_modifiers.display.missing_type: "Issue found in file - The item '' is missing the required 'type' argument for 'attribute-modifiers' display data." +warning.config.item.data.attribute_modifiers.display.missing_value: "Issue found in file - The item '' is missing the required 'value' argument for 'attribute-modifiers' display data." warning.config.item.missing_material: "Issue found in file - The item '' is missing the required 'material' argument." warning.config.item.invalid_material: "Issue found in file - The item '' is using an invalid material type ''." warning.config.item.invalid_custom_model_data: "Issue found in file - The item '' is using a negative custom model data '' which is invalid." diff --git a/common-files/src/main/resources/translations/zh_cn.yml b/common-files/src/main/resources/translations/zh_cn.yml index de5367bc2..b0c543e5b 100644 --- a/common-files/src/main/resources/translations/zh_cn.yml +++ b/common-files/src/main/resources/translations/zh_cn.yml @@ -160,6 +160,11 @@ warning.config.item.settings.invulnerable.invalid_damage_source: "在文 warning.config.item.settings.equipment.missing_asset_id: "在文件 发现问题 - 物品 '' 缺少 'equipment' 设置所需的 'asset-id' 参数." warning.config.item.settings.equipment.invalid_asset_id: "在文件 发现问题 - 物品 '' 为 'equipment' 设置配置了无效的 'asset-id'. 这可能是因为你没有创建装备配置或是错误地拼写了 asset-id." warning.config.item.settings.projectile.missing_item: "在文件 发现问题 - 物品 '' 缺少 'projectile' 设置所需的 'item' 参数." +warning.config.item.data.attribute_modifiers.missing_type: "在文件 发现问题 - 物品 '' 缺少 'attribute-modifiers' 数据所需的 'type' 参数." +warning.config.item.data.attribute_modifiers.missing_amount: "在文件 发现问题 - 物品 '' 缺少 'attribute-modifiers' 数据所需的 'amount' 参数." +warning.config.item.data.attribute_modifiers.missing_operation: "在文件 发现问题 - 物品 '' 缺少 'attribute-modifiers' 数据所需的 'operation' 参数." +warning.config.item.data.attribute_modifiers.display.missing_type: "在文件 发现问题 - 物品 '' 缺少 'attribute-modifiers' 显示数据所需的 'type' 参数。" +warning.config.item.data.attribute_modifiers.display.missing_value: "在文件 发现问题 - 物品 '' 缺少 'attribute-modifiers' 显示数据所需的 'value' 参数。" warning.config.item.missing_material: "在文件 发现问题 - 物品 '' 缺少必需的 'material' 参数" warning.config.item.invalid_material: "在文件 发现问题 - 物品 '' 使用了无效的材料类型 ''" warning.config.item.invalid_custom_model_data: "在文件 发现问题 - 物品 '' 使用了无效的负数模型值 ''." diff --git a/core/src/main/java/net/momirealms/craftengine/core/attribute/AttributeModifier.java b/core/src/main/java/net/momirealms/craftengine/core/attribute/AttributeModifier.java new file mode 100644 index 000000000..0d5ff2dfb --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/attribute/AttributeModifier.java @@ -0,0 +1,81 @@ +package net.momirealms.craftengine.core.attribute; + +import net.momirealms.craftengine.core.util.Key; +import org.jetbrains.annotations.Nullable; + +public class AttributeModifier { + private final String type; + private final Slot slot; + private final Key id; + private final double amount; + private final Operation operation; + @Nullable + private final Display display; + + public AttributeModifier(String type, Slot slot, Key id, double amount, Operation operation, @Nullable Display display) { + this.amount = amount; + this.display = display; + this.id = id; + this.operation = operation; + this.slot = slot; + this.type = type; + } + + public double amount() { + return amount; + } + + public @Nullable Display display() { + return display; + } + + public Key id() { + return id; + } + + public Operation operation() { + return operation; + } + + public Slot slot() { + return slot; + } + + public String type() { + return type; + } + + public enum Slot { + ANY, + HAND, + ARMOR, + MAINHAND, + OFFHAND, + HEAD, + CHEST, + LEGS, + FEET, + BODY + } + + public enum Operation { + ADD_VALUE("add_value"), ADD_MULTIPLIED_BASE("add_multiplied_base"), ADD_MULTIPLIED_TOTAL("add_multiplied_total"); + + private final String id; + + Operation(String id) { + this.id = id; + } + + public String id() { + return id; + } + } + + public record Display(AttributeModifier.Display.Type type, String value) { + + public enum Type { + DEFAULT, HIDDEN, OVERRIDE + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/attribute/Attributes.java b/core/src/main/java/net/momirealms/craftengine/core/attribute/Attributes.java new file mode 100644 index 000000000..2ff402e78 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/attribute/Attributes.java @@ -0,0 +1,43 @@ +package net.momirealms.craftengine.core.attribute; + +import net.momirealms.craftengine.core.util.Key; + +public final class Attributes { + private Attributes() {} + // latest version + public static final Key ARMOR = Key.from("armor"); + public static final Key ARMOR_TOUGHNESS = Key.from("armor_toughness"); + public static final Key ATTACK_DAMAGE = Key.from("attack_damage"); + public static final Key ATTACK_KNOCKBACK = Key.from("attack_knockback"); + public static final Key ATTACK_SPEED = Key.from("attack_speed"); + public static final Key BLOCK_BREAK_SPEED = Key.from("block_break_speed"); + public static final Key BLOCK_INTERACTION_RANGE = Key.from("block_interaction_range"); + public static final Key BURNING_TIME = Key.from("burning_time"); + public static final Key CAMERA_DISTANCE = Key.from("camera_distance"); + public static final Key ENTITY_INTERACTION_RANGE = Key.from("entity_interaction_range"); + public static final Key EXPLOSION_KNOCKBACK_RESISTANCE = Key.from("explosion_knockback_resistance"); + public static final Key FALL_DAMAGE_MULTIPLIER = Key.from("fall_damage_multiplier"); + public static final Key FLYING_SPEED = Key.from("flying_speed"); + public static final Key FOLLOW_RANGE = Key.from("follow_range"); + public static final Key GRAVITY = Key.from("gravity"); + public static final Key JUMP_STRENGTH = Key.from("jump_strength"); + public static final Key KNOCKBACK_RESISTANCE = Key.from("knockback_resistance"); + public static final Key LUCK = Key.from("luck"); + public static final Key MAX_ABSORPTION = Key.from("max_absorption"); + public static final Key MAX_HEALTH = Key.from("max_health"); + public static final Key MINING_EFFICIENCY = Key.from("mining_efficiency"); + public static final Key MOVEMENT_EFFICIENCY = Key.from("movement_efficiency"); + public static final Key MOVEMENT_SPEED = Key.from("movement_speed"); + public static final Key OXYGEN_BONUS = Key.from("oxygen_bonus"); + public static final Key SAFE_FALL_DISTANCE = Key.from("safe_fall_distance"); + public static final Key SCALE = Key.from("scale"); + public static final Key SPAWN_REINFORCEMENT = Key.from("spawn_reinforcements"); + public static final Key SNEAKING_SPEED = Key.from("sneaking_speed"); + public static final Key STEP_HEIGHT = Key.from("step_height"); + public static final Key SUBMERGED_MINING_SPEED = Key.from("submerged_mining_speed"); + public static final Key SWEEPING_DAMAGE_RATIO = Key.from("sweeping_damage_ratio"); + public static final Key TEMPT_RANGE = Key.from("tempt_range"); + public static final Key WATER_MOVEMENT_EFFICIENCY = Key.from("water_movement_efficiency"); + public static final Key WAYPOINT_RECEIVE_RANGE = Key.from("waypoint_receive_range"); + public static final Key WAYPOINT_TRANSMIT_RANGE = Key.from("waypoint_transmit_range"); +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/attribute/Attributes1_21.java b/core/src/main/java/net/momirealms/craftengine/core/attribute/Attributes1_21.java new file mode 100644 index 000000000..0410b3922 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/attribute/Attributes1_21.java @@ -0,0 +1,37 @@ +package net.momirealms.craftengine.core.attribute; + +import net.momirealms.craftengine.core.util.Key; + +public final class Attributes1_21 { + private Attributes1_21() {} + public static final Key ARMOR = Key.from("generic.armor"); + public static final Key ARMOR_TOUGHNESS = Key.from("generic.armor_toughness"); + public static final Key ATTACK_DAMAGE = Key.from("generic.attack_damage"); + public static final Key ATTACK_KNOCKBACK = Key.from("generic.attack_knockback"); + public static final Key ATTACK_SPEED = Key.from("generic.attack_speed"); + public static final Key FLYING_SPEED = Key.from("generic.flying_speed"); + public static final Key FOLLOW_RANGE = Key.from("generic.follow_range"); + public static final Key KNOCKBACK_RESISTANCE = Key.from("generic.knockback_resistance"); + public static final Key LUCK = Key.from("generic.luck"); + public static final Key MAX_ABSORPTION = Key.from("generic.max_absorption"); + public static final Key MAX_HEALTH = Key.from("generic.max_health"); + public static final Key MOVEMENT_EFFICIENCY = Key.from("generic.movement_efficiency"); + public static final Key SCALE = Key.from("generic.scale"); + public static final Key STEP_HEIGHT = Key.from("generic.step_height"); + public static final Key JUMP_STRENGTH = Key.from("generic.jump_strength"); + public static final Key ENTITY_INTERACTION_RANGE = Key.from("player.entity_interaction_range"); + public static final Key BLOCK_INTERACTION_RANGE = Key.from("player.block_interaction_range"); + public static final Key SPAWN_REINFORCEMENT = Key.from("zombie.spawn_reinforcements"); + public static final Key BLOCK_BREAK_SPEED = Key.from("player.block_break_speed"); + public static final Key GRAVITY = Key.from("generic.gravity"); + public static final Key SAFE_FALL_DISTANCE = Key.from("generic.safe_fall_distance"); + public static final Key FALL_DAMAGE_MULTIPLIER = Key.from("generic.fall_damage_multiplier"); + public static final Key BURNING_TIME = Key.from("generic.burning_time"); + public static final Key EXPLOSION_KNOCKBACK_RESISTANCE = Key.from("generic.explosion_knockback_resistance"); + public static final Key MINING_EFFICIENCY = Key.from("player.mining_efficiency"); + public static final Key OXYGEN_BONUS = Key.from("generic.oxygen_bonus"); + public static final Key SNEAKING_SPEED = Key.from("player.sneaking_speed"); + public static final Key SUBMERGED_MINING_SPEED = Key.from("player.submerged_mining_speed"); + public static final Key SWEEPING_DAMAGE_RATIO = Key.from("player.sweeping_damage_ratio"); + public static final Key WATER_MOVEMENT_EFFICIENCY = Key.from("generic.water_movement_efficiency"); +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItem.java b/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItem.java index fc3cc6e25..aada4746b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItem.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItem.java @@ -366,7 +366,12 @@ public class AbstractItem, I> implements Item { } @Override - public Tag getNBTComponent(Object type) { + public Tag getSparrowNBTComponent(Object type) { + return this.factory.getSparrowNBTComponent(this.item, type); + } + + @Override + public Object getNBTComponent(Object type) { return this.factory.getNBTComponent(this.item, type); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java b/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java index 5ee3e5a45..61536f023 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.item; +import net.momirealms.craftengine.core.attribute.AttributeModifier; import net.momirealms.craftengine.core.item.behavior.ItemBehavior; import net.momirealms.craftengine.core.item.behavior.ItemBehaviors; import net.momirealms.craftengine.core.item.data.Enchantment; @@ -532,6 +533,38 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl return new TagsModifier<>(data); }, "tags", "tag", "nbt"); } + registerDataType((object -> { + MutableInt mutableInt = new MutableInt(0); + List attributeModifiers = ResourceConfigUtils.parseConfigAsList(object, (map) -> { + String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.item.data.attribute_modifiers.missing_type"); + Key nativeType = AttributeModifiersModifier.getNativeAttributeName(Key.of(type)); + AttributeModifier.Slot slot = AttributeModifier.Slot.valueOf(map.getOrDefault("slot", "any").toString().toUpperCase(Locale.ENGLISH)); + Key id = Optional.ofNullable(map.get("id")).map(String::valueOf).map(Key::of).orElseGet(() -> { + mutableInt.add(1); + return Key.of("craftengine", "modifier_" + mutableInt.intValue()); + }); + double amount = ResourceConfigUtils.getAsDouble( + ResourceConfigUtils.requireNonNullOrThrow(map.get("amount"), "warning.config.item.data.attribute_modifiers.missing_amount"), "amount" + ); + AttributeModifier.Operation operation = AttributeModifier.Operation.valueOf( + ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("operation"), "warning.config.item.data.attribute_modifiers.missing_operation").toUpperCase(Locale.ENGLISH) + ); + AttributeModifier.Display display = null; + if (VersionHelper.isOrAbove1_21_6() && map.containsKey("display")) { + Map displayMap = MiscUtils.castToMap(map.get("display"), false); + AttributeModifier.Display.Type displayType = AttributeModifier.Display.Type.valueOf(ResourceConfigUtils.requireNonEmptyStringOrThrow(displayMap.get("type"), "warning.config.item.data.attribute_modifiers.display.missing_type").toUpperCase(Locale.ENGLISH)); + if (displayType == AttributeModifier.Display.Type.OVERRIDE) { + String miniMessageValue = ResourceConfigUtils.requireNonEmptyStringOrThrow(displayMap.get("value"), "warning.config.item.data.attribute_modifiers.display.missing_value"); + display = new AttributeModifier.Display(displayType, miniMessageValue); + } else { + display = new AttributeModifier.Display(displayType, null); + } + } + return new AttributeModifier(nativeType.value(), slot, id, + amount, operation, display); + }); + return new AttributeModifiersModifier<>(attributeModifiers); + }), "attributes", "attribute-modifiers", "attribute-modifier"); registerDataType((obj) -> { boolean value = TypeUtils.checkType(obj, Boolean.class); return new UnbreakableModifier<>(value); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/Item.java b/core/src/main/java/net/momirealms/craftengine/core/item/Item.java index 237eb3d0e..02e2e1d44 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/Item.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/Item.java @@ -154,7 +154,9 @@ public interface Item { JsonElement getJsonComponent(Object type); - Tag getNBTComponent(Object type); + Tag getSparrowNBTComponent(Object type); + + Object getNBTComponent(Object type); void setComponent(Object type, Object value); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/ItemFactory.java b/core/src/main/java/net/momirealms/craftengine/core/item/ItemFactory.java index f0af10fe0..067a8aca6 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/ItemFactory.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/ItemFactory.java @@ -53,7 +53,9 @@ public abstract class ItemFactory, I> { protected abstract JsonElement getJsonComponent(W item, Object type); - protected abstract Tag getNBTComponent(W item, Object type); + protected abstract Tag getSparrowNBTComponent(W item, Object type); + + protected abstract Object getNBTComponent(W item, Object type); protected abstract boolean hasComponent(W item, Object type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ArgumentModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ArgumentModifier.java index a3ec03e7d..63628171d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ArgumentModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ArgumentModifier.java @@ -28,7 +28,7 @@ public class ArgumentModifier implements ItemDataModifier { @Override public Item apply(Item item, ItemBuildContext context) { if (VersionHelper.isOrAbove1_20_5()) { - CompoundTag customData = (CompoundTag) Optional.ofNullable(item.getNBTComponent(ComponentKeys.CUSTOM_DATA)).orElse(new CompoundTag()); + CompoundTag customData = (CompoundTag) Optional.ofNullable(item.getSparrowNBTComponent(ComponentKeys.CUSTOM_DATA)).orElse(new CompoundTag()); CompoundTag argumentTag = new CompoundTag(); for (Map.Entry entry : this.arguments.entrySet()) { argumentTag.put(entry.getKey(), new StringTag(entry.getValue().get(context))); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/AttributeModifiersModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/AttributeModifiersModifier.java new file mode 100644 index 000000000..fcd097ffd --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/AttributeModifiersModifier.java @@ -0,0 +1,193 @@ +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.Item; +import net.momirealms.craftengine.core.item.ItemBuildContext; +import net.momirealms.craftengine.core.item.NetworkItemHandler; +import net.momirealms.craftengine.core.util.AdventureHelper; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.UUIDUtils; +import net.momirealms.craftengine.core.util.VersionHelper; +import net.momirealms.sparrow.nbt.CompoundTag; +import net.momirealms.sparrow.nbt.ListTag; +import net.momirealms.sparrow.nbt.Tag; + +import java.nio.charset.StandardCharsets; +import java.util.*; + +public class AttributeModifiersModifier implements ItemDataModifier { + public static final Map CONVERTOR = new HashMap<>(); + + static { + if (VersionHelper.isOrAbove1_20_2()) { + CONVERTOR.put(Attributes1_21.BURNING_TIME, Attributes.BURNING_TIME); + CONVERTOR.put(Attributes1_21.ARMOR, Attributes.ARMOR); + CONVERTOR.put(Attributes1_21.ARMOR_TOUGHNESS, Attributes.ARMOR_TOUGHNESS); + CONVERTOR.put(Attributes1_21.ATTACK_KNOCKBACK, Attributes.ATTACK_KNOCKBACK); + CONVERTOR.put(Attributes1_21.ATTACK_DAMAGE, Attributes.ATTACK_DAMAGE); + CONVERTOR.put(Attributes1_21.ATTACK_SPEED, Attributes.ATTACK_SPEED); + CONVERTOR.put(Attributes1_21.FLYING_SPEED, Attributes.FLYING_SPEED); + CONVERTOR.put(Attributes1_21.FOLLOW_RANGE, Attributes.FOLLOW_RANGE); + CONVERTOR.put(Attributes1_21.KNOCKBACK_RESISTANCE, Attributes.KNOCKBACK_RESISTANCE); + CONVERTOR.put(Attributes1_21.LUCK, Attributes.LUCK); + CONVERTOR.put(Attributes1_21.MAX_ABSORPTION, Attributes.MAX_ABSORPTION); + CONVERTOR.put(Attributes1_21.MAX_HEALTH, Attributes.MAX_HEALTH); + CONVERTOR.put(Attributes1_21.MOVEMENT_EFFICIENCY, Attributes.MOVEMENT_EFFICIENCY); + CONVERTOR.put(Attributes1_21.SCALE, Attributes.SCALE); + CONVERTOR.put(Attributes1_21.STEP_HEIGHT, Attributes.STEP_HEIGHT); + CONVERTOR.put(Attributes1_21.JUMP_STRENGTH, Attributes.JUMP_STRENGTH); + CONVERTOR.put(Attributes1_21.ENTITY_INTERACTION_RANGE, Attributes.ENTITY_INTERACTION_RANGE); + CONVERTOR.put(Attributes1_21.BLOCK_INTERACTION_RANGE, Attributes.BLOCK_INTERACTION_RANGE); + CONVERTOR.put(Attributes1_21.SPAWN_REINFORCEMENT, Attributes.SPAWN_REINFORCEMENT); + CONVERTOR.put(Attributes1_21.BLOCK_BREAK_SPEED, Attributes.BLOCK_BREAK_SPEED); + CONVERTOR.put(Attributes1_21.GRAVITY, Attributes.GRAVITY); + CONVERTOR.put(Attributes1_21.SAFE_FALL_DISTANCE, Attributes.SAFE_FALL_DISTANCE); + CONVERTOR.put(Attributes1_21.FALL_DAMAGE_MULTIPLIER, Attributes.FALL_DAMAGE_MULTIPLIER); + CONVERTOR.put(Attributes1_21.EXPLOSION_KNOCKBACK_RESISTANCE, Attributes.EXPLOSION_KNOCKBACK_RESISTANCE); + CONVERTOR.put(Attributes1_21.MINING_EFFICIENCY, Attributes.MINING_EFFICIENCY); + CONVERTOR.put(Attributes1_21.OXYGEN_BONUS, Attributes.OXYGEN_BONUS); + CONVERTOR.put(Attributes1_21.SNEAKING_SPEED, Attributes.SNEAKING_SPEED); + CONVERTOR.put(Attributes1_21.SUBMERGED_MINING_SPEED, Attributes.SUBMERGED_MINING_SPEED); + CONVERTOR.put(Attributes1_21.SWEEPING_DAMAGE_RATIO, Attributes.SWEEPING_DAMAGE_RATIO); + CONVERTOR.put(Attributes1_21.WATER_MOVEMENT_EFFICIENCY, Attributes.WATER_MOVEMENT_EFFICIENCY); + } else { + CONVERTOR.put(Attributes.BURNING_TIME, Attributes1_21.BURNING_TIME); + CONVERTOR.put(Attributes.ARMOR, Attributes1_21.ARMOR); + CONVERTOR.put(Attributes.ARMOR_TOUGHNESS, Attributes1_21.ARMOR_TOUGHNESS); + CONVERTOR.put(Attributes.ATTACK_KNOCKBACK, Attributes1_21.ATTACK_KNOCKBACK); + CONVERTOR.put(Attributes.ATTACK_DAMAGE, Attributes1_21.ATTACK_DAMAGE); + CONVERTOR.put(Attributes.ATTACK_SPEED, Attributes1_21.ATTACK_SPEED); + CONVERTOR.put(Attributes.FLYING_SPEED, Attributes1_21.FLYING_SPEED); + CONVERTOR.put(Attributes.FOLLOW_RANGE, Attributes1_21.FOLLOW_RANGE); + CONVERTOR.put(Attributes.KNOCKBACK_RESISTANCE, Attributes1_21.KNOCKBACK_RESISTANCE); + CONVERTOR.put(Attributes.LUCK, Attributes1_21.LUCK); + CONVERTOR.put(Attributes.MAX_ABSORPTION, Attributes1_21.MAX_ABSORPTION); + CONVERTOR.put(Attributes.MAX_HEALTH, Attributes1_21.MAX_HEALTH); + CONVERTOR.put(Attributes.MOVEMENT_EFFICIENCY, Attributes1_21.MOVEMENT_EFFICIENCY); + CONVERTOR.put(Attributes.SCALE, Attributes1_21.SCALE); + CONVERTOR.put(Attributes.STEP_HEIGHT, Attributes1_21.STEP_HEIGHT); + CONVERTOR.put(Attributes.JUMP_STRENGTH, Attributes1_21.JUMP_STRENGTH); + CONVERTOR.put(Attributes.ENTITY_INTERACTION_RANGE, Attributes1_21.ENTITY_INTERACTION_RANGE); + CONVERTOR.put(Attributes.BLOCK_INTERACTION_RANGE, Attributes1_21.BLOCK_INTERACTION_RANGE); + CONVERTOR.put(Attributes.SPAWN_REINFORCEMENT, Attributes1_21.SPAWN_REINFORCEMENT); + CONVERTOR.put(Attributes.BLOCK_BREAK_SPEED, Attributes1_21.BLOCK_BREAK_SPEED); + CONVERTOR.put(Attributes.GRAVITY, Attributes1_21.GRAVITY); + CONVERTOR.put(Attributes.SAFE_FALL_DISTANCE, Attributes1_21.SAFE_FALL_DISTANCE); + CONVERTOR.put(Attributes.FALL_DAMAGE_MULTIPLIER, Attributes1_21.FALL_DAMAGE_MULTIPLIER); + CONVERTOR.put(Attributes.EXPLOSION_KNOCKBACK_RESISTANCE, Attributes1_21.EXPLOSION_KNOCKBACK_RESISTANCE); + CONVERTOR.put(Attributes.MINING_EFFICIENCY, Attributes1_21.MINING_EFFICIENCY); + CONVERTOR.put(Attributes.OXYGEN_BONUS, Attributes1_21.OXYGEN_BONUS); + CONVERTOR.put(Attributes.SNEAKING_SPEED, Attributes1_21.SNEAKING_SPEED); + CONVERTOR.put(Attributes.SUBMERGED_MINING_SPEED, Attributes1_21.SUBMERGED_MINING_SPEED); + CONVERTOR.put(Attributes.SWEEPING_DAMAGE_RATIO, Attributes1_21.SWEEPING_DAMAGE_RATIO); + CONVERTOR.put(Attributes.WATER_MOVEMENT_EFFICIENCY, Attributes1_21.WATER_MOVEMENT_EFFICIENCY); + } + } + + public static Key getNativeAttributeName(final Key attributeName) { + return CONVERTOR.getOrDefault(attributeName, attributeName); + } + + private final List modifiers; + + public AttributeModifiersModifier(List modifiers) { + this.modifiers = modifiers; + } + + public List modifiers() { + return this.modifiers; + } + + @Override + public String name() { + return "attribute-modifiers"; + } + + private static Object previous; + + @Override + public Item apply(Item item, ItemBuildContext context) { + if (VersionHelper.isOrAbove1_21_5()) { + ListTag modifiers = (ListTag) Optional.ofNullable(item.getSparrowNBTComponent(ComponentKeys.ATTRIBUTE_MODIFIERS)).orElseGet(ListTag::new); + for (AttributeModifier modifier : this.modifiers) { + CompoundTag modifierTag = new CompoundTag(); + modifierTag.putString("type", modifier.type()); + modifierTag.putString("slot", modifier.slot().name().toLowerCase(Locale.ENGLISH)); + modifierTag.putString("id", modifier.id().toString()); + modifierTag.putDouble("amount", modifier.amount()); + modifierTag.putString("operation", modifier.operation().id()); + AttributeModifier.Display display = modifier.display(); + if (VersionHelper.isOrAbove1_21_6() && display != null) { + CompoundTag displayTag = new CompoundTag(); + AttributeModifier.Display.Type displayType = display.type(); + displayTag.putString("type", displayType.name().toLowerCase(Locale.ENGLISH)); + if (displayType == AttributeModifier.Display.Type.OVERRIDE) { + displayTag.put("value", AdventureHelper.componentToTag(AdventureHelper.miniMessage().deserialize(display.value(), context.tagResolvers()))); + } + modifierTag.put("display", displayTag); + } + modifiers.add(modifierTag); + } + item.setNBTComponent(ComponentKeys.ATTRIBUTE_MODIFIERS, modifiers); + } else if (VersionHelper.isOrAbove1_20_5()) { + CompoundTag compoundTag = (CompoundTag) Optional.ofNullable(item.getSparrowNBTComponent(ComponentKeys.ATTRIBUTE_MODIFIERS)).orElseGet(CompoundTag::new); + ListTag modifiers = compoundTag.getList("modifiers"); + if (modifiers == null) { + modifiers = new ListTag(); + compoundTag.put("modifiers", modifiers); + } + for (AttributeModifier modifier : this.modifiers) { + CompoundTag modifierTag = new CompoundTag(); + modifierTag.putString("type", modifier.type()); + modifierTag.putString("slot", modifier.slot().name().toLowerCase(Locale.ENGLISH)); + if (VersionHelper.isOrAbove1_21()) { + modifierTag.putString("id", modifier.id().toString()); + } else { + modifierTag.putIntArray("uuid", UUIDUtils.uuidToIntArray(UUID.nameUUIDFromBytes(modifier.id().toString().getBytes(StandardCharsets.UTF_8)))); + modifierTag.putString("name", modifier.id().toString()); + } + modifierTag.putDouble("amount", modifier.amount()); + modifierTag.putString("operation", modifier.operation().id()); + modifiers.add(modifierTag); + } + item.setNBTComponent(ComponentKeys.ATTRIBUTE_MODIFIERS, compoundTag); + } else { + ListTag listTag = (ListTag) Optional.ofNullable(item.getNBTTag("AttributeModifiers")).orElseGet(ListTag::new); + for (AttributeModifier modifier : this.modifiers) { + CompoundTag modifierTag = new CompoundTag(); + modifierTag.putString("AttributeName", modifier.type()); + modifierTag.putString("Name", modifier.id().toString()); + modifierTag.putString("Slot", modifier.slot().name().toLowerCase(Locale.ENGLISH)); + modifierTag.putInt("Operation", modifier.operation().ordinal()); + modifierTag.putDouble("Amount", modifier.amount()); + modifierTag.putIntArray("UUID", UUIDUtils.uuidToIntArray(UUID.nameUUIDFromBytes(modifier.id().toString().getBytes(StandardCharsets.UTF_8)))); + listTag.add(modifierTag); + } + item.setTag(listTag, "AttributeModifiers"); + } + return item; + } + + @Override + public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { + if (VersionHelper.isOrAbove1_20_5()) { + Tag previous = item.getSparrowNBTComponent(ComponentKeys.ATTRIBUTE_MODIFIERS); + if (previous != null) { + networkData.put(ComponentKeys.ATTRIBUTE_MODIFIERS.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); + } else { + networkData.put(ComponentKeys.ATTRIBUTE_MODIFIERS.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE)); + } + } else { + Tag previous = item.getNBTTag("AttributeModifiers"); + if (previous != null) { + networkData.put("AttributeModifiers", NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); + } else { + networkData.put("AttributeModifiers", NetworkItemHandler.pack(NetworkItemHandler.Operation.REMOVE)); + } + } + return item; + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ComponentModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ComponentModifier.java index e9c333e69..b23c283f1 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ComponentModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ComponentModifier.java @@ -75,7 +75,7 @@ public class ComponentModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { for (Pair entry : this.arguments) { - Tag previous = item.getNBTComponent(entry.left()); + Tag previous = item.getSparrowNBTComponent(entry.left()); if (previous != null) { networkData.put(entry.left().asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/CustomModelDataModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/CustomModelDataModifier.java index 9634a56c1..2449d816b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/CustomModelDataModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/CustomModelDataModifier.java @@ -29,7 +29,7 @@ public class CustomModelDataModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.CUSTOM_MODEL_DATA); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.CUSTOM_MODEL_DATA); if (previous != null) { networkData.put(ComponentKeys.CUSTOM_MODEL_DATA.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/CustomNameModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/CustomNameModifier.java index ae46ebae5..ab3b0adfe 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/CustomNameModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/CustomNameModifier.java @@ -30,7 +30,7 @@ public class CustomNameModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.CUSTOM_NAME); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.CUSTOM_NAME); if (previous != null) { networkData.put(ComponentKeys.CUSTOM_NAME.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/DyedColorModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/DyedColorModifier.java index d85b3133e..329490661 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/DyedColorModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/DyedColorModifier.java @@ -29,7 +29,7 @@ public class DyedColorModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.DYED_COLOR); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.DYED_COLOR); if (previous != null) { networkData.put(ComponentKeys.DYED_COLOR.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/DynamicLoreModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/DynamicLoreModifier.java index 8962c63e0..a365694f7 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/DynamicLoreModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/DynamicLoreModifier.java @@ -47,7 +47,7 @@ public class DynamicLoreModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.LORE); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.LORE); if (previous != null) { networkData.put(ComponentKeys.LORE.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/EnchantmentModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/EnchantmentModifier.java index baf4e6caf..d223c4708 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/EnchantmentModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/EnchantmentModifier.java @@ -34,7 +34,7 @@ public class EnchantmentModifier implements ItemDataModifier { public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (item.vanillaId().equals(ItemKeys.ENCHANTED_BOOK)) { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.STORED_ENCHANTMENTS); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.STORED_ENCHANTMENTS); if (previous != null) { networkData.put(ComponentKeys.STORED_ENCHANTMENTS.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { @@ -50,7 +50,7 @@ public class EnchantmentModifier implements ItemDataModifier { } } else { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.ENCHANTMENTS); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.ENCHANTMENTS); if (previous != null) { networkData.put(ComponentKeys.ENCHANTMENTS.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/EquippableAssetIdModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/EquippableAssetIdModifier.java index 9472dfca9..48630e358 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/EquippableAssetIdModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/EquippableAssetIdModifier.java @@ -40,7 +40,7 @@ public class EquippableAssetIdModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { - Tag previous = item.getNBTComponent(ComponentKeys.EQUIPPABLE); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.EQUIPPABLE); if (previous != null) { networkData.put(ComponentKeys.EQUIPPABLE.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/FoodModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/FoodModifier.java index 38fc4232b..4ab82b684 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/FoodModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/FoodModifier.java @@ -37,7 +37,7 @@ public class FoodModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { - Tag previous = item.getNBTComponent(ComponentKeys.FOOD); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.FOOD); if (previous != null) { networkData.put(ComponentKeys.FOOD.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/HideTooltipModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/HideTooltipModifier.java index e3a3688d7..847089e5e 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/HideTooltipModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/HideTooltipModifier.java @@ -78,7 +78,7 @@ public class HideTooltipModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (VersionHelper.isOrAbove1_21_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.TOOLTIP_DISPLAY); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.TOOLTIP_DISPLAY); if (previous != null) { networkData.put(ComponentKeys.TOOLTIP_DISPLAY.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { @@ -86,7 +86,7 @@ public class HideTooltipModifier implements ItemDataModifier { } } else if (VersionHelper.isOrAbove1_20_5()) { for (Key component : this.components) { - Tag previous = item.getNBTComponent(component); + Tag previous = item.getSparrowNBTComponent(component); if (previous != null) { networkData.put(component.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { @@ -130,7 +130,7 @@ public class HideTooltipModifier implements ItemDataModifier { @Override public void apply(Item item) { - Tag previous = item.getNBTComponent(this.component); + Tag previous = item.getSparrowNBTComponent(this.component); if (previous instanceof CompoundTag compoundTag) { compoundTag.putBoolean("show_in_tooltip", false); item.setNBTComponent(this.component, compoundTag); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ItemModelModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ItemModelModifier.java index 0d4cea04d..319cacc13 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ItemModelModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ItemModelModifier.java @@ -28,7 +28,7 @@ public class ItemModelModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { - Tag previous = item.getNBTComponent(ComponentKeys.ITEM_MODEL); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.ITEM_MODEL); if (previous != null) { networkData.put(ComponentKeys.ITEM_MODEL.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ItemNameModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ItemNameModifier.java index 0171474e1..587b1c467 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ItemNameModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/ItemNameModifier.java @@ -30,7 +30,7 @@ public class ItemNameModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.ITEM_NAME); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.ITEM_NAME); if (previous != null) { networkData.put(ComponentKeys.ITEM_NAME.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/LoreModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/LoreModifier.java index dd5816861..aaa1c47fc 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/LoreModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/LoreModifier.java @@ -32,7 +32,7 @@ public class LoreModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.LORE); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.LORE); if (previous != null) { networkData.put(ComponentKeys.LORE.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/RemoveComponentModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/RemoveComponentModifier.java index f6461e772..324db069b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/RemoveComponentModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/RemoveComponentModifier.java @@ -36,7 +36,7 @@ public class RemoveComponentModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { for (String component : this.arguments) { - Tag previous = item.getNBTComponent(component); + Tag previous = item.getSparrowNBTComponent(component); if (previous != null) { networkData.put(component, NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/TooltipStyleModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/TooltipStyleModifier.java index af066a977..ac3a38114 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/TooltipStyleModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/TooltipStyleModifier.java @@ -28,7 +28,7 @@ public class TooltipStyleModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { - Tag previous = item.getNBTComponent(ComponentKeys.TOOLTIP_STYLE); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.TOOLTIP_STYLE); if (previous != null) { networkData.put(ComponentKeys.TOOLTIP_STYLE.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/TrimModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/TrimModifier.java index ff1e0db66..27650aea5 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/TrimModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/TrimModifier.java @@ -32,7 +32,7 @@ public class TrimModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.TRIM); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.TRIM); if (previous != null) { networkData.put(ComponentKeys.TRIM.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/UnbreakableModifier.java b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/UnbreakableModifier.java index 756152329..33ec2d9c2 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/modifier/UnbreakableModifier.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/modifier/UnbreakableModifier.java @@ -29,7 +29,7 @@ public class UnbreakableModifier implements ItemDataModifier { @Override public Item prepareNetworkItem(Item item, ItemBuildContext context, CompoundTag networkData) { if (VersionHelper.isOrAbove1_20_5()) { - Tag previous = item.getNBTComponent(ComponentKeys.UNBREAKABLE); + Tag previous = item.getSparrowNBTComponent(ComponentKeys.UNBREAKABLE); if (previous != null) { networkData.put(ComponentKeys.UNBREAKABLE.asString(), NetworkItemHandler.pack(NetworkItemHandler.Operation.ADD, previous)); } else { diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/UUIDUtils.java b/core/src/main/java/net/momirealms/craftengine/core/util/UUIDUtils.java index 9d29dc019..40a812d7c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/UUIDUtils.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/UUIDUtils.java @@ -6,4 +6,18 @@ public final class UUIDUtils { public static final UUID EMPTY = new UUID(0, 0); private UUIDUtils() {} + + public static UUID uuidFromIntArray(int[] array) { + return new UUID((long) array[0] << 32 | (long) array[1] & 4294967295L, (long) array[2] << 32 | (long) array[3] & 4294967295L); + } + + public static int[] uuidToIntArray(UUID uuid) { + long l = uuid.getMostSignificantBits(); + long m = uuid.getLeastSignificantBits(); + return leastMostToIntArray(l, m); + } + + private static int[] leastMostToIntArray(long uuidMost, long uuidLeast) { + return new int[]{(int) (uuidMost >> 32), (int) uuidMost, (int) (uuidLeast >> 32), (int) uuidLeast}; + } } diff --git a/gradle.properties b/gradle.properties index e74a4c804..69673cad8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=0.0.59.4 +project_version=0.0.59.5 config_version=41 lang_version=21 project_group=net.momirealms @@ -39,7 +39,7 @@ zstd_version=1.5.7-2 commons_io_version=2.18.0 commons_imaging_version=1.0.0-alpha6 commons_lang3_version=3.17.0 -sparrow_nbt_version=0.9.1 +sparrow_nbt_version=0.9.4 sparrow_util_version=0.50.6 fastutil_version=8.5.15 netty_version=4.1.121.Final