Skip to content

Commit

Permalink
Deprecate/disable more stuff not applying to 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Apr 23, 2024
1 parent 6395dd1 commit 167487e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
23 changes: 23 additions & 0 deletions item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/NBTItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.tr7zw.changeme.nbtapi.iface.ReadWriteItemNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;

Expand Down Expand Up @@ -210,10 +211,18 @@ public void mergeNBT(ItemStack item) {
*
* @param item ItemStack that should get the new NBT data
*/
@Deprecated
public void mergeCustomNBT(ItemStack item) {
if (item == null || item.getType() == Material.AIR) {
throw new NullPointerException("ItemStack can't be null/Air!");
}
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
// 1.20.5+ doesn't have any vanilla tags
NBT.modify(item, nbt -> {
nbt.mergeCompound(this);
});
return;
}
ItemMeta meta = item.getItemMeta();
NBTReflectionUtil.getUnhandledNBTTags(meta)
.putAll(NBTReflectionUtil.getUnhandledNBTTags(bukkitItem.getItemMeta()));
Expand All @@ -225,7 +234,12 @@ public void mergeCustomNBT(ItemStack item) {
*
* @return true when custom tags are present
*/
@Deprecated
public boolean hasCustomNbtData() {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
// 1.20.5+ doesn't have any vanilla tags
return hasNBTData();
}
finalizeChanges();
ItemMeta meta = bukkitItem.getItemMeta();
return !NBTReflectionUtil.getUnhandledNBTTags(meta).isEmpty();
Expand All @@ -234,8 +248,14 @@ public boolean hasCustomNbtData() {
/**
* Remove all custom (non-vanilla) NBT tags from the NBTItem.
*/
@Deprecated
public void clearCustomNBT() {
finalizeChanges();
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
// 1.20.5+ doesn't have any vanilla tags
setCompound(null);
return;
}
ItemMeta meta = bukkitItem.getItemMeta();
NBTReflectionUtil.getUnhandledNBTTags(meta).clear();
bukkitItem.setItemMeta(meta);
Expand Down Expand Up @@ -280,6 +300,9 @@ public void modifyMeta(BiConsumer<ReadableNBT, ItemMeta> handler) {
bukkitItem.setItemMeta(meta);
updateCachedCompound();
if (directApply) {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
throw new NbtApiException("Direct apply mode meta changes don't work anymore in 1.20.5+. Please switch to the modern NBT.modify sytnax!");
}
applyNBT(originalSrcStack);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) {
* @return Map containing unhandled (custom) NBT tags
*/
@SuppressWarnings("unchecked")
@Deprecated
public static Map<String, Object> getUnhandledNBTTags(ItemMeta meta) {
try {
return (Map<String, Object>) field_unhandledTags.get(meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTItem;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.nbtapi.plugin.tests.Test;

public class DirectApplyMetaTest implements Test {

@Override
public void test() throws Exception {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
return; // skip
}
ItemStack baseItem = new ItemStack(Material.STONE);
NBTItem nbti = new NBTItem(baseItem, true);
nbti.setString("SomeKey", "SomeValue");
nbti.modifyMeta(this::modifyMeta);

if (!new NBTItem(baseItem).hasTag("SomeKey") || !"SomeValue".equals(baseItem.getItemMeta().getDisplayName())) {
throw new NbtApiException("The item was not modified correctly!");
throw new NbtApiException("The item was not modified correctly! " + NBT.itemStackToNBT(baseItem));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

import de.tr7zw.changeme.nbtapi.NBTItem;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.nbtapi.plugin.tests.Test;

public class ItemMergingTest implements Test {

@Override
public void test() throws Exception {
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) {
return; // skip, there is no vanilla nbt
}
ItemStack item = new ItemStack(Material.WRITTEN_BOOK);
BookMeta bookMeta = (BookMeta) item.getItemMeta();
bookMeta.setAuthor("Author");
Expand Down

0 comments on commit 167487e

Please sign in to comment.