mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 13:40:24 -07:00
rewrite CraftItemMetas#getItemMetaData
This commit is contained in:
parent
6c8db58b51
commit
2d5e052842
@ -35,6 +35,7 @@ val rewriteApi = tasks.registerGenerationTask("rewriteApi", true, "api", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val rewriteImpl = tasks.registerGenerationTask("rewriteImpl", true, "impl", {
|
val rewriteImpl = tasks.registerGenerationTask("rewriteImpl", true, "impl", {
|
||||||
|
bootstrapTags = true // needed for CraftItemMetasRewriter, remove once item meta is gone
|
||||||
sourceSet = rootProject.layout.projectDirectory.dir("paper-server/src/main/java")
|
sourceSet = rootProject.layout.projectDirectory.dir("paper-server/src/main/java")
|
||||||
}) {
|
}) {
|
||||||
description = "Rewrite existing implementation classes"
|
description = "Rewrite existing implementation classes"
|
||||||
|
@ -13,6 +13,7 @@ import io.papermc.generator.rewriter.types.registry.RegistryFieldRewriter;
|
|||||||
import io.papermc.generator.rewriter.types.registry.RegistryTagRewriter;
|
import io.papermc.generator.rewriter.types.registry.RegistryTagRewriter;
|
||||||
import io.papermc.generator.rewriter.types.registry.TagRewriter;
|
import io.papermc.generator.rewriter.types.registry.TagRewriter;
|
||||||
import io.papermc.generator.rewriter.types.simple.CraftBlockEntityStateMapping;
|
import io.papermc.generator.rewriter.types.simple.CraftBlockEntityStateMapping;
|
||||||
|
import io.papermc.generator.rewriter.types.simple.CraftItemMetasRewriter;
|
||||||
import io.papermc.generator.rewriter.types.simple.CraftPotionUtilRewriter;
|
import io.papermc.generator.rewriter.types.simple.CraftPotionUtilRewriter;
|
||||||
import io.papermc.generator.rewriter.types.simple.EntityTypeRewriter;
|
import io.papermc.generator.rewriter.types.simple.EntityTypeRewriter;
|
||||||
import io.papermc.generator.rewriter.types.simple.ItemTypeRewriter;
|
import io.papermc.generator.rewriter.types.simple.ItemTypeRewriter;
|
||||||
@ -23,7 +24,6 @@ import io.papermc.generator.rewriter.types.simple.trial.VillagerProfessionRewrit
|
|||||||
import io.papermc.generator.types.goal.MobGoalNames;
|
import io.papermc.generator.types.goal.MobGoalNames;
|
||||||
import io.papermc.generator.rewriter.types.registry.RegistriesArgumentProviderRewriter;
|
import io.papermc.generator.rewriter.types.registry.RegistriesArgumentProviderRewriter;
|
||||||
import io.papermc.generator.utils.Formatting;
|
import io.papermc.generator.utils.Formatting;
|
||||||
import io.papermc.generator.utils.ItemMetaMapping;
|
|
||||||
import io.papermc.typewriter.preset.EnumCloneRewriter;
|
import io.papermc.typewriter.preset.EnumCloneRewriter;
|
||||||
import io.papermc.typewriter.preset.model.EnumValue;
|
import io.papermc.typewriter.preset.model.EnumValue;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -169,6 +169,7 @@ public final class Rewriters {
|
|||||||
sourceSet
|
sourceSet
|
||||||
//.register("CraftBlockData#MAP", Types.CRAFT_BLOCK_DATA, new CraftBlockDataMapping())
|
//.register("CraftBlockData#MAP", Types.CRAFT_BLOCK_DATA, new CraftBlockDataMapping())
|
||||||
.register("CraftBlockEntityStates", Types.CRAFT_BLOCK_STATES, new CraftBlockEntityStateMapping())
|
.register("CraftBlockEntityStates", Types.CRAFT_BLOCK_STATES, new CraftBlockEntityStateMapping())
|
||||||
|
.register("CraftItemMetas#getItemMetaData", Types.CRAFT_ITEM_METAS, new CraftItemMetasRewriter())
|
||||||
.register(Types.CRAFT_STATISTIC, composite(
|
.register(Types.CRAFT_STATISTIC, composite(
|
||||||
sameHolder("CraftStatisticCustom", new StatisticRewriter.CraftCustom()),
|
sameHolder("CraftStatisticCustom", new StatisticRewriter.CraftCustom()),
|
||||||
sameHolder("CraftStatisticType", new StatisticRewriter.CraftType())
|
sameHolder("CraftStatisticType", new StatisticRewriter.CraftType())
|
||||||
|
@ -105,6 +105,8 @@ public final class Types {
|
|||||||
|
|
||||||
public static final ClassNamed CRAFT_BLOCK_STATES = ClassNamed.of(IMPL_PACKAGE + ".block", "CraftBlockStates");
|
public static final ClassNamed CRAFT_BLOCK_STATES = ClassNamed.of(IMPL_PACKAGE + ".block", "CraftBlockStates");
|
||||||
|
|
||||||
|
public static final ClassNamed CRAFT_ITEM_METAS = ClassNamed.of(IMPL_PACKAGE + ".inventory", "CraftItemMetas");
|
||||||
|
|
||||||
public static final ClassNamed CRAFT_STATISTIC = ClassNamed.of(IMPL_PACKAGE, "CraftStatistic");
|
public static final ClassNamed CRAFT_STATISTIC = ClassNamed.of(IMPL_PACKAGE, "CraftStatistic");
|
||||||
|
|
||||||
public static final ClassNamed CRAFT_POTION_UTIL = ClassNamed.of(IMPL_PACKAGE + ".potion", "CraftPotionUtil");
|
public static final ClassNamed CRAFT_POTION_UTIL = ClassNamed.of(IMPL_PACKAGE + ".potion", "CraftPotionUtil");
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
package io.papermc.generator.rewriter.types.simple;
|
||||||
|
|
||||||
|
import io.papermc.generator.registry.RegistryEntries;
|
||||||
|
import io.papermc.generator.rewriter.types.Types;
|
||||||
|
import io.papermc.generator.utils.Formatting;
|
||||||
|
import io.papermc.generator.utils.ItemMetaMapping;
|
||||||
|
import io.papermc.typewriter.ClassNamed;
|
||||||
|
import io.papermc.typewriter.context.IndentUnit;
|
||||||
|
import io.papermc.typewriter.replace.SearchMetadata;
|
||||||
|
import io.papermc.typewriter.replace.SearchReplaceRewriter;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.tags.TagKey;
|
||||||
|
import net.minecraft.util.ExtraCodecs;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public class CraftItemMetasRewriter extends SearchReplaceRewriter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void insert(SearchMetadata metadata, StringBuilder builder) {
|
||||||
|
IndentUnit indentUnit = this.indentUnit();
|
||||||
|
ClassNamed itemType = RegistryEntries.byRegistryKey(Registries.ITEM).data().api().klass();
|
||||||
|
for (Map.Entry<ClassNamed, List<ItemMetaMapping.ItemPredicate>> entry : ItemMetaMapping.PREDICATES.entrySet()) {
|
||||||
|
String field = ItemMetaMapping.BRIDGE.get(entry.getKey()).field();
|
||||||
|
Iterator<ItemMetaMapping.ItemPredicate> predicateIterator = entry.getValue().iterator();
|
||||||
|
|
||||||
|
builder.append(metadata.indent());
|
||||||
|
builder.append("if (");
|
||||||
|
boolean beginning = true;
|
||||||
|
while (predicateIterator.hasNext()) {
|
||||||
|
ItemMetaMapping.ItemPredicate predicate = predicateIterator.next();
|
||||||
|
if (!beginning) {
|
||||||
|
builder.append(metadata.indent()).append(indentUnit);
|
||||||
|
}
|
||||||
|
switch (predicate) {
|
||||||
|
case ItemMetaMapping.ItemPredicate.IsElementPredicate isElementPredicate:
|
||||||
|
ExtraCodecs.TagOrElementLocation value = isElementPredicate.value();
|
||||||
|
if (value.tag()) {
|
||||||
|
// flatten tag since they can change at runtime with plugins/data-packs
|
||||||
|
Iterator<Holder<Item>> tagValues = BuiltInRegistries.ITEM.getTagOrEmpty(TagKey.create(Registries.ITEM, value.id())).iterator();
|
||||||
|
while (tagValues.hasNext()) {
|
||||||
|
appendElementEquality(builder, itemType, tagValues.next().unwrapKey().orElseThrow().location());
|
||||||
|
if (tagValues.hasNext()) {
|
||||||
|
builder.append(" ||").append("\n");
|
||||||
|
builder.append(metadata.indent()).append(indentUnit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
appendElementEquality(builder, itemType, value.id());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ItemMetaMapping.ItemPredicate.IsClassPredicate isClassPredicate: {
|
||||||
|
String itemLikeName = isClassPredicate.againstBlock() ? "blockHandle" : "itemHandle";
|
||||||
|
builder.append("(%1$s != null && %1$s.getClass().equals(%2$s))".formatted(itemLikeName, this.importCollector.getShortName(isClassPredicate.value())));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ItemMetaMapping.ItemPredicate.InstanceOfPredicate instanceOfPredicate: {
|
||||||
|
String itemLikeName = instanceOfPredicate.againstBlock() ? "blockHandle" : "itemHandle";
|
||||||
|
builder.append("%s instanceof %s".formatted(itemLikeName, this.importCollector.getShortName(instanceOfPredicate.value())));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (predicateIterator.hasNext()) {
|
||||||
|
builder.append(" ||").append("\n");
|
||||||
|
}
|
||||||
|
beginning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append(") {").append("\n");
|
||||||
|
{
|
||||||
|
builder.append(metadata.indent()).append(indentUnit);
|
||||||
|
builder.append("return %s.asType(%s);".formatted(Types.CRAFT_ITEM_METAS.simpleName(), field));
|
||||||
|
builder.append("\n");
|
||||||
|
}
|
||||||
|
builder.append(metadata.indent());
|
||||||
|
builder.append("}").append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void appendElementEquality(StringBuilder builder, ClassNamed itemType, ResourceLocation id) {
|
||||||
|
builder.append("itemType == %s.%s".formatted(itemType.simpleName(), Formatting.formatKeyAsField(id.getPath())));
|
||||||
|
}
|
||||||
|
}
|
@ -25,21 +25,21 @@ public class ItemTypeRewriter extends RegistryFieldRewriter<Item> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo shortcut and remove order rule for CraftMetaColorableArmor <-> CraftMetaArmor / CraftMetaBanner|CraftMetaSkull <-> CraftMetaBlockState (create custom tag? or just inline?)
|
// todo shortcut and remove order rule for CraftMetaColorableArmor <-> CraftMetaArmor / CraftMetaBanner|CraftMetaSkull <-> CraftMetaBlockState (create custom tag? or just inline?)
|
||||||
ClassNamed implName = null;
|
ClassNamed implMetaName = null;
|
||||||
mainLoop:
|
mainLoop:
|
||||||
for (Map.Entry<ClassNamed, List<ItemMetaMapping.ItemPredicate>> entry : ItemMetaMapping.PREDICATES.entrySet()) {
|
for (Map.Entry<ClassNamed, List<ItemMetaMapping.ItemPredicate>> entry : ItemMetaMapping.PREDICATES.entrySet()) {
|
||||||
for (ItemMetaMapping.ItemPredicate predicate : entry.getValue()) {
|
for (ItemMetaMapping.ItemPredicate predicate : entry.getValue()) {
|
||||||
if (predicate.test(reference)) {
|
if (predicate.test(reference)) {
|
||||||
implName = entry.getKey();
|
implMetaName = entry.getKey();
|
||||||
break mainLoop;
|
break mainLoop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassNamed apiName = null;
|
ClassNamed metaName = null;
|
||||||
if (implName != null) {
|
if (implMetaName != null) {
|
||||||
apiName = ItemMetaMapping.BRIDGE.get(implName).api();
|
metaName = ItemMetaMapping.BRIDGE.get(implMetaName).api();
|
||||||
}
|
}
|
||||||
return "%s<%s>".formatted(Types.ITEM_TYPE_TYPED.dottedNestedName(), apiName != null ? this.importCollector.getShortName(apiName) : Types.ITEM_META.simpleName());
|
return "%s<%s>".formatted(Types.ITEM_TYPE_TYPED.dottedNestedName(), metaName != null ? this.importCollector.getShortName(metaName) : Types.ITEM_META.simpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class ItemMetaMapping {
|
|||||||
public static final Codec<ItemPredicate> DIRECT_PREDICATE_CODEC = ItemPredicate.Type.CODEC.dispatch("type", ItemPredicate::type, type -> type.codec);
|
public static final Codec<ItemPredicate> DIRECT_PREDICATE_CODEC = ItemPredicate.Type.CODEC.dispatch("type", ItemPredicate::type, type -> type.codec);
|
||||||
public static final Codec<ItemPredicate> PREDICATE_CODEC = Codec.either(ItemPredicate.IsElementPredicate.COMPACT_CODEC, DIRECT_PREDICATE_CODEC).xmap(Either::unwrap, Either::right);
|
public static final Codec<ItemPredicate> PREDICATE_CODEC = Codec.either(ItemPredicate.IsElementPredicate.COMPACT_CODEC, DIRECT_PREDICATE_CODEC).xmap(Either::unwrap, Either::right);
|
||||||
|
|
||||||
public interface ItemPredicate {
|
public sealed interface ItemPredicate permits ItemPredicate.IsClassPredicate, ItemPredicate.InstanceOfPredicate, ItemPredicate.IsElementPredicate {
|
||||||
|
|
||||||
Type type();
|
Type type();
|
||||||
|
|
||||||
|
@ -2,16 +2,12 @@ package org.bukkit.craftbukkit.inventory;
|
|||||||
|
|
||||||
import com.destroystokyo.paper.inventory.meta.ArmorStandMeta;
|
import com.destroystokyo.paper.inventory.meta.ArmorStandMeta;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import net.minecraft.world.item.BannerItem;
|
|
||||||
import net.minecraft.world.item.BedItem;
|
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.BundleItem;
|
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.SignItem;
|
|
||||||
import net.minecraft.world.item.SpawnEggItem;
|
import net.minecraft.world.item.SpawnEggItem;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.ShulkerBoxBlock;
|
import net.minecraft.world.level.block.EntityBlock;
|
||||||
import org.bukkit.inventory.ItemType;
|
import org.bukkit.inventory.ItemType;
|
||||||
import org.bukkit.inventory.meta.ArmorMeta;
|
import org.bukkit.inventory.meta.ArmorMeta;
|
||||||
import org.bukkit.inventory.meta.AxolotlBucketMeta;
|
import org.bukkit.inventory.meta.AxolotlBucketMeta;
|
||||||
@ -165,126 +161,161 @@ public final class CraftItemMetas {
|
|||||||
if (itemType == ItemType.AIR) {
|
if (itemType == ItemType.AIR) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.EMPTY_META_DATA);
|
return CraftItemMetas.asType(CraftItemMetas.EMPTY_META_DATA);
|
||||||
}
|
}
|
||||||
|
// Start generate - CraftItemMetas#getItemMetaData
|
||||||
|
// @GeneratedFrom 1.21.5
|
||||||
if (itemType == ItemType.WRITTEN_BOOK) {
|
if (itemType == ItemType.WRITTEN_BOOK) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.SIGNED_BOOK_META_DATA);
|
return CraftItemMetas.asType(SIGNED_BOOK_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.WRITABLE_BOOK) {
|
if (itemType == ItemType.WRITABLE_BOOK) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.WRITABLE_BOOK_META_DATA);
|
return CraftItemMetas.asType(WRITABLE_BOOK_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.CREEPER_HEAD || itemType == ItemType.DRAGON_HEAD
|
if (itemType == ItemType.LEATHER_BOOTS ||
|
||||||
|| itemType == ItemType.PIGLIN_HEAD || itemType == ItemType.PLAYER_HEAD
|
itemType == ItemType.LEATHER_LEGGINGS ||
|
||||||
|| itemType == ItemType.SKELETON_SKULL || itemType == ItemType.WITHER_SKELETON_SKULL
|
itemType == ItemType.LEATHER_CHESTPLATE ||
|
||||||
|| itemType == ItemType.ZOMBIE_HEAD) {
|
itemType == ItemType.LEATHER_HELMET ||
|
||||||
return CraftItemMetas.asType(CraftItemMetas.SKULL_META_DATA);
|
itemType == ItemType.WOLF_ARMOR) {
|
||||||
|
return CraftItemMetas.asType(COLORABLE_ARMOR_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.CHAINMAIL_HELMET || itemType == ItemType.CHAINMAIL_CHESTPLATE
|
if (itemType == ItemType.LEATHER_BOOTS ||
|
||||||
|| itemType == ItemType.CHAINMAIL_LEGGINGS || itemType == ItemType.CHAINMAIL_BOOTS
|
itemType == ItemType.CHAINMAIL_BOOTS ||
|
||||||
|| itemType == ItemType.DIAMOND_HELMET || itemType == ItemType.DIAMOND_CHESTPLATE
|
itemType == ItemType.GOLDEN_BOOTS ||
|
||||||
|| itemType == ItemType.DIAMOND_LEGGINGS || itemType == ItemType.DIAMOND_BOOTS
|
itemType == ItemType.IRON_BOOTS ||
|
||||||
|| itemType == ItemType.GOLDEN_HELMET || itemType == ItemType.GOLDEN_CHESTPLATE
|
itemType == ItemType.DIAMOND_BOOTS ||
|
||||||
|| itemType == ItemType.GOLDEN_LEGGINGS || itemType == ItemType.GOLDEN_BOOTS
|
itemType == ItemType.NETHERITE_BOOTS ||
|
||||||
|| itemType == ItemType.IRON_HELMET || itemType == ItemType.IRON_CHESTPLATE
|
itemType == ItemType.LEATHER_LEGGINGS ||
|
||||||
|| itemType == ItemType.IRON_LEGGINGS || itemType == ItemType.IRON_BOOTS
|
itemType == ItemType.CHAINMAIL_LEGGINGS ||
|
||||||
|| itemType == ItemType.NETHERITE_HELMET || itemType == ItemType.NETHERITE_CHESTPLATE
|
itemType == ItemType.GOLDEN_LEGGINGS ||
|
||||||
|| itemType == ItemType.NETHERITE_LEGGINGS || itemType == ItemType.NETHERITE_BOOTS
|
itemType == ItemType.IRON_LEGGINGS ||
|
||||||
|| itemType == ItemType.TURTLE_HELMET) {
|
itemType == ItemType.DIAMOND_LEGGINGS ||
|
||||||
return CraftItemMetas.asType(CraftItemMetas.ARMOR_META_DATA);
|
itemType == ItemType.NETHERITE_LEGGINGS ||
|
||||||
}
|
itemType == ItemType.LEATHER_CHESTPLATE ||
|
||||||
if (itemType == ItemType.LEATHER_HELMET || itemType == ItemType.LEATHER_CHESTPLATE
|
itemType == ItemType.CHAINMAIL_CHESTPLATE ||
|
||||||
|| itemType == ItemType.LEATHER_LEGGINGS || itemType == ItemType.LEATHER_BOOTS
|
itemType == ItemType.GOLDEN_CHESTPLATE ||
|
||||||
|| itemType == ItemType.WOLF_ARMOR) {
|
itemType == ItemType.IRON_CHESTPLATE ||
|
||||||
return CraftItemMetas.asType(CraftItemMetas.COLORABLE_ARMOR_META_DATA);
|
itemType == ItemType.DIAMOND_CHESTPLATE ||
|
||||||
|
itemType == ItemType.NETHERITE_CHESTPLATE ||
|
||||||
|
itemType == ItemType.LEATHER_HELMET ||
|
||||||
|
itemType == ItemType.CHAINMAIL_HELMET ||
|
||||||
|
itemType == ItemType.GOLDEN_HELMET ||
|
||||||
|
itemType == ItemType.IRON_HELMET ||
|
||||||
|
itemType == ItemType.DIAMOND_HELMET ||
|
||||||
|
itemType == ItemType.NETHERITE_HELMET ||
|
||||||
|
itemType == ItemType.TURTLE_HELMET) {
|
||||||
|
return CraftItemMetas.asType(ARMOR_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.LEATHER_HORSE_ARMOR) {
|
if (itemType == ItemType.LEATHER_HORSE_ARMOR) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.LEATHER_ARMOR_META_DATA);
|
return CraftItemMetas.asType(LEATHER_ARMOR_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.POTION || itemType == ItemType.SPLASH_POTION
|
if (itemType == ItemType.POTION ||
|
||||||
|| itemType == ItemType.LINGERING_POTION || itemType == ItemType.TIPPED_ARROW) {
|
itemType == ItemType.SPLASH_POTION ||
|
||||||
return CraftItemMetas.asType(CraftItemMetas.POTION_META_DATA);
|
itemType == ItemType.LINGERING_POTION ||
|
||||||
|
itemType == ItemType.TIPPED_ARROW) {
|
||||||
|
return CraftItemMetas.asType(POTION_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.FILLED_MAP) {
|
if (itemType == ItemType.FILLED_MAP) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.MAP_META_DATA);
|
return CraftItemMetas.asType(MAP_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.FIREWORK_ROCKET) {
|
if (itemType == ItemType.FIREWORK_ROCKET) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.FIREWORK_META_DATA);
|
return CraftItemMetas.asType(FIREWORK_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.FIREWORK_STAR) {
|
if (itemType == ItemType.FIREWORK_STAR) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.CHARGE_META_DATA);
|
return CraftItemMetas.asType(CHARGE_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.ENCHANTED_BOOK) {
|
if (itemType == ItemType.ENCHANTED_BOOK) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.ENCHANTED_BOOK_META_DATA);
|
return CraftItemMetas.asType(ENCHANTED_BOOK_META_DATA);
|
||||||
}
|
|
||||||
if (itemHandle instanceof BannerItem) {
|
|
||||||
return CraftItemMetas.asType(CraftItemMetas.BANNER_META_DATA);
|
|
||||||
}
|
}
|
||||||
if (itemHandle instanceof SpawnEggItem) {
|
if (itemHandle instanceof SpawnEggItem) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.SPAWN_EGG_META_DATA);
|
return CraftItemMetas.asType(SPAWN_EGG_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.ARMOR_STAND) {
|
if (itemType == ItemType.ARMOR_STAND) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.ARMOR_STAND_META_DATA);
|
return CraftItemMetas.asType(ARMOR_STAND_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.KNOWLEDGE_BOOK) {
|
if (itemType == ItemType.KNOWLEDGE_BOOK) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.KNOWLEDGE_BOOK_META_DATA);
|
return CraftItemMetas.asType(KNOWLEDGE_BOOK_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.FURNACE || itemType == ItemType.CHEST
|
if (itemType == ItemType.PLAYER_HEAD ||
|
||||||
|| itemType == ItemType.TRAPPED_CHEST || itemType == ItemType.JUKEBOX
|
itemType == ItemType.CREEPER_HEAD ||
|
||||||
|| itemType == ItemType.DISPENSER || itemType == ItemType.DROPPER
|
itemType == ItemType.ZOMBIE_HEAD ||
|
||||||
|| itemHandle instanceof SignItem || itemType == ItemType.SPAWNER
|
itemType == ItemType.SKELETON_SKULL ||
|
||||||
|| itemType == ItemType.BREWING_STAND || itemType == ItemType.ENCHANTING_TABLE
|
itemType == ItemType.WITHER_SKELETON_SKULL ||
|
||||||
|| itemType == ItemType.COMMAND_BLOCK || itemType == ItemType.REPEATING_COMMAND_BLOCK
|
itemType == ItemType.DRAGON_HEAD ||
|
||||||
|| itemType == ItemType.CHAIN_COMMAND_BLOCK || itemType == ItemType.BEACON
|
itemType == ItemType.PIGLIN_HEAD) {
|
||||||
|| itemType == ItemType.DAYLIGHT_DETECTOR || itemType == ItemType.HOPPER
|
return CraftItemMetas.asType(SKULL_META_DATA);
|
||||||
|| itemType == ItemType.COMPARATOR || itemType == ItemType.STRUCTURE_BLOCK
|
}
|
||||||
|| blockHandle instanceof ShulkerBoxBlock
|
if (itemType == ItemType.WHITE_BANNER ||
|
||||||
|| itemType == ItemType.ENDER_CHEST || itemType == ItemType.BARREL
|
itemType == ItemType.ORANGE_BANNER ||
|
||||||
|| itemType == ItemType.BELL || itemType == ItemType.BLAST_FURNACE
|
itemType == ItemType.MAGENTA_BANNER ||
|
||||||
|| itemType == ItemType.CAMPFIRE || itemType == ItemType.SOUL_CAMPFIRE
|
itemType == ItemType.LIGHT_BLUE_BANNER ||
|
||||||
|| itemType == ItemType.JIGSAW || itemType == ItemType.LECTERN
|
itemType == ItemType.YELLOW_BANNER ||
|
||||||
|| itemType == ItemType.SMOKER || itemType == ItemType.BEEHIVE
|
itemType == ItemType.LIME_BANNER ||
|
||||||
|| itemType == ItemType.BEE_NEST || itemType == ItemType.SCULK_CATALYST
|
itemType == ItemType.PINK_BANNER ||
|
||||||
|| itemType == ItemType.SCULK_SHRIEKER || itemType == ItemType.SCULK_SENSOR
|
itemType == ItemType.GRAY_BANNER ||
|
||||||
|| itemType == ItemType.CALIBRATED_SCULK_SENSOR || itemType == ItemType.CHISELED_BOOKSHELF
|
itemType == ItemType.LIGHT_GRAY_BANNER ||
|
||||||
|| itemType == ItemType.DECORATED_POT || itemType == ItemType.SUSPICIOUS_SAND
|
itemType == ItemType.CYAN_BANNER ||
|
||||||
|| itemType == ItemType.SUSPICIOUS_GRAVEL || itemType == ItemType.CRAFTER
|
itemType == ItemType.PURPLE_BANNER ||
|
||||||
|| itemType == ItemType.TRIAL_SPAWNER || itemType == ItemType.VAULT
|
itemType == ItemType.BLUE_BANNER ||
|
||||||
|| itemType == ItemType.CREAKING_HEART || itemType == ItemType.TEST_BLOCK
|
itemType == ItemType.BROWN_BANNER ||
|
||||||
|| itemType == ItemType.TEST_INSTANCE_BLOCK || itemType == ItemType.CONDUIT
|
itemType == ItemType.GREEN_BANNER ||
|
||||||
|| itemHandle instanceof BedItem) {
|
itemType == ItemType.RED_BANNER ||
|
||||||
return CraftItemMetas.asType(CraftItemMetas.BLOCK_STATE_META_DATA);
|
itemType == ItemType.BLACK_BANNER) {
|
||||||
|
return CraftItemMetas.asType(BANNER_META_DATA);
|
||||||
|
}
|
||||||
|
if (blockHandle instanceof EntityBlock) {
|
||||||
|
return CraftItemMetas.asType(BLOCK_STATE_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.SHIELD) {
|
if (itemType == ItemType.SHIELD) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.SHIELD_META_DATA);
|
return CraftItemMetas.asType(SHIELD_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.TROPICAL_FISH_BUCKET) {
|
if (itemType == ItemType.TROPICAL_FISH_BUCKET) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.TROPICAL_FISH_BUCKET_META_DATA);
|
return CraftItemMetas.asType(TROPICAL_FISH_BUCKET_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.AXOLOTL_BUCKET) {
|
if (itemType == ItemType.AXOLOTL_BUCKET) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.AXOLOTL_BUCKET_META_DATA);
|
return CraftItemMetas.asType(AXOLOTL_BUCKET_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.CROSSBOW) {
|
if (itemType == ItemType.CROSSBOW) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.CROSSBOW_META_DATA);
|
return CraftItemMetas.asType(CROSSBOW_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.SUSPICIOUS_STEW) {
|
if (itemType == ItemType.SUSPICIOUS_STEW) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.SUSPICIOUS_STEW_META_DATA);
|
return CraftItemMetas.asType(SUSPICIOUS_STEW_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.COD_BUCKET || itemType == ItemType.PUFFERFISH_BUCKET || itemType == ItemType.TADPOLE_BUCKET
|
if (itemType == ItemType.COD_BUCKET ||
|
||||||
|| itemType == ItemType.SALMON_BUCKET || itemType == ItemType.ITEM_FRAME
|
itemType == ItemType.PUFFERFISH_BUCKET ||
|
||||||
|| itemType == ItemType.GLOW_ITEM_FRAME || itemType == ItemType.PAINTING) {
|
itemType == ItemType.TADPOLE_BUCKET ||
|
||||||
return CraftItemMetas.asType(CraftItemMetas.ENTITY_TAG_META_DATA);
|
itemType == ItemType.SALMON_BUCKET ||
|
||||||
|
itemType == ItemType.ITEM_FRAME ||
|
||||||
|
itemType == ItemType.GLOW_ITEM_FRAME ||
|
||||||
|
itemType == ItemType.PAINTING) {
|
||||||
|
return CraftItemMetas.asType(ENTITY_TAG_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.COMPASS) {
|
if (itemType == ItemType.COMPASS) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.COMPASS_META_DATA);
|
return CraftItemMetas.asType(COMPASS_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemHandle instanceof BundleItem) {
|
if (itemType == ItemType.BUNDLE ||
|
||||||
return CraftItemMetas.asType(CraftItemMetas.BUNDLE_META_DATA);
|
itemType == ItemType.BLACK_BUNDLE ||
|
||||||
|
itemType == ItemType.BLUE_BUNDLE ||
|
||||||
|
itemType == ItemType.BROWN_BUNDLE ||
|
||||||
|
itemType == ItemType.CYAN_BUNDLE ||
|
||||||
|
itemType == ItemType.GRAY_BUNDLE ||
|
||||||
|
itemType == ItemType.GREEN_BUNDLE ||
|
||||||
|
itemType == ItemType.LIGHT_BLUE_BUNDLE ||
|
||||||
|
itemType == ItemType.LIGHT_GRAY_BUNDLE ||
|
||||||
|
itemType == ItemType.LIME_BUNDLE ||
|
||||||
|
itemType == ItemType.MAGENTA_BUNDLE ||
|
||||||
|
itemType == ItemType.ORANGE_BUNDLE ||
|
||||||
|
itemType == ItemType.PINK_BUNDLE ||
|
||||||
|
itemType == ItemType.PURPLE_BUNDLE ||
|
||||||
|
itemType == ItemType.RED_BUNDLE ||
|
||||||
|
itemType == ItemType.YELLOW_BUNDLE ||
|
||||||
|
itemType == ItemType.WHITE_BUNDLE) {
|
||||||
|
return CraftItemMetas.asType(BUNDLE_META_DATA);
|
||||||
}
|
}
|
||||||
if (itemType == ItemType.GOAT_HORN) {
|
if (itemType == ItemType.GOAT_HORN) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.MUSIC_INSTRUMENT_META_DATA);
|
return CraftItemMetas.asType(MUSIC_INSTRUMENT_META_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemType == ItemType.OMINOUS_BOTTLE) {
|
if (itemType == ItemType.OMINOUS_BOTTLE) {
|
||||||
return CraftItemMetas.asType(CraftItemMetas.OMINOUS_BOTTLE_META_DATA);
|
return CraftItemMetas.asType(OMINOUS_BOTTLE_META_DATA);
|
||||||
}
|
}
|
||||||
|
// End generate - CraftItemMetas#getItemMetaData
|
||||||
|
|
||||||
return CraftItemMetas.asType(CraftItemMetas.ITEM_META_DATA);
|
return CraftItemMetas.asType(CraftItemMetas.ITEM_META_DATA);
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,13 @@ package org.bukkit.craftbukkit.inventory;
|
|||||||
import static org.bukkit.support.MatcherAssert.*;
|
import static org.bukkit.support.MatcherAssert.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.world.item.BlockItem;
|
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.StandingAndWallBlockItem;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.EntityBlock;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
@ -41,7 +37,6 @@ import org.bukkit.inventory.meta.ArmorMeta;
|
|||||||
import org.bukkit.inventory.meta.AxolotlBucketMeta;
|
import org.bukkit.inventory.meta.AxolotlBucketMeta;
|
||||||
import org.bukkit.inventory.meta.BannerMeta;
|
import org.bukkit.inventory.meta.BannerMeta;
|
||||||
import org.bukkit.inventory.meta.BlockDataMeta;
|
import org.bukkit.inventory.meta.BlockDataMeta;
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
import org.bukkit.inventory.meta.BundleMeta;
|
import org.bukkit.inventory.meta.BundleMeta;
|
||||||
import org.bukkit.inventory.meta.ColorableArmorMeta;
|
import org.bukkit.inventory.meta.ColorableArmorMeta;
|
||||||
@ -54,7 +49,6 @@ import org.bukkit.inventory.meta.KnowledgeBookMeta;
|
|||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
import org.bukkit.inventory.meta.MapMeta;
|
import org.bukkit.inventory.meta.MapMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.bukkit.inventory.meta.SpawnEggMeta;
|
|
||||||
import org.bukkit.inventory.meta.TropicalFishBucketMeta;
|
import org.bukkit.inventory.meta.TropicalFishBucketMeta;
|
||||||
import org.bukkit.inventory.meta.trim.ArmorTrim;
|
import org.bukkit.inventory.meta.trim.ArmorTrim;
|
||||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||||
@ -157,64 +151,12 @@ public class ItemMetaTest {
|
|||||||
assertThat(bukkit, is(craft));
|
assertThat(bukkit, is(craft));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBlockStateMeta() {
|
|
||||||
List<Block> queue = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Item item : BuiltInRegistries.ITEM) {
|
|
||||||
if (item instanceof BlockItem) {
|
|
||||||
queue.add(((BlockItem) item).getBlock());
|
|
||||||
}
|
|
||||||
if (item instanceof StandingAndWallBlockItem) {
|
|
||||||
queue.add(((StandingAndWallBlockItem) item).wallBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Block block : queue) {
|
|
||||||
if (block != null) {
|
|
||||||
ItemStack stack = CraftItemStack.asNewCraftStack(Item.byBlock(block));
|
|
||||||
|
|
||||||
// Command blocks aren't unit testable atm
|
|
||||||
if (stack.getType() == Material.COMMAND_BLOCK || stack.getType() == Material.CHAIN_COMMAND_BLOCK || stack.getType() == Material.REPEATING_COMMAND_BLOCK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemMeta meta = stack.getItemMeta();
|
|
||||||
if (block instanceof EntityBlock) {
|
|
||||||
assertTrue(meta instanceof BlockStateMeta, stack + " has meta of type " + meta + " expected BlockStateMeta");
|
|
||||||
|
|
||||||
BlockStateMeta blockState = (BlockStateMeta) meta;
|
|
||||||
assertNotNull(blockState.getBlockState(), stack + " has null block state");
|
|
||||||
|
|
||||||
blockState.setBlockState(blockState.getBlockState());
|
|
||||||
} else {
|
|
||||||
assertFalse(meta instanceof BlockStateMeta, stack + " has unexpected meta of type BlockStateMeta (but is not a tile)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSpawnEggsHasMeta() {
|
|
||||||
for (Item item : BuiltInRegistries.ITEM) {
|
|
||||||
if (item instanceof net.minecraft.world.item.SpawnEggItem) {
|
|
||||||
Material material = CraftItemType.minecraftToBukkit(item);
|
|
||||||
CraftMetaItem baseMeta = (CraftMetaItem) Bukkit.getItemFactory().getItemMeta(material);
|
|
||||||
ItemMeta baseMetaItem = CraftItemStack.getItemMeta(item.getDefaultInstance());
|
|
||||||
|
|
||||||
assertTrue(baseMeta instanceof CraftMetaSpawnEgg, material + " is not handled in CraftItemFactory");
|
|
||||||
assertTrue(baseMeta.applicableTo(material), material + " is not applicable to CraftMetaSpawnEgg");
|
|
||||||
assertTrue(baseMetaItem instanceof SpawnEggMeta, material + " is not handled in CraftItemStack");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Paper start - check entity tag metas
|
|
||||||
private static final java.util.Set<Class<?>> ENTITY_TAG_METAS = java.util.Set.of(
|
private static final java.util.Set<Class<?>> ENTITY_TAG_METAS = java.util.Set.of(
|
||||||
CraftMetaEntityTag.class,
|
CraftMetaEntityTag.class,
|
||||||
CraftMetaTropicalFishBucket.class,
|
CraftMetaTropicalFishBucket.class,
|
||||||
CraftMetaAxolotlBucket.class
|
CraftMetaAxolotlBucket.class
|
||||||
);
|
);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityTagMeta() {
|
public void testEntityTagMeta() {
|
||||||
for (final Item item : BuiltInRegistries.ITEM) {
|
for (final Item item : BuiltInRegistries.ITEM) {
|
||||||
@ -228,7 +170,6 @@ public class ItemMetaTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Paper end
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEachExtraData() {
|
public void testEachExtraData() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user