SPIGOT-7636: Fix clearing ItemMeta

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-04-25 16:15:01 +10:00
parent b031cef198
commit 2f65b80661
5 changed files with 28 additions and 24 deletions

View File

@@ -4,7 +4,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.enchantment.EnchantmentManager;
@@ -616,7 +616,7 @@ public final class CraftItemStack extends ItemStack {
return false;
}
if (CraftItemFactory.instance().equals(itemMeta, null)) {
item.applyComponents(DataComponentMap.EMPTY);
item.restorePatch(DataComponentPatch.EMPTY);
return true;
}
if (!CraftItemFactory.instance().isApplicable(itemMeta, getType(item))) {
@@ -636,7 +636,7 @@ public final class CraftItemStack extends ItemStack {
CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
((CraftMetaItem) itemMeta).applyToItem(tag);
item.applyComponents(tag.build());
item.restorePatch(tag.build());
}
// SpigotCraft#463 this is required now by the Vanilla client, so mimic ItemStack constructor in ensuring it
if (item.getItem() != null && item.getMaxDamage() > 0) {

View File

@@ -308,8 +308,12 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta {
if (this.pages != null) {
hash = 61 * hash + 17 * this.pages.hashCode();
}
hash = 61 * hash + 17 * Boolean.hashCode(resolved);
hash = 61 * hash + 19 * Integer.hashCode(generation);
if (this.resolved) {
hash = 61 * hash + 17 * Boolean.hashCode(this.resolved);
}
if (hasGeneration()) {
hash = 61 * hash + 19 * Integer.hashCode(this.generation);
}
return original != hash ? CraftMetaBook.class.hashCode() ^ hash : hash;
}

View File

@@ -18,7 +18,8 @@ public class CraftMetaColorableArmor extends CraftMetaArmor implements Colorable
Material.LEATHER_HELMET,
Material.LEATHER_CHESTPLATE,
Material.LEATHER_LEGGINGS,
Material.LEATHER_BOOTS
Material.LEATHER_BOOTS,
Material.WOLF_ARMOR
);
private Color color = DEFAULT_LEATHER_COLOR;

View File

@@ -169,7 +169,9 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
hash = 73 * hash + lodestoneY;
hash = 73 * hash + lodestoneZ;
}
hash = 73 * hash + (isLodestoneTracked() ? 1231 : 1237);
if (hasLodestoneTracked()) {
hash = 73 * hash + (isLodestoneTracked() ? 1231 : 1237);
}
return original != hash ? CraftMetaCompass.class.hashCode() ^ hash : hash;
}
@@ -205,7 +207,9 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
builder.put(LODESTONE_POS_Y.BUKKIT, lodestoneY);
builder.put(LODESTONE_POS_Z.BUKKIT, lodestoneZ);
}
builder.put(LODESTONE_TRACKED.BUKKIT, tracked);
if (hasLodestoneTracked()) {
builder.put(LODESTONE_TRACKED.BUKKIT, tracked);
}
return builder;
}