9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 04:19:27 +00:00

修改1.20.1-1.20.4nbt实现

This commit is contained in:
XiaoMoMi
2025-06-29 21:13:46 +08:00
parent 4a2d4c76c7
commit 997890ca38
38 changed files with 153 additions and 235 deletions

View File

@@ -33,7 +33,6 @@ import net.momirealms.craftengine.core.pack.LoadingSequence;
import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.pack.ResourceLocation;
import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
import net.momirealms.craftengine.core.plugin.config.StringKeyConstructor;
import net.momirealms.craftengine.core.plugin.context.event.EventFunctions;

View File

@@ -63,7 +63,6 @@ public class BukkitFurnitureElement extends AbstractFurnitureElement {
} else {
if (color != null) {
item.dyedColor(color);
item.load();
}
}
ItemDisplayEntityData.DisplayedItem.addEntityDataIfNotDefaultValue(item.getLiteralObject(), cachedValues);

View File

@@ -153,7 +153,7 @@ public class BukkitFontManager extends AbstractFontManager implements Listener {
if (replaceProcessResult.changed()) {
Item<ItemStack> wrapped = this.plugin.itemManager().wrap(result);
wrapped.customNameJson(AdventureHelper.componentToJson(replaceProcessResult.newText()));
event.setResult(wrapped.load());
event.setResult(wrapped.getItem());
}
}

View File

@@ -38,7 +38,7 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
for (ItemDataModifier<ItemStack> modifier : this.modifiers) {
modifier.apply(wrapped, context);
}
return wrapped.load();
return wrapped.getItem();
}
@Override
@@ -48,7 +48,7 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
for (ItemDataModifier<ItemStack> modifier : dataModifiers()) {
modifier.apply(wrapped, context);
}
return BukkitCraftEngine.instance().itemManager().wrap(wrapped.load());
return BukkitCraftEngine.instance().itemManager().wrap(wrapped.getItem());
}
public Object clientItem() {

View File

@@ -83,7 +83,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
try {
Item<ItemStack> wrapped = wrap(itemStack);
if (wrapped == null) return Optional.empty();
return this.networkItemHandler.s2c(wrapped, player).map(Item::load);
return this.networkItemHandler.s2c(wrapped, player).map(Item::getItem);
} catch (Throwable e) {
if (Config.debug()) {
this.plugin.logger().warn("Failed to handle s2c items.", e);
@@ -96,7 +96,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
try {
Item<ItemStack> wrapped = wrap(itemStack);
if (wrapped == null) return Optional.empty();
return this.networkItemHandler.c2s(wrapped).map(Item::load);
return this.networkItemHandler.c2s(wrapped).map(Item::getItem);
} catch (Throwable e) {
if (Config.debug()) {
this.plugin.logger().warn("Failed to handle c2s items.", e);

View File

@@ -153,11 +153,6 @@ public class ComponentItemWrapper implements ItemWrapper<ItemStack> {
return this.item;
}
@Override
public ItemStack load() {
return this.item;
}
@Override
public Object getLiteralObject() {
return this.handle;

View File

@@ -1,36 +1,60 @@
package net.momirealms.craftengine.bukkit.item;
import com.saicone.rtag.RtagItem;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
import net.momirealms.craftengine.bukkit.util.ItemUtils;
import net.momirealms.craftengine.core.item.ItemWrapper;
import net.momirealms.sparrow.nbt.Tag;
import org.bukkit.inventory.ItemStack;
public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
private final RtagItem rtagItem;
private final Object nmsStack;
private final ItemStack itemStack;
public LegacyItemWrapper(RtagItem rtagItem) {
this.rtagItem = rtagItem;
public LegacyItemWrapper(ItemStack item) {
this.itemStack = ItemUtils.ensureCraftItemStack(item);
this.nmsStack = FastNMS.INSTANCE.field$CraftItemStack$handle(this.itemStack);
}
public boolean setTag(Object value, Object... path) {
Object finalNMSTag;
if (value instanceof Tag tag) {
return this.rtagItem.set(MRegistryOps.SPARROW_NBT.convertTo(MRegistryOps.NBT, tag), path);
finalNMSTag = MRegistryOps.SPARROW_NBT.convertTo(MRegistryOps.NBT, tag);
} else {
return this.rtagItem.set(value, path);
}
}
public boolean add(Object value, Object... path) {
if (value instanceof Tag tag) {
return this.rtagItem.add(MRegistryOps.SPARROW_NBT.convertTo(MRegistryOps.NBT, tag), path);
} else {
return this.rtagItem.add(value, path);
finalNMSTag = MRegistryOps.JAVA.convertTo(MRegistryOps.NBT, value);
}
Object currentTag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(this.nmsStack);
if (path == null || path.length == 0) {
if (CoreReflections.clazz$CompoundTag.isInstance(finalNMSTag)) {
FastNMS.INSTANCE.method$ItemStack$setTag(this.nmsStack, finalNMSTag);
return true;
}
return false;
}
for (int i = 0; i < path.length - 1; i++) {
Object pathSegment = path[i];
if (pathSegment == null) return false;
Object childTag = FastNMS.INSTANCE.method$CompoundTag$get(currentTag, pathSegment.toString());
if (!CoreReflections.clazz$CompoundTag.isInstance(childTag)) {
childTag = FastNMS.INSTANCE.constructor$CompoundTag();
FastNMS.INSTANCE.method$CompoundTag$put(currentTag, pathSegment.toString(), childTag);
}
currentTag = childTag;
}
String finalKey = path[path.length - 1].toString();
FastNMS.INSTANCE.method$CompoundTag$put(currentTag, finalKey, finalNMSTag);
return true;
}
@SuppressWarnings("unchecked")
public <V> V getJavaTag(Object... path) {
return this.rtagItem.get(path);
Object tag = getExactTag(path);
if (tag == null) return null;
return (V) MRegistryOps.NBT.convertTo(MRegistryOps.JAVA, tag);
}
public Tag getNBTTag(Object... path) {
@@ -49,41 +73,73 @@ public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
}
public Object getExactTag(Object... path) {
return this.rtagItem.getExact(path);
Object compoundTag = FastNMS.INSTANCE.method$ItemStack$getTag(this.nmsStack);
if (compoundTag == null) return null;
Object currentTag = compoundTag;
for (int i = 0; i < path.length; i++) {
Object pathSegment = path[i];
if (pathSegment == null) return null;
currentTag = FastNMS.INSTANCE.method$CompoundTag$get(currentTag, path[i].toString());
if (currentTag == null) return null;
if (i == path.length - 1) {
return currentTag;
}
if (!CoreReflections.clazz$CompoundTag.isInstance(currentTag)) {
return null;
}
}
return null;
}
public boolean remove(Object... path) {
return this.rtagItem.remove(path);
Object compoundTag = FastNMS.INSTANCE.method$ItemStack$getTag(this.nmsStack);
if (compoundTag == null || path == null || path.length == 0) return false;
if (path.length == 1) {
String key = path[0].toString();
if (FastNMS.INSTANCE.method$CompoundTag$get(compoundTag, key) != null) {
FastNMS.INSTANCE.method$CompoundTag$remove(compoundTag, key);
return true;
}
}
Object currentTag = compoundTag;
for (int i = 0; i < path.length - 1; i++) {
Object pathSegment = path[i];
if (pathSegment == null) return false;
currentTag = FastNMS.INSTANCE.method$CompoundTag$get(currentTag, path[i].toString());
if (!CoreReflections.clazz$CompoundTag.isInstance(currentTag)) {
return false;
}
}
String finalKey = path[path.length - 1].toString();
if (FastNMS.INSTANCE.method$CompoundTag$get(currentTag, finalKey) != null) {
FastNMS.INSTANCE.method$CompoundTag$remove(currentTag, finalKey);
return true;
}
return false;
}
public boolean hasTag(Object... path) {
return this.rtagItem.hasTag(path);
}
public void update() {
this.rtagItem.update();
}
@Override
public ItemStack load() {
return this.rtagItem.load();
return getExactTag(path) != null;
}
@Override
public ItemStack getItem() {
return this.rtagItem.getItem();
return this.itemStack;
}
@Override
public Object getLiteralObject() {
return this.rtagItem.getLiteralObject();
return this.nmsStack;
}
@Override
public ItemWrapper<ItemStack> copyWithCount(int count) {
ItemStack copied = this.rtagItem.loadCopy();
ItemStack copied = this.itemStack.clone();
copied.setAmount(count);
return new LegacyItemWrapper(new RtagItem(copied));
return new LegacyItemWrapper(copied);
}
@Override

View File

@@ -157,7 +157,6 @@ public class BlockItemBehavior extends BlockBoundItemBehavior {
if (!player.isCreativeMode()) {
Item<?> item = context.getItem();
item.count(item.count() - 1);
item.load();
}
block.setPlacedBy(context, blockStateToPlace);

View File

@@ -158,7 +158,6 @@ public class FurnitureItemBehavior extends ItemBehavior {
if (!player.isCreativeMode()) {
item.count(item.count() - 1);
item.load();
}
context.getLevel().playBlockSound(finalPlacePosition, customFurniture.settings().sounds().placeSound());

View File

@@ -69,11 +69,6 @@ public abstract class BukkitItemFactory<W extends ItemWrapper<ItemStack>> extend
return customId(item).orElse(vanillaId(item));
}
@Override
protected ItemStack load(W item) {
return item.load();
}
@Override
protected ItemStack getItem(W item) {
return item.getItem();

View File

@@ -52,8 +52,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
for (int i = 0; i < path.length; i++) {
Object pathSegment = path[i];
if (pathSegment == null) return null;
String key = pathSegment.toString();
currentObj = ((Map<String, Object>) currentObj).get(key);
currentObj = ((Map<String, Object>) currentObj).get(pathSegment.toString());
if (currentObj == null) return null;
if (i == path.length - 1) {
return currentObj;
@@ -74,8 +73,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
Object pathSegment = path[i];
if (pathSegment == null) return null;
CompoundTag t = (CompoundTag) currentTag;
String key = pathSegment.toString();
currentTag = t.get(key);
currentTag = t.get(pathSegment.toString());
if (currentTag == null) return null;
if (i == path.length - 1) {
return currentTag;
@@ -424,30 +422,6 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
}
}
@Override
protected void addEnchantment(ComponentItemWrapper item, Enchantment enchantment) {
Object enchant = item.getComponentExact(ComponentTypes.ENCHANTMENTS);
try {
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
map.put(enchantment.id().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.getComponentExact(ComponentTypes.STORED_ENCHANTMENTS);
try {
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
map.put(enchantment.id().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+");

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.bukkit.item.factory;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.saicone.rtag.data.ComponentType;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
@@ -17,7 +16,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@SuppressWarnings("UnstableApiUsage")
public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
public ComponentItemFactory1_21_5(CraftEngine plugin) {
@@ -116,9 +114,7 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
@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.getComponentExact(ComponentTypes.JUKEBOX_PLAYABLE)).orElse(null);
String song = (String) item.getJavaComponent(ComponentTypes.JUKEBOX_PLAYABLE).orElse(null);
if (song == null) return Optional.empty();
return Optional.of(new JukeboxPlayable(song, true));
}

View File

@@ -1,10 +1,5 @@
package net.momirealms.craftengine.bukkit.item.factory;
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.LegacyItemWrapper;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries;
@@ -32,7 +27,7 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
@Override
protected LegacyItemWrapper wrapInternal(ItemStack item) {
return new LegacyItemWrapper(new RtagItem(item));
return new LegacyItemWrapper(item);
}
@Override
@@ -212,38 +207,6 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
item.setTag(tags, "StoredEnchantments");
}
@Override
protected void addEnchantment(LegacyItemWrapper item, Enchantment enchantment) {
Object enchantments = item.getExactTag("Enchantments");
if (enchantments != null) {
for (Object enchant : TagList.getValue(enchantments)) {
if (TagBase.getValue(TagCompound.get(enchant, "id")).equals(enchant.toString())) {
TagCompound.set(enchant, "lvl", TagBase.newTag(enchantment.level()));
return;
}
}
item.add(Map.of("id", enchantment.id().toString(), "lvl", (short) enchantment.level()), "Enchantments");
} else {
item.setTag(List.of(Map.of("id", enchantment.id().toString(), "lvl", (short) enchantment.level())), "Enchantments");
}
}
@Override
protected void addStoredEnchantment(LegacyItemWrapper item, Enchantment enchantment) {
Object enchantments = item.getExactTag("StoredEnchantments");
if (enchantments != null) {
for (Object enchant : TagList.getValue(enchantments)) {
if (TagBase.getValue(TagCompound.get(enchant, "id")).equals(enchant.toString())) {
TagCompound.set(enchant, "lvl", TagBase.newTag(enchantment.level()));
return;
}
}
item.add(Map.of("id", enchantment.id().toString(), "lvl", (short) enchantment.level()), "StoredEnchantments");
} else {
item.setTag(List.of(Map.of("id", enchantment.id().toString(), "lvl", (short) enchantment.level())), "StoredEnchantments");
}
}
@SuppressWarnings("deprecation")
@Override
protected Optional<Enchantment> getEnchantment(LegacyItemWrapper item, Key key) {
@@ -307,33 +270,33 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
@Override
protected LegacyItemWrapper mergeCopy(LegacyItemWrapper item1, LegacyItemWrapper item2) {
Object itemStack = ItemObject.copy(item2.getLiteralObject());
FastNMS.INSTANCE.method$ItemStack$setTag(itemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject())));
// one more step than vanilla
TagCompound.merge(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(itemStack), FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject()), true, true);
return new LegacyItemWrapper(new RtagItem(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack)));
Object copied = FastNMS.INSTANCE.constructor$ItemStack(FastNMS.INSTANCE.method$ItemStack$getItem(item2.getLiteralObject()), item2.count());
Object copiedTag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(copied);
FastNMS.INSTANCE.method$CompoundTag$merge(copiedTag, FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject()));
FastNMS.INSTANCE.method$CompoundTag$merge(copiedTag, FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject()));
return new LegacyItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(copied));
}
@Override
protected void merge(LegacyItemWrapper item1, LegacyItemWrapper item2) {
// load previous changes on nms items
item1.load();
TagCompound.merge(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject()), FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject()), true, true);
// update wrapped item
item1.update();
Object item1Tag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject());
Object item2Tag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject());
FastNMS.INSTANCE.method$CompoundTag$merge(item1Tag, item2Tag);
}
@Override
protected LegacyItemWrapper transmuteCopy(LegacyItemWrapper item, Key newItem, int amount) {
Object newItemStack = FastNMS.INSTANCE.constructor$ItemStack(FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(newItem)), amount);
FastNMS.INSTANCE.method$ItemStack$setTag(newItemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject())));
return new LegacyItemWrapper(new RtagItem(ItemObject.asCraftMirror(newItemStack)));
Object copied = FastNMS.INSTANCE.constructor$ItemStack(FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(newItem)), amount);
Object copiedTag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(copied);
Object thisTag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject());
FastNMS.INSTANCE.method$CompoundTag$merge(copiedTag, thisTag);
return new LegacyItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(copied));
}
@Override
protected LegacyItemWrapper unsafeTransmuteCopy(LegacyItemWrapper item, Object newItem, int amount) {
Object newItemStack = FastNMS.INSTANCE.constructor$ItemStack(newItem, amount);
FastNMS.INSTANCE.method$ItemStack$setTag(newItemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject())));
return new LegacyItemWrapper(new RtagItem(ItemObject.asCraftMirror(newItemStack)));
FastNMS.INSTANCE.method$ItemStack$setTag(newItemStack, FastNMS.INSTANCE.method$CompoundTag$copy(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject())));
return new LegacyItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(newItemStack));
}
}

View File

@@ -96,7 +96,6 @@ public class DebugStickListener implements Listener {
currentProperty = getRelative(properties, currentProperty, player.isSecondaryUseActive());
data.put(blockId, currentProperty.name());
wrapped.setTag(data, "craftengine:debug_stick_state");
wrapped.load();
Object systemChatPacket = NetworkReflections.constructor$ClientboundSystemChatPacket.newInstance(
ComponentUtils.adventureToMinecraft(Component.translatable("item.minecraft.debug_stick.select")
.arguments(

View File

@@ -130,7 +130,8 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
} else if (VersionHelper.isOrAbove1_20_2()) {
nmsRecipe = CoreReflections.constructor$RecipeHolder.newInstance(KeyUtils.toResourceLocation(id), nmsRecipe);
} else {
return () -> {};
Object finalNmsRecipe0 = nmsRecipe;
return () -> registerNMSSmithingRecipe(finalNmsRecipe0);
}
Object finalNmsRecipe = nmsRecipe;
return () -> registerNMSSmithingRecipe(finalNmsRecipe);

View File

@@ -643,7 +643,7 @@ public class RecipeEventListener implements Listener {
}
afterPenalty = calculateIncreasedRepairCost(afterPenalty);
wrappedFirst.repairCost(afterPenalty);
event.setResult(wrappedFirst.load());
event.setResult(wrappedFirst.getItem());
}
}
@@ -757,7 +757,7 @@ public class RecipeEventListener implements Listener {
int remainingDurability = totalMaxDamage - totalDamage;
int newItemDamage = Math.max(0, newItem.maxDamage() - remainingDurability);
newItem.damage(newItemDamage);
inventory.setResult(newItem.load());
inventory.setResult(newItem.getItem());
} else if (CoreReflections.clazz$ArmorDyeRecipe.isInstance(mcRecipe)) {
ItemStack[] itemStacks = inventory.getMatrix();
for (ItemStack itemStack : itemStacks) {

View File

@@ -1,9 +1,8 @@
package net.momirealms.craftengine.bukkit.plugin.command.feature;
import com.saicone.rtag.item.ItemTagStream;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
import net.momirealms.craftengine.bukkit.util.ItemUtils;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
@@ -28,11 +27,9 @@ public class DebugItemDataCommand extends BukkitCommandFeature<CommandSender> {
.handler(context -> {
ItemStack itemInHand = context.sender().getInventory().getItemInMainHand();
if (ItemUtils.isEmpty(itemInHand)) {
plugin().senderFactory().wrap(context.sender()).sendMessage(Component.text("Please hold an item").color(NamedTextColor.RED));
return;
}
Map<String, Object> readableMap = toReadableMap(itemInHand);
readableMap.remove("rtagDataVersion");
Map<String, Object> readableMap = toMap(itemInHand);
List<String> readableList = mapToList(readableMap);
StringJoiner joiner = new StringJoiner("<newline><reset>");
for (String text : readableList) {
@@ -47,13 +44,10 @@ public class DebugItemDataCommand extends BukkitCommandFeature<CommandSender> {
return "debug_item_data";
}
public static Map<String, Object> toReadableMap(ItemStack item) {
return toMap(item);
}
@SuppressWarnings("unchecked")
private static Map<String, Object> toMap(ItemStack object) {
return ItemTagStream.INSTANCE.toMap(object);
Object tag = FastNMS.INSTANCE.method$itemStack$save(FastNMS.INSTANCE.field$CraftItemStack$handle(object), FastNMS.INSTANCE.constructor$CompoundTag());
return (Map<String, Object>) MRegistryOps.NBT.convertTo(MRegistryOps.JAVA, tag);
}
private List<String> mapToList(Map<String, Object> readableDataMap) {

View File

@@ -79,7 +79,7 @@ public class TotemAnimationCommand extends BukkitCommandFeature<CommandSender> {
item.setComponent(ComponentTypes.DEATH_PROTECTION, Map.of());
}
}
ItemStack totemItem = item.load();
ItemStack totemItem = item.getItem();
MultiplePlayerSelector selector = context.get("players");
for (Player player : selector.values()) {
PlayerUtils.sendTotemAnimation(player, totemItem);

View File

@@ -3560,4 +3560,11 @@ public final class CoreReflections {
"world.level.block.state.properties.BlockStateProperties"
)
);
public static final Class<?> clazz$CompoundTag = requireNonNull(
BukkitReflectionUtils.findReobfOrMojmapClass(
"nbt.NBTTagCompound",
"nbt.CompoundTag"
)
);
}

View File

@@ -71,7 +71,7 @@ public class BukkitWorld implements World {
@Override
public void dropItemNaturally(Position location, Item<?> item) {
ItemStack itemStack = (ItemStack) item.load();
ItemStack itemStack = (ItemStack) item.getItem();
if (ItemUtils.isEmpty(itemStack)) return;
if (VersionHelper.isOrAbove1_21_2()) {
platformWorld().dropItemNaturally(new Location(null, location.x(), location.y(), location.z()), (ItemStack) item.getItem());