mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 12:29:15 +00:00
重构了物品系统
This commit is contained in:
@@ -217,8 +217,10 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof ItemDisplay display) {
|
||||
handleBaseEntityLoadEarly(display);
|
||||
} else if (COLLISION_ENTITY_CLASS.isInstance(entity)) {
|
||||
handleCollisionEntityLoadOnEntitiesLoad(entity);
|
||||
} else if (entity instanceof Interaction interaction) {
|
||||
handleCollisionEntityLoadOnEntitiesLoad(interaction);
|
||||
} else if (entity instanceof Boat boat) {
|
||||
handleCollisionEntityLoadOnEntitiesLoad(boat);
|
||||
} else if (entity instanceof Shulker shulker) {
|
||||
// TODO 移除这一行,预计过一个月
|
||||
handleCollisionEntityLoadOnEntitiesLoad(shulker);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.util.MaterialUtils;
|
||||
import net.momirealms.craftengine.core.item.*;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
}
|
||||
|
||||
private static BukkitItemManager instance;
|
||||
private final BukkitItemFactory factory;
|
||||
private final BukkitItemFactory<? extends ItemWrapper<ItemStack>> factory;
|
||||
private final BukkitCraftEngine plugin;
|
||||
private final ItemEventListener itemEventListener;
|
||||
private final DebugStickListener debugStickListener;
|
||||
@@ -143,11 +143,6 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object encodeJava(Key componentType, @Nullable Object component) {
|
||||
return this.factory.encodeJava(componentType, component);
|
||||
}
|
||||
|
||||
public static BukkitItemManager instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import com.saicone.rtag.tag.TagBase;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemWrapper implements ItemWrapper<ItemStack> {
|
||||
private final ItemStack item;
|
||||
|
||||
public ComponentItemWrapper(final ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public ComponentItemWrapper(final ItemStack item, int count) {
|
||||
this.item = item;
|
||||
this.item.setAmount(count);
|
||||
}
|
||||
|
||||
public void resetComponent(Object type) {
|
||||
FastNMS.INSTANCE.resetComponent(this.getLiteralObject(), type);
|
||||
}
|
||||
|
||||
public void setComponent(Object type, final Object value) {
|
||||
if (value instanceof JsonElement jsonElement) {
|
||||
setJsonComponent(type, jsonElement);
|
||||
} else if (TagBase.isTag(value)) {
|
||||
setNBTComponent(type, value);
|
||||
} else {
|
||||
setJavaComponent(type, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getComponent(Object type) {
|
||||
return FastNMS.INSTANCE.getComponent(getLiteralObject(), ensureDataComponentType(type));
|
||||
}
|
||||
|
||||
public boolean hasComponent(Object type) {
|
||||
return FastNMS.INSTANCE.hasComponent(getLiteralObject(), ensureDataComponentType(type));
|
||||
}
|
||||
|
||||
public void setJavaComponent(Object type, Object value) {
|
||||
ComponentType.parseJava(type, value).ifPresent(it -> FastNMS.INSTANCE.setComponent(this.getLiteralObject(), ensureDataComponentType(type), it));
|
||||
}
|
||||
|
||||
public void setJsonComponent(Object type, JsonElement value) {
|
||||
ComponentType.parseJson(type, value).ifPresent(it -> FastNMS.INSTANCE.setComponent(this.getLiteralObject(), ensureDataComponentType(type), it));
|
||||
}
|
||||
|
||||
public void setNBTComponent(Object type, Object value) {
|
||||
ComponentType.parseNbt(type, value).ifPresent(it -> FastNMS.INSTANCE.setComponent(this.getLiteralObject(), ensureDataComponentType(type), it));
|
||||
}
|
||||
|
||||
private Object ensureDataComponentType(Object type) {
|
||||
assert Reflections.clazz$DataComponentType != null;
|
||||
if (!Reflections.clazz$DataComponentType.isInstance(type)) {
|
||||
Key key = Key.of(type.toString());
|
||||
return FastNMS.INSTANCE.getComponentType(key.namespace(), key.value());
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemWrapper<ItemStack> copyWithCount(int count) {
|
||||
ItemStack copied = item.clone();
|
||||
copied.setAmount(count);
|
||||
return new ComponentItemWrapper(copied);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack load() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getLiteralObject() {
|
||||
return FastNMS.INSTANCE.field$CraftItemStack$handle(this.item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count() {
|
||||
return this.item.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void count(int amount) {
|
||||
this.item.setAmount(amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.momirealms.craftengine.bukkit.item;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
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);
|
||||
|
||||
private ComponentTypes() {}
|
||||
|
||||
private static Object getComponentType(Key key) {
|
||||
if (!VersionHelper.isVersionNewerThan1_20_5()) return null;
|
||||
return FastNMS.INSTANCE.getComponentType(key.namespace(), key.value());
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,11 @@ import com.saicone.rtag.RtagItem;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class RTagItemWrapper implements ItemWrapper<ItemStack> {
|
||||
public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
|
||||
private final RtagItem rtagItem;
|
||||
private int count;
|
||||
|
||||
public RTagItemWrapper(RtagItem rtagItem, int count) {
|
||||
public LegacyItemWrapper(RtagItem rtagItem, int count) {
|
||||
this.rtagItem = rtagItem;
|
||||
this.count = count;
|
||||
}
|
||||
@@ -23,67 +20,43 @@ public class RTagItemWrapper implements ItemWrapper<ItemStack> {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set(Object value, Object... path) {
|
||||
return this.rtagItem.set(value, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Object value, Object... path) {
|
||||
return this.rtagItem.add(value, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> V get(Object... path) {
|
||||
return this.rtagItem.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComponent(Object path, Object value) {
|
||||
this.rtagItem.setComponent(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getComponent(Object path) {
|
||||
return this.rtagItem.getComponent(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void count(int amount) {
|
||||
if (amount < 0) amount = 0;
|
||||
this.count = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> V getExact(Object... path) {
|
||||
return this.rtagItem.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeComponent(Object path) {
|
||||
this.rtagItem.removeComponent(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComponent(Object path) {
|
||||
return this.rtagItem.hasComponent(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object... path) {
|
||||
return this.rtagItem.remove(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTag(Object... path) {
|
||||
return this.rtagItem.hasTag(path);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
this.rtagItem.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack load() {
|
||||
ItemStack itemStack = this.rtagItem.load();
|
||||
@@ -98,11 +71,6 @@ public class RTagItemWrapper implements ItemWrapper<ItemStack> {
|
||||
|
||||
@Override
|
||||
public ItemWrapper<ItemStack> copyWithCount(int count) {
|
||||
return new RTagItemWrapper(new RtagItem(this.rtagItem.loadCopy()), count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getData() {
|
||||
return this.rtagItem.get();
|
||||
return new LegacyItemWrapper(new RtagItem(this.rtagItem.loadCopy()), count);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,40 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import net.momirealms.craftengine.bukkit.item.RTagItemWrapper;
|
||||
import com.google.gson.JsonElement;
|
||||
import net.momirealms.craftengine.bukkit.util.ItemTags;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.item.EquipmentData;
|
||||
import net.momirealms.craftengine.core.item.ItemFactory;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.item.modifier.IdModifier;
|
||||
import net.momirealms.craftengine.core.item.JukeboxPlayable;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class BukkitItemFactory extends ItemFactory<CraftEngine, ItemWrapper<ItemStack>, ItemStack> {
|
||||
public abstract class BukkitItemFactory<W extends ItemWrapper<ItemStack>> extends ItemFactory<W, ItemStack> {
|
||||
|
||||
protected BukkitItemFactory(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
public static BukkitItemFactory create(CraftEngine plugin) {
|
||||
public static BukkitItemFactory<? extends ItemWrapper<ItemStack>> create(CraftEngine plugin) {
|
||||
Objects.requireNonNull(plugin, "plugin");
|
||||
switch (plugin.serverVersion()) {
|
||||
case "1.20", "1.20.1", "1.20.2", "1.20.3", "1.20.4" -> {
|
||||
return new UniversalItemFactory(plugin);
|
||||
}
|
||||
case "1.20.5", "1.20.6",
|
||||
"1.21", "1.21.1", "1.21.2", "1.21.3" -> {
|
||||
return new ComponentItemFactory(plugin);
|
||||
case "1.20.5", "1.20.6"-> {
|
||||
return new ComponentItemFactory1_20_5(plugin);
|
||||
}
|
||||
case "1.21", "1.21.1" -> {
|
||||
return new ComponentItemFactory1_21(plugin);
|
||||
}
|
||||
case "1.21.2", "1.21.3" -> {
|
||||
return new ComponentItemFactory1_21_2(plugin);
|
||||
}
|
||||
case "1.21.4" -> {
|
||||
return new ComponentItemFactory1_21_4(plugin);
|
||||
@@ -42,69 +47,32 @@ public abstract class BukkitItemFactory extends ItemFactory<CraftEngine, ItemWra
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Key id(ItemWrapper<ItemStack> item) {
|
||||
Object id = item.get(IdModifier.CRAFT_ENGINE_ID);
|
||||
if (id == null) {
|
||||
NamespacedKey key = item.getItem().getType().getKey();
|
||||
return Key.of(key.getNamespace(), key.getKey());
|
||||
}
|
||||
return Key.of(id.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Key> customId(ItemWrapper<ItemStack> item) {
|
||||
Object id = item.get(IdModifier.CRAFT_ENGINE_ID);
|
||||
if (id == null) return Optional.empty();
|
||||
return Optional.of(Key.of(id.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isBlockItem(ItemWrapper<ItemStack> item) {
|
||||
protected boolean isBlockItem(W item) {
|
||||
return item.getItem().getType().isBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Key vanillaId(ItemWrapper<ItemStack> item) {
|
||||
protected Key vanillaId(W item) {
|
||||
return Key.of(item.getItem().getType().getKey().asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemWrapper<ItemStack> wrapInternal(ItemStack item) {
|
||||
return new RTagItemWrapper(new RtagItem(item), item.getAmount());
|
||||
protected Key id(W item) {
|
||||
return customId(item).orElse(vanillaId(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setTag(ItemWrapper<ItemStack> item, Object value, Object... path) {
|
||||
item.set(value, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getTag(ItemWrapper<ItemStack> item, Object... path) {
|
||||
return item.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasTag(ItemWrapper<ItemStack> item, Object... path) {
|
||||
return item.hasTag(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean removeTag(ItemWrapper<ItemStack> item, Object... path) {
|
||||
return item.remove(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack load(ItemWrapper<ItemStack> item) {
|
||||
protected ItemStack load(W item) {
|
||||
return item.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getItem(ItemWrapper<ItemStack> item) {
|
||||
protected ItemStack getItem(W item) {
|
||||
return item.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean is(ItemWrapper<ItemStack> item, Key itemTag) {
|
||||
protected boolean is(W item, Key itemTag) {
|
||||
Object literalObject = item.getLiteralObject();
|
||||
Object tag = ItemTags.getOrCreate(itemTag);
|
||||
try {
|
||||
@@ -113,4 +81,89 @@ public abstract class BukkitItemFactory extends ItemFactory<CraftEngine, ItemWra
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonElement encodeJson(Object type, Object component) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object encodeJava(Object componentType, @Nullable Object component) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resetComponent(W item, Object type) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setComponent(W item, Object type, Object value) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getComponent(W item, Object type) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasComponent(W item, Object type) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeComponent(W item, Object type) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> tooltipStyle(W item) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.21.2+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tooltipStyle(W item, String data) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.21.2+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<JukeboxPlayable> jukeboxSong(W item) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.21+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void jukeboxSong(W item, JukeboxPlayable data) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.21+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Boolean> glint(W item) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void glint(W item, Boolean glint) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemModel(W item) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.21.2+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemModel(W item, String data) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.21.2+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<EquipmentData> equippable(W item) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.21.2+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void equippable(W item, EquipmentData data) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.21.2+");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,391 +0,0 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import com.saicone.rtag.item.ItemObject;
|
||||
import net.momirealms.craftengine.bukkit.item.RTagItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.EnchantmentUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.Enchantment;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.item.Trim;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory extends BukkitItemFactory {
|
||||
|
||||
public ComponentItemFactory(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setComponent(ItemWrapper<ItemStack> item, Key type, Object value) {
|
||||
if (value instanceof JsonElement jsonElement) {
|
||||
setJsonComponentDirectly(item, type, jsonElement);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, type, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resetComponent(ItemWrapper<ItemStack> item, Key type) {
|
||||
FastNMS.INSTANCE.resetComponent(item.getLiteralObject(), KeyUtils.toResourceLocation(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getComponent(ItemWrapper<ItemStack> item, Key type) {
|
||||
return item.getComponent(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasComponent(ItemWrapper<ItemStack> item, Key type) {
|
||||
return item.hasComponent(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeComponent(ItemWrapper<ItemStack> item, Key type) {
|
||||
FastNMS.INSTANCE.removeComponent(item.getLiteralObject(), KeyUtils.toResourceLocation(type));
|
||||
}
|
||||
|
||||
protected void setJavaComponentDirectly(ItemWrapper<ItemStack> item, Key type, Object value) {
|
||||
ComponentType.parseJava(type, value).ifPresent(it -> FastNMS.INSTANCE.setComponent(item.getLiteralObject(), KeyUtils.toResourceLocation(type), it));
|
||||
}
|
||||
|
||||
protected void setJsonComponentDirectly(ItemWrapper<ItemStack> item, Key type, JsonElement value) {
|
||||
ComponentType.parseJson(type, value).ifPresent(it -> FastNMS.INSTANCE.setComponent(item.getLiteralObject(), KeyUtils.toResourceLocation(type), it));
|
||||
}
|
||||
|
||||
protected void setNBTComponentDirectly(ItemWrapper<ItemStack> item, Key type, Object value) {
|
||||
ComponentType.parseNbt(type, value).ifPresent(it -> FastNMS.INSTANCE.setComponent(item.getLiteralObject(), KeyUtils.toResourceLocation(type), it));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object encodeJava(Key componentType, @Nullable Object component) {
|
||||
return ComponentType.encodeJava(componentType, component).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonElement encodeJson(Key type, Object component) {
|
||||
return ComponentType.encodeJson(type, component).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customModelData(ItemWrapper<ItemStack> item, Integer data) {
|
||||
if (data == null) {
|
||||
resetComponent(item, ComponentKeys.CUSTOM_MODEL_DATA);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.CUSTOM_MODEL_DATA, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.CUSTOM_MODEL_DATA)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(Integer) ComponentType.encodeJava(
|
||||
ComponentKeys.CUSTOM_MODEL_DATA,
|
||||
item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA)
|
||||
).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customName(ItemWrapper<ItemStack> item, String json) {
|
||||
if (json == null) {
|
||||
resetComponent(item, ComponentKeys.CUSTOM_NAME);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.CUSTOM_NAME, json);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> customName(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.CUSTOM_NAME)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(String) ComponentType.encodeJava(
|
||||
ComponentKeys.CUSTOM_NAME,
|
||||
item.getComponent(ComponentKeys.CUSTOM_NAME)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemName(ItemWrapper<ItemStack> item, String json) {
|
||||
if (json == null) {
|
||||
resetComponent(item, ComponentKeys.ITEM_NAME);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.ITEM_NAME, json);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemName(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.ITEM_NAME)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(String) ComponentType.encodeJava(
|
||||
ComponentKeys.ITEM_NAME,
|
||||
item.getComponent(ComponentKeys.ITEM_NAME)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void skull(ItemWrapper<ItemStack> item, String skullData) {
|
||||
if (skullData == null) {
|
||||
resetComponent(item, ComponentKeys.PROFILE);
|
||||
} else {
|
||||
Map<String, Object> profile = Map.of("properties", List.of(Map.of("name", "textures", "value", skullData)));
|
||||
setJavaComponentDirectly(item, ComponentKeys.PROFILE, profile);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Optional<List<String>> lore(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.LORE)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(List<String>) ComponentType.encodeJava(
|
||||
ComponentKeys.LORE,
|
||||
item.getComponent(ComponentKeys.LORE)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void lore(ItemWrapper<ItemStack> item, List<String> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
resetComponent(item, ComponentKeys.LORE);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.LORE, lore);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean unbreakable(ItemWrapper<ItemStack> item) {
|
||||
return item.hasComponent(ComponentKeys.UNBREAKABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unbreakable(ItemWrapper<ItemStack> item, boolean unbreakable) {
|
||||
if (unbreakable) {
|
||||
resetComponent(item, ComponentKeys.UNBREAKABLE);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.UNBREAKABLE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Boolean> glint(ItemWrapper<ItemStack> item) {
|
||||
return Optional.ofNullable((Boolean) item.getComponent(ComponentKeys.ENCHANTMENT_GLINT_OVERRIDE));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void glint(ItemWrapper<ItemStack> item, Boolean glint) {
|
||||
if (glint == null) {
|
||||
resetComponent(item, ComponentKeys.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.ENCHANTMENT_GLINT_OVERRIDE, glint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> damage(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.DAMAGE)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(Integer) ComponentType.encodeJava(
|
||||
ComponentKeys.DAMAGE,
|
||||
item.getComponent(ComponentKeys.DAMAGE)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void damage(ItemWrapper<ItemStack> item, Integer damage) {
|
||||
if (damage == null) {
|
||||
resetComponent(item, ComponentKeys.DAMAGE);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.DAMAGE, damage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> maxDamage(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.MAX_DAMAGE)) return Optional.of((int) item.getItem().getType().getMaxDurability());
|
||||
return Optional.ofNullable(
|
||||
(Integer) ComponentType.encodeJava(
|
||||
ComponentKeys.MAX_DAMAGE,
|
||||
item.getComponent(ComponentKeys.MAX_DAMAGE)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void maxDamage(ItemWrapper<ItemStack> item, Integer damage) {
|
||||
if (damage == null) {
|
||||
resetComponent(item, ComponentKeys.MAX_DAMAGE);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.MAX_DAMAGE, damage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Enchantment> getEnchantment(ItemWrapper<ItemStack> item, Key key) {
|
||||
Object enchant = item.getComponent(ComponentKeys.ENCHANTMENTS);
|
||||
try {
|
||||
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
|
||||
Integer level = map.get(key.toString());
|
||||
if (level == null) return Optional.empty();
|
||||
return Optional.of(new Enchantment(key, level));
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.logger().warn("Failed to get enchantment " + key, e);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enchantments(ItemWrapper<ItemStack> item, List<Enchantment> enchantments) {
|
||||
if (enchantments == null || enchantments.isEmpty()) {
|
||||
resetComponent(item, ComponentKeys.ENCHANTMENTS);
|
||||
} else {
|
||||
Map<String, Integer> enchants = new HashMap<>();
|
||||
for (Enchantment enchantment : enchantments) {
|
||||
enchants.put(enchantment.id().toString(), enchantment.level());
|
||||
}
|
||||
setJavaComponentDirectly(item, ComponentKeys.ENCHANTMENTS, enchants);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storedEnchantments(ItemWrapper<ItemStack> item, List<Enchantment> enchantments) {
|
||||
if (enchantments == null || enchantments.isEmpty()) {
|
||||
resetComponent(item, ComponentKeys.STORED_ENCHANTMENTS);
|
||||
} else {
|
||||
Map<String, Integer> enchants = new HashMap<>();
|
||||
for (Enchantment enchantment : enchantments) {
|
||||
enchants.put(enchantment.id().toString(), enchantment.level());
|
||||
}
|
||||
setJavaComponentDirectly(item, ComponentKeys.STORED_ENCHANTMENTS, enchants);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addEnchantment(ItemWrapper<ItemStack> item, Enchantment enchantment) {
|
||||
Object enchant = item.getComponent(ComponentKeys.ENCHANTMENTS);
|
||||
try {
|
||||
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
|
||||
map.put(enchantment.toString(), enchantment.level());
|
||||
setJavaComponentDirectly(item, ComponentKeys.ENCHANTMENTS, map);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.logger().warn("Failed to add enchantment", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addStoredEnchantment(ItemWrapper<ItemStack> item, Enchantment enchantment) {
|
||||
Object enchant = item.getComponent(ComponentKeys.STORED_ENCHANTMENTS);
|
||||
try {
|
||||
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
|
||||
map.put(enchantment.toString(), enchantment.level());
|
||||
setJavaComponentDirectly(item, ComponentKeys.STORED_ENCHANTMENTS, map);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.logger().warn("Failed to add stored enchantment", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemFlags(ItemWrapper<ItemStack> item, List<String> flags) {
|
||||
throw new UnsupportedOperationException("This feature is not available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int maxStackSize(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.MAX_STACK_SIZE)) return item.getItem().getType().getMaxStackSize();
|
||||
return Optional.ofNullable((Integer) ComponentType.encodeJava(ComponentKeys.MAX_STACK_SIZE, item.getComponent(ComponentKeys.MAX_STACK_SIZE)).orElse(null))
|
||||
.orElse(item.getItem().getType().getMaxStackSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void maxStackSize(ItemWrapper<ItemStack> item, Integer maxStackSize) {
|
||||
if (maxStackSize == null) {
|
||||
resetComponent(item, ComponentKeys.MAX_STACK_SIZE);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.MAX_STACK_SIZE, maxStackSize);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repairCost(ItemWrapper<ItemStack> item, Integer data) {
|
||||
if (data == null) {
|
||||
resetComponent(item, ComponentKeys.REPAIR_COST);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.REPAIR_COST, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> repairCost(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.REPAIR_COST)) return Optional.empty();
|
||||
return Optional.ofNullable((Integer) ComponentType.encodeJava(ComponentKeys.REPAIR_COST, item.getComponent(ComponentKeys.REPAIR_COST)).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void trim(ItemWrapper<ItemStack> item, Trim trim) {
|
||||
if (trim == null) {
|
||||
resetComponent(item, ComponentKeys.TRIM);
|
||||
} else {
|
||||
setJavaComponentDirectly(item, ComponentKeys.TRIM, Map.of(
|
||||
"pattern", trim.pattern(),
|
||||
"material", trim.material()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Trim> trim(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.TRIM)) return Optional.empty();
|
||||
Optional<Object> trim = ComponentType.encodeJava(ComponentKeys.TRIM, item.getComponent(ComponentKeys.TRIM));
|
||||
if (trim.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> trimMap = (Map<String, String>) trim.get();
|
||||
return Optional.of(new Trim(trimMap.get("pattern"), trimMap.get("material")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemWrapper<ItemStack> mergeCopy(ItemWrapper<ItemStack> item1, ItemWrapper<ItemStack> item2) {
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = item2.getLiteralObject();
|
||||
try {
|
||||
Object itemStack3 = FastNMS.INSTANCE.method$ItemStack$transmuteCopy(itemStack1, itemStack2);
|
||||
FastNMS.INSTANCE.method$ItemStack$applyComponents(itemStack3, FastNMS.INSTANCE.method$ItemStack$getComponentsPatch(itemStack2));
|
||||
return new RTagItemWrapper(new RtagItem(ItemObject.asCraftMirror(itemStack3)), item2.count());
|
||||
} catch (Exception e) {
|
||||
this.plugin.logger().warn("Failed to merge item", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void merge(ItemWrapper<ItemStack> item1, ItemWrapper<ItemStack> item2) {
|
||||
// load previous changes on nms items
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = item2.getLiteralObject();
|
||||
try {
|
||||
FastNMS.INSTANCE.method$ItemStack$applyComponents(itemStack1, FastNMS.INSTANCE.method$ItemStack$getComponentsPatch(itemStack2));
|
||||
} catch (Exception e) {
|
||||
plugin.logger().warn("Failed to merge item", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import com.saicone.rtag.item.ItemObject;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.EnchantmentUtils;
|
||||
import net.momirealms.craftengine.core.item.Enchantment;
|
||||
import net.momirealms.craftengine.core.item.Trim;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemWrapper> {
|
||||
|
||||
public ComponentItemFactory1_20_5(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customId(ComponentItemWrapper item, Key id) {
|
||||
FastNMS.INSTANCE.setCustomItemId(item.getLiteralObject(), id.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Key> customId(ComponentItemWrapper item) {
|
||||
return Optional.ofNullable(FastNMS.INSTANCE.getCustomItemId(item.getLiteralObject())).map(Key::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentItemWrapper wrapInternal(ItemStack item) {
|
||||
return new ComponentItemWrapper(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getTag(ComponentItemWrapper item, Object... path) {
|
||||
throw new UnsupportedOperationException("This feature is not available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setTag(ComponentItemWrapper item, Object value, Object... path) {
|
||||
throw new UnsupportedOperationException("This feature is not available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasTag(ComponentItemWrapper item, Object... path) {
|
||||
throw new UnsupportedOperationException("This feature is not available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean removeTag(ComponentItemWrapper item, Object... path) {
|
||||
throw new UnsupportedOperationException("This feature is not available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> tooltipStyle(ComponentItemWrapper item) {
|
||||
throw new UnsupportedOperationException("This feature is not available on 1.21.2+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tooltipStyle(ComponentItemWrapper item, String data) {
|
||||
throw new UnsupportedOperationException("This feature is not available on 1.21.2+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setComponent(ComponentItemWrapper item, Object type, Object value) {
|
||||
item.setComponent(type, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resetComponent(ComponentItemWrapper item, Object type) {
|
||||
item.resetComponent(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getComponent(ComponentItemWrapper item, Object type) {
|
||||
return item.getComponent(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasComponent(ComponentItemWrapper item, Object type) {
|
||||
return item.hasComponent(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeComponent(ComponentItemWrapper item, Object type) {
|
||||
item.resetComponent(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object encodeJava(Object componentType, @Nullable Object component) {
|
||||
return ComponentType.encodeJava(componentType, component).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonElement encodeJson(Object type, Object component) {
|
||||
return ComponentType.encodeJson(type, component).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customModelData(ComponentItemWrapper item, Integer data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.CUSTOM_MODEL_DATA);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.CUSTOM_MODEL_DATA, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.CUSTOM_MODEL_DATA)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(Integer) ComponentType.encodeJava(
|
||||
ComponentTypes.CUSTOM_MODEL_DATA,
|
||||
item.getComponent(ComponentTypes.CUSTOM_MODEL_DATA)
|
||||
).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customName(ComponentItemWrapper item, String json) {
|
||||
if (json == null) {
|
||||
item.resetComponent(ComponentTypes.CUSTOM_NAME);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.CUSTOM_NAME, json);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> customName(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.CUSTOM_NAME)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(String) ComponentType.encodeJava(
|
||||
ComponentTypes.CUSTOM_NAME,
|
||||
item.getComponent(ComponentTypes.CUSTOM_NAME)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemName(ComponentItemWrapper item, String json) {
|
||||
if (json == null) {
|
||||
item.resetComponent(ComponentTypes.ITEM_NAME);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.ITEM_NAME, json);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemName(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.ITEM_NAME)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(String) ComponentType.encodeJava(
|
||||
ComponentTypes.ITEM_NAME,
|
||||
item.getComponent(ComponentTypes.ITEM_NAME)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void skull(ComponentItemWrapper item, String skullData) {
|
||||
if (skullData == null) {
|
||||
item.resetComponent(ComponentTypes.PROFILE);
|
||||
} else {
|
||||
Map<String, Object> profile = Map.of("properties", List.of(Map.of("name", "textures", "value", skullData)));
|
||||
item.setJavaComponent(ComponentTypes.PROFILE, profile);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Optional<List<String>> lore(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.LORE)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(List<String>) ComponentType.encodeJava(
|
||||
ComponentTypes.LORE,
|
||||
item.getComponent(ComponentTypes.LORE)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void lore(ComponentItemWrapper item, List<String> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
item.resetComponent(ComponentTypes.LORE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.LORE, lore);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean unbreakable(ComponentItemWrapper item) {
|
||||
return item.hasComponent(ComponentTypes.UNBREAKABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unbreakable(ComponentItemWrapper item, boolean unbreakable) {
|
||||
if (unbreakable) {
|
||||
item.resetComponent(ComponentTypes.UNBREAKABLE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.UNBREAKABLE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Boolean> glint(ComponentItemWrapper item) {
|
||||
return Optional.ofNullable((Boolean) item.getComponent(ComponentTypes.ENCHANTMENT_GLINT_OVERRIDE));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void glint(ComponentItemWrapper item, Boolean glint) {
|
||||
if (glint == null) {
|
||||
item.resetComponent(ComponentTypes.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, glint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> damage(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.DAMAGE)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(Integer) ComponentType.encodeJava(
|
||||
ComponentTypes.DAMAGE,
|
||||
item.getComponent(ComponentTypes.DAMAGE)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void damage(ComponentItemWrapper item, Integer damage) {
|
||||
if (damage == null) {
|
||||
item.resetComponent(ComponentTypes.DAMAGE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.DAMAGE, damage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> maxDamage(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.MAX_DAMAGE)) return Optional.of((int) item.getItem().getType().getMaxDurability());
|
||||
return Optional.ofNullable(
|
||||
(Integer) ComponentType.encodeJava(
|
||||
ComponentTypes.MAX_DAMAGE,
|
||||
item.getComponent(ComponentTypes.MAX_DAMAGE)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void maxDamage(ComponentItemWrapper item, Integer damage) {
|
||||
if (damage == null) {
|
||||
item.resetComponent(ComponentTypes.MAX_DAMAGE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.MAX_DAMAGE, damage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Enchantment> getEnchantment(ComponentItemWrapper item, Key key) {
|
||||
Object enchant = item.getComponent(ComponentTypes.ENCHANTMENTS);
|
||||
try {
|
||||
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
|
||||
Integer level = map.get(key.toString());
|
||||
if (level == null) return Optional.empty();
|
||||
return Optional.of(new Enchantment(key, level));
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.logger().warn("Failed to get enchantment " + key, e);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enchantments(ComponentItemWrapper item, List<Enchantment> enchantments) {
|
||||
if (enchantments == null || enchantments.isEmpty()) {
|
||||
item.resetComponent(ComponentTypes.ENCHANTMENTS);
|
||||
} else {
|
||||
Map<String, Integer> enchants = new HashMap<>();
|
||||
for (Enchantment enchantment : enchantments) {
|
||||
enchants.put(enchantment.id().toString(), enchantment.level());
|
||||
}
|
||||
item.setJavaComponent(ComponentTypes.ENCHANTMENTS, enchants);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storedEnchantments(ComponentItemWrapper item, List<Enchantment> enchantments) {
|
||||
if (enchantments == null || enchantments.isEmpty()) {
|
||||
item.resetComponent(ComponentTypes.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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addEnchantment(ComponentItemWrapper item, Enchantment enchantment) {
|
||||
Object enchant = item.getComponent(ComponentTypes.ENCHANTMENTS);
|
||||
try {
|
||||
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
|
||||
map.put(enchantment.toString(), enchantment.level());
|
||||
item.setJavaComponent(ComponentTypes.ENCHANTMENTS, map);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.logger().warn("Failed to add enchantment", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addStoredEnchantment(ComponentItemWrapper item, Enchantment enchantment) {
|
||||
Object enchant = item.getComponent(ComponentTypes.STORED_ENCHANTMENTS);
|
||||
try {
|
||||
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
|
||||
map.put(enchantment.toString(), enchantment.level());
|
||||
item.setJavaComponent(ComponentTypes.STORED_ENCHANTMENTS, map);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.logger().warn("Failed to add stored enchantment", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemFlags(ComponentItemWrapper item, List<String> flags) {
|
||||
throw new UnsupportedOperationException("This feature is not available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int maxStackSize(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.MAX_STACK_SIZE)) return item.getItem().getType().getMaxStackSize();
|
||||
return Optional.ofNullable((Integer) ComponentType.encodeJava(ComponentTypes.MAX_STACK_SIZE, item.getComponent(ComponentTypes.MAX_STACK_SIZE)).orElse(null))
|
||||
.orElse(item.getItem().getType().getMaxStackSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void maxStackSize(ComponentItemWrapper item, Integer maxStackSize) {
|
||||
if (maxStackSize == null) {
|
||||
item.resetComponent(ComponentTypes.MAX_STACK_SIZE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.MAX_STACK_SIZE, maxStackSize);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repairCost(ComponentItemWrapper item, Integer data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.REPAIR_COST);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.REPAIR_COST, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> repairCost(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.REPAIR_COST)) return Optional.empty();
|
||||
return Optional.ofNullable((Integer) ComponentType.encodeJava(ComponentTypes.REPAIR_COST, item.getComponent(ComponentTypes.REPAIR_COST)).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void trim(ComponentItemWrapper item, Trim trim) {
|
||||
if (trim == null) {
|
||||
item.resetComponent(ComponentTypes.TRIM);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.TRIM, Map.of(
|
||||
"pattern", trim.pattern(),
|
||||
"material", trim.material()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Trim> trim(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.TRIM)) return Optional.empty();
|
||||
Optional<Object> trim = ComponentType.encodeJava(ComponentTypes.TRIM, item.getComponent(ComponentTypes.TRIM));
|
||||
if (trim.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> trimMap = (Map<String, String>) trim.get();
|
||||
return Optional.of(new Trim(trimMap.get("pattern"), trimMap.get("material")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentItemWrapper mergeCopy(ComponentItemWrapper item1, ComponentItemWrapper item2) {
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = item2.getLiteralObject();
|
||||
Object itemStack3 = FastNMS.INSTANCE.method$ItemStack$transmuteCopy(itemStack1, itemStack2);
|
||||
FastNMS.INSTANCE.method$ItemStack$applyComponents(itemStack3, FastNMS.INSTANCE.method$ItemStack$getComponentsPatch(itemStack2));
|
||||
return new ComponentItemWrapper(ItemObject.asCraftMirror(itemStack3), item2.count());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void merge(ComponentItemWrapper item1, ComponentItemWrapper item2) {
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = item2.getLiteralObject();
|
||||
try {
|
||||
FastNMS.INSTANCE.method$ItemStack$applyComponents(itemStack1, FastNMS.INSTANCE.method$ItemStack$getComponentsPatch(itemStack2));
|
||||
} catch (Exception e) {
|
||||
plugin.logger().warn("Failed to merge item", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.core.item.JukeboxPlayable;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory1_21 extends ComponentItemFactory1_20_5 {
|
||||
|
||||
public ComponentItemFactory1_21(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<JukeboxPlayable> jukeboxSong(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.JUKEBOX_PLAYABLE)) return Optional.empty();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) ComponentType.encodeJava(
|
||||
ComponentTypes.JUKEBOX_PLAYABLE,
|
||||
item.getComponent(ComponentTypes.JUKEBOX_PLAYABLE)
|
||||
).orElse(null);
|
||||
if (map == null) return Optional.empty();
|
||||
return Optional.of(new JukeboxPlayable((String) map.get("song"), (boolean) map.getOrDefault("show_in_tooltip", true)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void jukeboxSong(ComponentItemWrapper item, JukeboxPlayable data) {
|
||||
item.setJavaComponent(ComponentTypes.JUKEBOX_PLAYABLE, Map.of(
|
||||
"song", data.song(),
|
||||
"show_in_tooltip", true
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.core.item.EquipmentData;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory1_21_2 extends ComponentItemFactory1_21 {
|
||||
|
||||
public ComponentItemFactory1_21_2(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tooltipStyle(ComponentItemWrapper item, String data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.TOOLTIP_STYLE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.TOOLTIP_STYLE, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> tooltipStyle(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.TOOLTIP_STYLE)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(String) ComponentType.encodeJava(
|
||||
ComponentTypes.TOOLTIP_STYLE,
|
||||
item.getComponent(ComponentTypes.TOOLTIP_STYLE)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemModel(ComponentItemWrapper item, String data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.ITEM_MODEL);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.ITEM_MODEL, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemModel(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.ITEM_MODEL)) return Optional.empty();
|
||||
return Optional.ofNullable(
|
||||
(String) ComponentType.encodeJava(
|
||||
ComponentTypes.ITEM_MODEL,
|
||||
item.getComponent(ComponentTypes.ITEM_MODEL)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void equippable(ComponentItemWrapper item, EquipmentData data) {
|
||||
if (data == null) {
|
||||
item.resetComponent(ComponentTypes.EQUIPPABLE);
|
||||
} else {
|
||||
item.setJavaComponent(ComponentTypes.EQUIPPABLE, data.toMap());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<EquipmentData> equippable(ComponentItemWrapper item) {
|
||||
throw new UnsupportedOperationException("Not implemented yet.");
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,25 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory1_21_4 extends ComponentItemFactory {
|
||||
public class ComponentItemFactory1_21_4 extends ComponentItemFactory1_21_2 {
|
||||
|
||||
public ComponentItemFactory1_21_4(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.CUSTOM_MODEL_DATA)) return Optional.empty();
|
||||
Optional<Object> optional = ComponentType.encodeJava(ComponentKeys.CUSTOM_MODEL_DATA, item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA));
|
||||
protected Optional<Integer> customModelData(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.CUSTOM_MODEL_DATA)) return Optional.empty();
|
||||
Optional<Object> optional = ComponentType.encodeJava(ComponentTypes.CUSTOM_MODEL_DATA, item.getComponent(ComponentTypes.CUSTOM_MODEL_DATA));
|
||||
if (optional.isEmpty()) return Optional.empty();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) optional.get();
|
||||
@@ -31,11 +30,11 @@ public class ComponentItemFactory1_21_4 extends ComponentItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customModelData(ItemWrapper<ItemStack> item, Integer data) {
|
||||
protected void customModelData(ComponentItemWrapper item, Integer data) {
|
||||
if (data == null) {
|
||||
resetComponent(item, ComponentKeys.CUSTOM_MODEL_DATA);
|
||||
item.resetComponent(ComponentTypes.CUSTOM_MODEL_DATA);
|
||||
} else {
|
||||
setComponent(item, ComponentKeys.CUSTOM_MODEL_DATA, Map.of("floats", List.of(data.floatValue())));
|
||||
item.setJavaComponent(ComponentTypes.CUSTOM_MODEL_DATA, Map.of("floats", List.of(data.floatValue())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import com.google.gson.JsonElement;
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import com.saicone.rtag.tag.TagList;
|
||||
import com.saicone.rtag.util.ChatComponent;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.item.JukeboxPlayable;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.GsonHelper;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -24,41 +24,41 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customName(ItemWrapper<ItemStack> item, String json) {
|
||||
protected void customName(ComponentItemWrapper item, String json) {
|
||||
if (json == null) {
|
||||
resetComponent(item, ComponentKeys.CUSTOM_NAME);
|
||||
item.resetComponent(ComponentTypes.CUSTOM_NAME);
|
||||
} else {
|
||||
setNBTComponentDirectly(item, ComponentKeys.CUSTOM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
|
||||
item.setNBTComponent(ComponentTypes.CUSTOM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> customName(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.CUSTOM_NAME)) return Optional.empty();
|
||||
return ComponentType.encodeJson(ComponentKeys.CUSTOM_NAME, item.getComponent(ComponentKeys.CUSTOM_NAME)).map(jsonElement -> GsonHelper.get().toJson(jsonElement));
|
||||
protected Optional<String> customName(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.CUSTOM_NAME)) return Optional.empty();
|
||||
return ComponentType.encodeJson(ComponentTypes.CUSTOM_NAME, item.getComponent(ComponentTypes.CUSTOM_NAME)).map(jsonElement -> GsonHelper.get().toJson(jsonElement));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemName(ItemWrapper<ItemStack> item, String json) {
|
||||
protected void itemName(ComponentItemWrapper item, String json) {
|
||||
if (json == null) {
|
||||
resetComponent(item, ComponentKeys.ITEM_NAME);
|
||||
item.resetComponent(ComponentTypes.ITEM_NAME);
|
||||
} else {
|
||||
setNBTComponentDirectly(item, ComponentKeys.ITEM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
|
||||
item.setNBTComponent(ComponentTypes.ITEM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemName(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.ITEM_NAME)) return Optional.empty();
|
||||
return ComponentType.encodeJson(ComponentKeys.ITEM_NAME, item.getComponent(ComponentKeys.ITEM_NAME)).map(jsonElement -> GsonHelper.get().toJson(jsonElement));
|
||||
protected Optional<String> itemName(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.ITEM_NAME)) return Optional.empty();
|
||||
return ComponentType.encodeJson(ComponentTypes.ITEM_NAME, item.getComponent(ComponentTypes.ITEM_NAME)).map(jsonElement -> GsonHelper.get().toJson(jsonElement));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<List<String>> lore(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.LORE)) return Optional.empty();
|
||||
protected Optional<List<String>> lore(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.LORE)) return Optional.empty();
|
||||
return ComponentType.encodeJson(
|
||||
ComponentKeys.LORE,
|
||||
item.getComponent(ComponentKeys.LORE)
|
||||
ComponentTypes.LORE,
|
||||
item.getComponent(ComponentTypes.LORE)
|
||||
).map(list -> {
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (JsonElement jsonElement : (JsonArray) list) {
|
||||
@@ -69,15 +69,30 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void lore(ItemWrapper<ItemStack> item, List<String> lore) {
|
||||
protected void lore(ComponentItemWrapper item, List<String> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
resetComponent(item, ComponentKeys.LORE);
|
||||
item.resetComponent(ComponentTypes.LORE);
|
||||
} else {
|
||||
List<Object> loreTags = new ArrayList<>();
|
||||
for (String json : lore) {
|
||||
loreTags.add(ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
|
||||
}
|
||||
setNBTComponentDirectly(item, ComponentKeys.LORE, TagList.newTag(loreTags));
|
||||
item.setNBTComponent(ComponentTypes.LORE, TagList.newTag(loreTags));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<JukeboxPlayable> jukeboxSong(ComponentItemWrapper item) {
|
||||
if (!item.hasComponent(ComponentTypes.JUKEBOX_PLAYABLE)) return Optional.empty();
|
||||
String song = (String) ComponentType.encodeJava(
|
||||
ComponentTypes.JUKEBOX_PLAYABLE,
|
||||
item.getComponent(ComponentTypes.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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.saicone.rtag.RtagItem;
|
||||
import com.saicone.rtag.item.ItemObject;
|
||||
import com.saicone.rtag.tag.TagBase;
|
||||
import com.saicone.rtag.tag.TagCompound;
|
||||
import com.saicone.rtag.tag.TagList;
|
||||
import net.momirealms.craftengine.bukkit.item.RTagItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.LegacyItemWrapper;
|
||||
import net.momirealms.craftengine.core.item.Enchantment;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.item.Trim;
|
||||
import net.momirealms.craftengine.core.item.modifier.IdModifier;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.SkullUtils;
|
||||
@@ -17,54 +16,55 @@ import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
public class UniversalItemFactory extends BukkitItemFactory {
|
||||
public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
|
||||
|
||||
public UniversalItemFactory(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resetComponent(ItemWrapper<ItemStack> item, Key type) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
protected LegacyItemWrapper wrapInternal(ItemStack item) {
|
||||
return new LegacyItemWrapper(new RtagItem(item), item.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonElement encodeJson(Key type, Object component) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
protected void setTag(LegacyItemWrapper item, Object value, Object... path) {
|
||||
item.set(value, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setComponent(ItemWrapper<ItemStack> item, Key type, Object value) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
protected Object getTag(LegacyItemWrapper item, Object... path) {
|
||||
return item.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getComponent(ItemWrapper<ItemStack> item, Key type) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
protected boolean hasTag(LegacyItemWrapper item, Object... path) {
|
||||
return item.hasTag(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasComponent(ItemWrapper<ItemStack> item, Key type) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
protected boolean removeTag(LegacyItemWrapper item, Object... path) {
|
||||
return item.remove(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeComponent(ItemWrapper<ItemStack> item, Key type) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
protected Optional<Key> customId(LegacyItemWrapper item) {
|
||||
Object id = item.get(IdModifier.CRAFT_ENGINE_ID);
|
||||
if (id == null) return Optional.empty();
|
||||
return Optional.of(Key.of(id.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object encodeJava(Key componentType, @Nullable Object component) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
protected void customId(LegacyItemWrapper item, Key id) {
|
||||
item.set(id.toString(), IdModifier.CRAFT_ENGINE_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customName(ItemWrapper<ItemStack> item, String json) {
|
||||
protected void customName(LegacyItemWrapper item, String json) {
|
||||
if (json != null) {
|
||||
item.set(json, "display", "Name");
|
||||
} else {
|
||||
@@ -73,23 +73,23 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> customName(ItemWrapper<ItemStack> item) {
|
||||
protected Optional<String> customName(LegacyItemWrapper item) {
|
||||
if (!item.hasTag("display", "Name")) return Optional.empty();
|
||||
return Optional.of(item.get("display", "Name"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemName(ItemWrapper<ItemStack> item, String json) {
|
||||
protected void itemName(LegacyItemWrapper item, String json) {
|
||||
customName(item, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemName(ItemWrapper<ItemStack> item) {
|
||||
protected Optional<String> itemName(LegacyItemWrapper item) {
|
||||
return customName(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customModelData(ItemWrapper<ItemStack> item, Integer data) {
|
||||
protected void customModelData(LegacyItemWrapper item, Integer data) {
|
||||
if (data == null) {
|
||||
item.remove("CustomModelData");
|
||||
} else {
|
||||
@@ -98,13 +98,13 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(ItemWrapper<ItemStack> item) {
|
||||
protected Optional<Integer> customModelData(LegacyItemWrapper item) {
|
||||
if (!item.hasTag("CustomModelData")) return Optional.empty();
|
||||
return Optional.of(item.get("CustomModelData"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void skull(ItemWrapper<ItemStack> item, String skullData) {
|
||||
protected void skull(LegacyItemWrapper item, String skullData) {
|
||||
if (skullData == null) {
|
||||
item.remove("SkullOwner");
|
||||
} else {
|
||||
@@ -117,13 +117,13 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<List<String>> lore(ItemWrapper<ItemStack> item) {
|
||||
protected Optional<List<String>> lore(LegacyItemWrapper item) {
|
||||
if (!item.hasTag("display", "Lore")) return Optional.empty();
|
||||
return Optional.of(item.get("display", "Lore"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void lore(ItemWrapper<ItemStack> item, List<String> lore) {
|
||||
protected void lore(LegacyItemWrapper item, List<String> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
item.remove("display", "Lore");
|
||||
} else {
|
||||
@@ -132,48 +132,38 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean unbreakable(ItemWrapper<ItemStack> item) {
|
||||
protected boolean unbreakable(LegacyItemWrapper item) {
|
||||
return Optional.ofNullable((Boolean) item.get("Unbreakable")).orElse(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unbreakable(ItemWrapper<ItemStack> item, boolean unbreakable) {
|
||||
protected void unbreakable(LegacyItemWrapper item, boolean unbreakable) {
|
||||
item.set(unbreakable, "Unbreakable");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Boolean> glint(ItemWrapper<ItemStack> item) {
|
||||
return Optional.of(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void glint(ItemWrapper<ItemStack> item, Boolean glint) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> damage(ItemWrapper<ItemStack> item) {
|
||||
protected Optional<Integer> damage(LegacyItemWrapper item) {
|
||||
if (!item.hasTag("Damage")) return Optional.empty();
|
||||
return Optional.of(item.get("Damage"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void damage(ItemWrapper<ItemStack> item, Integer damage) {
|
||||
protected void damage(LegacyItemWrapper item, Integer damage) {
|
||||
item.set(damage, "Damage");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> maxDamage(ItemWrapper<ItemStack> item) {
|
||||
protected Optional<Integer> maxDamage(LegacyItemWrapper item) {
|
||||
return Optional.of((int) item.getItem().getType().getMaxDurability());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void maxDamage(ItemWrapper<ItemStack> item, Integer damage) {
|
||||
protected void maxDamage(LegacyItemWrapper item, Integer damage) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enchantments(ItemWrapper<ItemStack> item, List<Enchantment> enchantments) {
|
||||
protected void enchantments(LegacyItemWrapper item, List<Enchantment> enchantments) {
|
||||
if (enchantments == null || enchantments.isEmpty()) {
|
||||
item.remove("Enchantments");
|
||||
return;
|
||||
@@ -186,7 +176,7 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storedEnchantments(ItemWrapper<ItemStack> item, List<Enchantment> enchantments) {
|
||||
protected void storedEnchantments(LegacyItemWrapper item, List<Enchantment> enchantments) {
|
||||
if (enchantments == null || enchantments.isEmpty()) {
|
||||
item.remove("StoredEnchantments");
|
||||
return;
|
||||
@@ -199,7 +189,7 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addEnchantment(ItemWrapper<ItemStack> item, Enchantment enchantment) {
|
||||
protected void addEnchantment(LegacyItemWrapper item, Enchantment enchantment) {
|
||||
Object enchantments = item.getExact("Enchantments");
|
||||
if (enchantments != null) {
|
||||
for (Object enchant : TagList.getValue(enchantments)) {
|
||||
@@ -215,7 +205,7 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addStoredEnchantment(ItemWrapper<ItemStack> item, Enchantment enchantment) {
|
||||
protected void addStoredEnchantment(LegacyItemWrapper item, Enchantment enchantment) {
|
||||
Object enchantments = item.getExact("StoredEnchantments");
|
||||
if (enchantments != null) {
|
||||
for (Object enchant : TagList.getValue(enchantments)) {
|
||||
@@ -232,14 +222,14 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected Optional<Enchantment> getEnchantment(ItemWrapper<ItemStack> item, Key key) {
|
||||
protected Optional<Enchantment> getEnchantment(LegacyItemWrapper item, Key key) {
|
||||
int level = item.getItem().getEnchantmentLevel(Objects.requireNonNull(Registry.ENCHANTMENT.get(new NamespacedKey(key.namespace(), key.value()))));
|
||||
if (level <= 0) return Optional.empty();
|
||||
return Optional.of(new Enchantment(key, level));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemFlags(ItemWrapper<ItemStack> item, List<String> flags) {
|
||||
protected void itemFlags(LegacyItemWrapper item, List<String> flags) {
|
||||
if (flags == null || flags.isEmpty()) {
|
||||
item.remove("HideFlags");
|
||||
return;
|
||||
@@ -253,44 +243,28 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int maxStackSize(ItemWrapper<ItemStack> item) {
|
||||
protected int maxStackSize(LegacyItemWrapper item) {
|
||||
return item.getItem().getType().getMaxStackSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void maxStackSize(ItemWrapper<ItemStack> item, Integer maxStackSize) {
|
||||
protected void maxStackSize(LegacyItemWrapper item, Integer maxStackSize) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repairCost(ItemWrapper<ItemStack> item, Integer data) {
|
||||
protected void repairCost(LegacyItemWrapper item, Integer data) {
|
||||
item.set(data, "RepairCost");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> repairCost(ItemWrapper<ItemStack> item) {
|
||||
protected Optional<Integer> repairCost(LegacyItemWrapper item) {
|
||||
if (!item.hasTag("RepairCost")) return Optional.empty();
|
||||
return Optional.of(item.get("RepairCost"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemWrapper<ItemStack> mergeCopy(ItemWrapper<ItemStack> item1, ItemWrapper<ItemStack> item2) {
|
||||
Object itemStack = ItemObject.copy(item2.getLiteralObject());
|
||||
ItemObject.setCustomDataTag(itemStack, TagCompound.clone(ItemObject.getCustomDataTag(item1.getLiteralObject())));
|
||||
// one more step than vanilla
|
||||
TagCompound.merge(ItemObject.getCustomDataTag(itemStack), ItemObject.getCustomDataTag(item2.getLiteralObject()), true, true);
|
||||
return new RTagItemWrapper(new RtagItem(ItemObject.asCraftMirror(itemStack)), item2.count());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void merge(ItemWrapper<ItemStack> item1, ItemWrapper<ItemStack> item2) {
|
||||
// load previous changes on nms items
|
||||
item1.load();
|
||||
TagCompound.merge(ItemObject.getCustomDataTag(item1.getLiteralObject()), ItemObject.getCustomDataTag(item2.getLiteralObject()), true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void trim(ItemWrapper<ItemStack> item, Trim trim) {
|
||||
protected void trim(LegacyItemWrapper item, Trim trim) {
|
||||
if (trim == null) {
|
||||
item.remove("Trim");
|
||||
return;
|
||||
@@ -300,10 +274,28 @@ public class UniversalItemFactory extends BukkitItemFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Trim> trim(ItemWrapper<ItemStack> item) {
|
||||
protected Optional<Trim> trim(LegacyItemWrapper item) {
|
||||
String material = item.get("Trim", "material");
|
||||
String pattern = item.get("Trim", "pattern");
|
||||
if (material == null || pattern == null) return Optional.empty();
|
||||
return Optional.of(new Trim(material, pattern));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LegacyItemWrapper mergeCopy(LegacyItemWrapper item1, LegacyItemWrapper item2) {
|
||||
Object itemStack = ItemObject.copy(item2.getLiteralObject());
|
||||
ItemObject.setCustomDataTag(itemStack, TagCompound.clone(ItemObject.getCustomDataTag(item1.getLiteralObject())));
|
||||
// one more step than vanilla
|
||||
TagCompound.merge(ItemObject.getCustomDataTag(itemStack), ItemObject.getCustomDataTag(item2.getLiteralObject()), true, true);
|
||||
return new LegacyItemWrapper(new RtagItem(ItemObject.asCraftMirror(itemStack)), item2.count());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void merge(LegacyItemWrapper item1, LegacyItemWrapper item2) {
|
||||
// load previous changes on nms items
|
||||
item1.load();
|
||||
TagCompound.merge(ItemObject.getCustomDataTag(item1.getLiteralObject()), ItemObject.getCustomDataTag(item2.getLiteralObject()), true, true);
|
||||
// update wrapped item
|
||||
item1.update();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.bukkit.item.recipe;
|
||||
import com.destroystokyo.paper.event.inventory.PrepareResultEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector;
|
||||
@@ -587,7 +588,7 @@ public class RecipeEventListener implements Listener {
|
||||
} catch (ReflectiveOperationException e) {
|
||||
plugin.logger().warn("Failed to get hover name", e);
|
||||
}
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_5() && wrappedFirst.hasComponent(ComponentKeys.CUSTOM_NAME)) {
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_5() && wrappedFirst.hasComponent(ComponentTypes.CUSTOM_NAME)) {
|
||||
repairCost += 1;
|
||||
wrappedFirst.customName(null);
|
||||
} else if (!VersionHelper.isVersionNewerThan1_20_5() && wrappedFirst.hasTag("display", "Name")) {
|
||||
|
||||
@@ -6515,4 +6515,10 @@ public class Reflections {
|
||||
? ReflectionUtils.getConstructor(clazz$ServerboundResourcePackPacket, UUID.class, clazz$ServerboundResourcePackPacket$Action)
|
||||
: ReflectionUtils.getConstructor(clazz$ServerboundResourcePackPacket, clazz$ServerboundResourcePackPacket$Action)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$DataComponentType = ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass(
|
||||
"core.component.DataComponentType"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,14 +8,58 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
|
||||
private final ItemFactory<?, W, I> factory;
|
||||
private final ItemWrapper<I> item;
|
||||
private final ItemFactory<W, I> factory;
|
||||
private final W item;
|
||||
|
||||
AbstractItem(ItemFactory<?, W, I> factory, ItemWrapper<I> item) {
|
||||
AbstractItem(ItemFactory<W, I> factory, W item) {
|
||||
this.factory = factory;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item<I> itemModel(String data) {
|
||||
this.factory.itemModel(this.item, data);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> itemModel() {
|
||||
return this.factory.itemModel(this.item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<JukeboxPlayable> jukeboxSong() {
|
||||
return this.factory.jukeboxSong(this.item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item<I> jukeboxSong(JukeboxPlayable data) {
|
||||
this.factory.jukeboxSong(this.item, data);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EquipmentData> equippable() {
|
||||
return this.factory.equippable(this.item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item<I> equippable(EquipmentData data) {
|
||||
this.factory.equippable(this.item, data);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item<I> tooltipStyle(String data) {
|
||||
this.factory.tooltipStyle(this.item, data);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> tooltipStyle() {
|
||||
return this.factory.tooltipStyle(this.item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item<I> damage(Integer data) {
|
||||
this.factory.damage(this.item, data);
|
||||
@@ -85,6 +129,12 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
|
||||
return this.factory.customId(this.item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item<I> customId(Key data) {
|
||||
this.factory.customId(this.item, data);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count() {
|
||||
return this.item.count();
|
||||
@@ -124,8 +174,9 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> itemName() {
|
||||
return this.factory.itemName(this.item);
|
||||
public Item<I> customName(String displayName) {
|
||||
this.factory.customName(this.item, displayName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,10 +201,10 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
|
||||
return this.factory.unbreakable(this.item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Item<I> customName(String displayName) {
|
||||
this.factory.customName(this.item, displayName);
|
||||
return this;
|
||||
public Optional<String> itemName() {
|
||||
return this.factory.itemName(this.item);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,37 +287,37 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComponent(Key type) {
|
||||
public boolean hasComponent(Object type) {
|
||||
return this.factory.hasComponent(this.item, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeComponent(Key type) {
|
||||
public void removeComponent(Object type) {
|
||||
this.factory.removeComponent(this.item, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getComponent(Key type) {
|
||||
public Object getComponent(Object type) {
|
||||
return this.factory.getComponent(this.item, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getJavaTypeComponent(Key type) {
|
||||
public Object getJavaTypeComponent(Object type) {
|
||||
return this.factory.encodeJava(type, getComponent(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement getJsonTypeComponent(Key type) {
|
||||
public JsonElement getJsonTypeComponent(Object type) {
|
||||
return this.factory.encodeJson(type, getComponent(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComponent(Key type, Object value) {
|
||||
public void setComponent(Object type, Object value) {
|
||||
this.factory.setComponent(this.item, type, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetComponent(Key type) {
|
||||
public void resetComponent(Object type) {
|
||||
this.factory.resetComponent(this.item, type);
|
||||
}
|
||||
|
||||
@@ -280,9 +331,10 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
|
||||
return this.factory.load(this.item);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
public Item<I> copyWithCount(int count) {
|
||||
return new AbstractItem<>(this.factory, this.item.copyWithCount(count));
|
||||
public AbstractItem<W, I> copyWithCount(int count) {
|
||||
return new AbstractItem<>(this.factory, (W) this.item.copyWithCount(count));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -297,13 +349,13 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public Item<I> mergeCopy(Item<?> another) {
|
||||
return new AbstractItem<>(this.factory, this.factory.mergeCopy(this.item, ((AbstractItem) another).item));
|
||||
public AbstractItem<W, I> mergeCopy(Item<?> another) {
|
||||
return new AbstractItem<>(this.factory, this.factory.mergeCopy(this.item, (W) ((AbstractItem) another).item));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public void merge(Item<I> another) {
|
||||
this.factory.merge(this.item, ((AbstractItem) another).item);
|
||||
this.factory.merge(this.item, (W) ((AbstractItem) another).item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
if (VersionHelper.isVersionNewerThan1_21()) {
|
||||
registerDataFunction((obj) -> {
|
||||
String song = obj.toString();
|
||||
return new JukeboxSongModifier<>(Key.of(song));
|
||||
return new JukeboxSongModifier<>(new JukeboxPlayable(song, true));
|
||||
}, "jukebox-playable");
|
||||
}
|
||||
if (VersionHelper.isVersionNewerThan1_21_2()) {
|
||||
|
||||
@@ -30,6 +30,8 @@ public interface Item<I> {
|
||||
|
||||
Optional<Key> customId();
|
||||
|
||||
Item<I> customId(Key id);
|
||||
|
||||
int count();
|
||||
|
||||
Item<I> count(int amount);
|
||||
@@ -66,8 +68,24 @@ public interface Item<I> {
|
||||
|
||||
Optional<String> itemName();
|
||||
|
||||
Item<I> itemModel(String itemModel);
|
||||
|
||||
Optional<String> itemModel();
|
||||
|
||||
Item<I> tooltipStyle(String tooltipStyle);
|
||||
|
||||
Optional<String> tooltipStyle();
|
||||
|
||||
Item<I> lore(List<String> lore);
|
||||
|
||||
Optional<JukeboxPlayable> jukeboxSong();
|
||||
|
||||
Item<I> jukeboxSong(JukeboxPlayable song);
|
||||
|
||||
Optional<EquipmentData> equippable();
|
||||
|
||||
Item<I> equippable(EquipmentData equipmentData);
|
||||
|
||||
Optional<List<String>> lore();
|
||||
|
||||
Item<I> unbreakable(boolean unbreakable);
|
||||
@@ -96,19 +114,19 @@ public interface Item<I> {
|
||||
|
||||
boolean removeTag(Object... path);
|
||||
|
||||
boolean hasComponent(Key type);
|
||||
boolean hasComponent(Object type);
|
||||
|
||||
void removeComponent(Key type);
|
||||
void removeComponent(Object type);
|
||||
|
||||
Object getComponent(Key type);
|
||||
Object getComponent(Object type);
|
||||
|
||||
Object getJavaTypeComponent(Key type);
|
||||
Object getJavaTypeComponent(Object type);
|
||||
|
||||
JsonElement getJsonTypeComponent(Key type);
|
||||
JsonElement getJsonTypeComponent(Object type);
|
||||
|
||||
void setComponent(Key type, Object value);
|
||||
void setComponent(Object type, Object value);
|
||||
|
||||
void resetComponent(Key type);
|
||||
void resetComponent(Object type);
|
||||
|
||||
I getItem();
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import net.momirealms.craftengine.core.plugin.Plugin;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -9,10 +9,10 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class ItemFactory<P extends Plugin, W extends ItemWrapper<I>, I> {
|
||||
protected final P plugin;
|
||||
public abstract class ItemFactory<W extends ItemWrapper<I>, I> {
|
||||
protected final CraftEngine plugin;
|
||||
|
||||
protected ItemFactory(P plugin) {
|
||||
protected ItemFactory(CraftEngine plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@@ -21,103 +21,121 @@ public abstract class ItemFactory<P extends Plugin, W extends ItemWrapper<I>, I>
|
||||
return new AbstractItem<>(this, wrapInternal(item));
|
||||
}
|
||||
|
||||
public abstract Object encodeJava(Key componentType, @Nullable Object component);
|
||||
protected abstract W mergeCopy(W item1, W item2);
|
||||
|
||||
protected abstract JsonElement encodeJson(Key type, Object component);
|
||||
protected abstract void merge(W item1, W item2);
|
||||
|
||||
protected abstract ItemWrapper<I> wrapInternal(I item);
|
||||
protected abstract Object encodeJava(Object type, @Nullable Object component);
|
||||
|
||||
protected abstract Object getTag(ItemWrapper<I> item, Object... path);
|
||||
protected abstract JsonElement encodeJson(Object type, Object component);
|
||||
|
||||
protected abstract void setTag(ItemWrapper<I> item, Object value, Object... path);
|
||||
protected abstract W wrapInternal(I item);
|
||||
|
||||
protected abstract boolean hasTag(ItemWrapper<I> item, Object... path);
|
||||
protected abstract Object getTag(W item, Object... path);
|
||||
|
||||
protected abstract boolean removeTag(ItemWrapper<I> item, Object... path);
|
||||
protected abstract void setTag(W item, Object value, Object... path);
|
||||
|
||||
protected abstract void setComponent(ItemWrapper<I> item, Key type, Object value);
|
||||
protected abstract boolean hasTag(W item, Object... path);
|
||||
|
||||
protected abstract Object getComponent(ItemWrapper<I> item, Key type);
|
||||
protected abstract boolean removeTag(W item, Object... path);
|
||||
|
||||
protected abstract boolean hasComponent(ItemWrapper<I> item, Key type);
|
||||
protected abstract void setComponent(W item, Object type, Object value);
|
||||
|
||||
protected abstract void removeComponent(ItemWrapper<I> item, Key type);
|
||||
protected abstract Object getComponent(W item, Object type);
|
||||
|
||||
protected abstract void resetComponent(ItemWrapper<I> item, Key type);
|
||||
protected abstract boolean hasComponent(W item, Object type);
|
||||
|
||||
protected abstract I load(ItemWrapper<I> item);
|
||||
protected abstract void removeComponent(W item, Object type);
|
||||
|
||||
protected abstract I getItem(ItemWrapper<I> item);
|
||||
protected abstract void resetComponent(W item, Object type);
|
||||
|
||||
protected abstract void customModelData(ItemWrapper<I> item, Integer data);
|
||||
protected abstract I load(W item);
|
||||
|
||||
protected abstract Optional<Integer> customModelData(ItemWrapper<I> item);
|
||||
protected abstract I getItem(W item);
|
||||
|
||||
protected abstract void customName(ItemWrapper<I> item, String json);
|
||||
protected abstract void customModelData(W item, Integer data);
|
||||
|
||||
protected abstract Optional<String> customName(ItemWrapper<I> item);
|
||||
protected abstract Optional<Integer> customModelData(W item);
|
||||
|
||||
protected abstract void itemName(ItemWrapper<I> item, String json);
|
||||
protected abstract void customName(W item, String json);
|
||||
|
||||
protected abstract Optional<String> itemName(ItemWrapper<I> item);
|
||||
protected abstract Optional<String> customName(W item);
|
||||
|
||||
protected abstract void skull(ItemWrapper<I> item, String skullData);
|
||||
protected abstract void itemName(W item, String json);
|
||||
|
||||
protected abstract Optional<List<String>> lore(ItemWrapper<I> item);
|
||||
protected abstract Optional<String> itemName(W item);
|
||||
|
||||
protected abstract void lore(ItemWrapper<I> item, List<String> lore);
|
||||
protected abstract void skull(W item, String skullData);
|
||||
|
||||
protected abstract boolean unbreakable(ItemWrapper<I> item);
|
||||
protected abstract Optional<List<String>> lore(W item);
|
||||
|
||||
protected abstract void unbreakable(ItemWrapper<I> item, boolean unbreakable);
|
||||
protected abstract void lore(W item, List<String> lore);
|
||||
|
||||
protected abstract Optional<Boolean> glint(ItemWrapper<I> item);
|
||||
protected abstract boolean unbreakable(W item);
|
||||
|
||||
protected abstract void glint(ItemWrapper<I> item, Boolean glint);
|
||||
protected abstract void unbreakable(W item, boolean unbreakable);
|
||||
|
||||
protected abstract Optional<Integer> damage(ItemWrapper<I> item);
|
||||
protected abstract Optional<Boolean> glint(W item);
|
||||
|
||||
protected abstract void damage(ItemWrapper<I> item, Integer damage);
|
||||
protected abstract void glint(W item, Boolean glint);
|
||||
|
||||
protected abstract Optional<Integer> maxDamage(ItemWrapper<I> item);
|
||||
protected abstract Optional<Integer> damage(W item);
|
||||
|
||||
protected abstract void maxDamage(ItemWrapper<I> item, Integer damage);
|
||||
protected abstract void damage(W item, Integer damage);
|
||||
|
||||
protected abstract void enchantments(ItemWrapper<I> item, List<Enchantment> enchantments);
|
||||
protected abstract Optional<Integer> maxDamage(W item);
|
||||
|
||||
protected abstract void storedEnchantments(ItemWrapper<I> item, List<Enchantment> enchantments);
|
||||
protected abstract void maxDamage(W item, Integer damage);
|
||||
|
||||
protected abstract void addEnchantment(ItemWrapper<I> item, Enchantment enchantment);
|
||||
protected abstract void enchantments(W item, List<Enchantment> enchantments);
|
||||
|
||||
protected abstract void addStoredEnchantment(ItemWrapper<I> item, Enchantment enchantment);
|
||||
protected abstract void storedEnchantments(W item, List<Enchantment> enchantments);
|
||||
|
||||
protected abstract Optional<Enchantment> getEnchantment(ItemWrapper<I> item, Key key);
|
||||
protected abstract void addEnchantment(W item, Enchantment enchantment);
|
||||
|
||||
protected abstract void itemFlags(ItemWrapper<I> item, List<String> flags);
|
||||
protected abstract void addStoredEnchantment(W item, Enchantment enchantment);
|
||||
|
||||
protected abstract Key id(ItemWrapper<I> item);
|
||||
protected abstract Optional<Enchantment> getEnchantment(W item, Key key);
|
||||
|
||||
protected abstract Optional<Key> customId(ItemWrapper<I> item);
|
||||
protected abstract void itemFlags(W item, List<String> flags);
|
||||
|
||||
protected abstract Key vanillaId(ItemWrapper<I> item);
|
||||
protected abstract Key id(W item);
|
||||
|
||||
protected abstract int maxStackSize(ItemWrapper<I> item);
|
||||
protected abstract Optional<Key> customId(W item);
|
||||
|
||||
protected abstract void maxStackSize(ItemWrapper<I> item, Integer maxStackSize);
|
||||
protected abstract void customId(W item, Key id);
|
||||
|
||||
protected abstract boolean is(ItemWrapper<I> item, Key itemTag);
|
||||
protected abstract Key vanillaId(W item);
|
||||
|
||||
protected abstract boolean isBlockItem(ItemWrapper<I> item);
|
||||
protected abstract int maxStackSize(W item);
|
||||
|
||||
protected abstract void repairCost(ItemWrapper<I> item, Integer data);
|
||||
protected abstract void maxStackSize(W item, Integer maxStackSize);
|
||||
|
||||
protected abstract Optional<Integer> repairCost(ItemWrapper<I> item);
|
||||
protected abstract boolean is(W item, Key itemTag);
|
||||
|
||||
protected abstract void trim(ItemWrapper<I> item, Trim trim);
|
||||
protected abstract boolean isBlockItem(W item);
|
||||
|
||||
protected abstract Optional<Trim> trim(ItemWrapper<I> item);
|
||||
protected abstract void repairCost(W item, Integer data);
|
||||
|
||||
protected abstract ItemWrapper<I> mergeCopy(ItemWrapper<I> item1, ItemWrapper<I> item2);
|
||||
protected abstract Optional<Integer> repairCost(W item);
|
||||
|
||||
protected abstract void merge(ItemWrapper<I> item1, ItemWrapper<I> item2);
|
||||
protected abstract void trim(W item, Trim trim);
|
||||
|
||||
protected abstract Optional<Trim> trim(W item);
|
||||
|
||||
protected abstract void tooltipStyle(W item, String data);
|
||||
|
||||
protected abstract Optional<String> tooltipStyle(W item);
|
||||
|
||||
protected abstract void jukeboxSong(W item, JukeboxPlayable data);
|
||||
|
||||
protected abstract Optional<JukeboxPlayable> jukeboxSong(W item);
|
||||
|
||||
protected abstract void itemModel(W item, String data);
|
||||
|
||||
protected abstract Optional<String> itemModel(W item);
|
||||
|
||||
protected abstract void equippable(W item, EquipmentData data);
|
||||
|
||||
protected abstract Optional<EquipmentData> equippable(W item);
|
||||
}
|
||||
|
||||
@@ -78,6 +78,4 @@ public interface ItemManager<T> extends Manageable, ModelGenerator {
|
||||
Collection<Suggestion> cachedSuggestions();
|
||||
|
||||
Collection<Suggestion> cachedTotemSuggestions();
|
||||
|
||||
Object encodeJava(Key componentType, @Nullable Object component);
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.momirealms.craftengine.core.item;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ItemWrapper<I> {
|
||||
|
||||
I getItem();
|
||||
@@ -10,31 +8,9 @@ public interface ItemWrapper<I> {
|
||||
|
||||
Object getLiteralObject();
|
||||
|
||||
boolean set(Object value, Object... path);
|
||||
|
||||
boolean add(Object value, Object... path);
|
||||
|
||||
<V> V get(Object... path);
|
||||
|
||||
<V> V getExact(Object... path);
|
||||
|
||||
boolean remove(Object... path);
|
||||
|
||||
boolean hasTag(Object... path);
|
||||
|
||||
void removeComponent(Object type);
|
||||
|
||||
boolean hasComponent(Object type);
|
||||
|
||||
void setComponent(Object type, Object value);
|
||||
|
||||
Object getComponent(Object type);
|
||||
|
||||
int count();
|
||||
|
||||
void count(int amount);
|
||||
|
||||
ItemWrapper<I> copyWithCount(int count);
|
||||
|
||||
Map<String, Object> getData();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package net.momirealms.craftengine.core.item;
|
||||
|
||||
public record JukeboxPlayable(String song, boolean showInToolTip) {
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.EquipmentData;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
@@ -19,11 +18,11 @@ public class EquippableModifier<I> implements ItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
item.setComponent(ComponentKeys.EQUIPPABLE, this.data.toMap());
|
||||
item.equippable(this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Item<I> item) {
|
||||
item.removeComponent(ComponentKeys.EQUIPPABLE);
|
||||
item.equippable(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,11 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
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.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class IdModifier<I> implements ItemDataModifier<I> {
|
||||
public static final String CRAFT_ENGINE_ID = "craftengine:id";
|
||||
private static final BiConsumer<Item<?>, String> ID_SETTER = VersionHelper.isVersionNewerThan1_20_5() ?
|
||||
((item, id) -> {
|
||||
JsonElement element = item.getJsonTypeComponent(ComponentKeys.CUSTOM_DATA);
|
||||
if (element instanceof JsonObject jo) {
|
||||
jo.add(CRAFT_ENGINE_ID, new JsonPrimitive(id));
|
||||
item.setComponent(ComponentKeys.CUSTOM_DATA, jo);
|
||||
} else {
|
||||
item.setComponent(ComponentKeys.CUSTOM_DATA, Map.of(CRAFT_ENGINE_ID, id));
|
||||
}
|
||||
}) : ((item, id) -> item.setTag(id, CRAFT_ENGINE_ID));
|
||||
private final Key argument;
|
||||
|
||||
public IdModifier(Key argument) {
|
||||
@@ -37,11 +19,11 @@ public class IdModifier<I> implements ItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
ID_SETTER.accept(item, argument.toString());
|
||||
item.customId(this.argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Item<I> item) {
|
||||
item.removeTag(CRAFT_ENGINE_ID);
|
||||
// WHY DO YOU WANT TO REMOVE CRAFTENGINE ID?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
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.util.Key;
|
||||
@@ -19,11 +18,11 @@ public class ItemModelModifier<I> implements ItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
item.setComponent(ComponentKeys.ITEM_MODEL, this.data.toString());
|
||||
item.itemModel(this.data.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Item<I> item) {
|
||||
item.removeComponent(ComponentKeys.ITEM_MODEL);
|
||||
item.itemModel(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
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.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
import java.util.Map;
|
||||
import net.momirealms.craftengine.core.item.JukeboxPlayable;
|
||||
|
||||
public class JukeboxSongModifier<I> implements ItemDataModifier<I> {
|
||||
private final Key song;
|
||||
private final JukeboxPlayable song;
|
||||
|
||||
public JukeboxSongModifier(Key song) {
|
||||
public JukeboxSongModifier(JukeboxPlayable song) {
|
||||
this.song = song;
|
||||
}
|
||||
|
||||
@@ -22,18 +18,11 @@ public class JukeboxSongModifier<I> implements ItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
if (VersionHelper.isVersionNewerThan1_21_5()) {
|
||||
item.setComponent(ComponentKeys.JUKEBOX_PLAYABLE, song.toString());
|
||||
} else {
|
||||
item.setComponent(ComponentKeys.JUKEBOX_PLAYABLE, Map.of(
|
||||
"song", song.toString(),
|
||||
"show_in_tooltip", true
|
||||
));
|
||||
}
|
||||
item.jukeboxSong(this.song);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Item<I> item) {
|
||||
item.removeComponent(ComponentKeys.JUKEBOX_PLAYABLE);
|
||||
item.jukeboxSong(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class LoreModifier<I> implements ItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
item.lore(argument.stream().map(it -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(
|
||||
item.lore(this.argument.stream().map(it -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(
|
||||
it, context.tagResolvers()))).toList());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
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.util.Key;
|
||||
@@ -19,11 +18,11 @@ public class TooltipStyleModifier<I> implements ItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, ItemBuildContext context) {
|
||||
item.setComponent(ComponentKeys.TOOLTIP_STYLE, argument.toString());
|
||||
item.tooltipStyle(argument.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Item<I> item) {
|
||||
item.removeComponent(ComponentKeys.TOOLTIP_STYLE);
|
||||
item.tooltipStyle(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.core.pack.host;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.pack.host.impl.*;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.momirealms.craftengine.core.plugin.script;
|
||||
|
||||
import java.io.EOFException;
|
||||
|
||||
public abstract class AbstractTokenStringReader implements TokenStringReader {
|
||||
protected final char[] chars;
|
||||
protected int index;
|
||||
|
||||
@@ -51,7 +51,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.4
|
||||
anti_grief_version=0.15
|
||||
nms_helper_version=0.61.1
|
||||
nms_helper_version=0.61.7
|
||||
reactive_streams_version=1.0.4
|
||||
amazon_awssdk_version=2.31.23
|
||||
amazon_awssdk_eventstream_version=1.0.1
|
||||
|
||||
Reference in New Issue
Block a user