use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaItem in project Mohist by MohistMC.
the class CraftItemStack method setItemMeta.
public static boolean setItemMeta(net.minecraft.world.item.ItemStack item, ItemMeta itemMeta) {
if (item == null) {
return false;
}
if (CraftItemFactory.instance().equals(itemMeta, null)) {
item.setTag(null);
return true;
}
if (!CraftItemFactory.instance().isApplicable(itemMeta, getType(item))) {
return false;
}
itemMeta = CraftItemFactory.instance().asMetaFor(itemMeta, getType(item));
if (itemMeta == null)
return true;
Item oldItem = item.getItem();
Item newItem = CraftMagicNumbers.getItem(CraftItemFactory.instance().updateMaterial(itemMeta, CraftMagicNumbers.getMaterial(oldItem)));
if (oldItem != newItem) {
item.setItem(newItem);
}
CompoundTag tag = new CompoundTag();
item.setTag(tag);
((CraftMetaItem) itemMeta).applyToItem(tag);
item.convertStack(((CraftMetaItem) itemMeta).getVersion());
// SpigotCraft#463 this is required now by the Vanilla client, so mimic ItemStack constructor in ensuring it
if (item.getItem() != null && item.getItem().canBeDepleted()) {
item.setDamageValue(item.getDamageValue());
}
return true;
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaItem in project Magma by magmafoundation.
the class ItemMetaImplementationOverrideTest method data.
@Parameters(name = "[{index}]:{1}")
public static List<Object[]> data() {
final List<Object[]> testData = new ArrayList<Object[]>();
List<Class<? extends CraftMetaItem>> classes = new ArrayList<Class<? extends CraftMetaItem>>();
for (Material material : ItemStackTest.COMPOUND_MATERIALS) {
Class<? extends CraftMetaItem> clazz = CraftItemFactory.instance().getItemMeta(material).getClass().asSubclass(parent);
if (clazz != parent) {
classes.add(clazz);
}
}
List<Method> list = new ArrayList<Method>();
for (Method method : parent.getDeclaredMethods()) {
if (method.isAnnotationPresent(Overridden.class)) {
list.add(method);
}
}
for (final Class<?> clazz : classes) {
for (final Method method : list) {
testData.add(new Object[] { new Callable<Method>() {
public Method call() throws Exception {
return clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
}
}, clazz.getSimpleName() + " contains " + method.getName() });
}
testData.add(new Object[] { new Callable<DelegateDeserialization>() {
public DelegateDeserialization call() throws Exception {
return clazz.getAnnotation(DelegateDeserialization.class);
}
}, clazz.getSimpleName() + " contains annotation " + DelegateDeserialization.class });
}
return testData;
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaItem in project Magma by magmafoundation.
the class FactoryItemMaterialTest method generalCase.
@Test
public void generalCase() {
CraftMetaItem meta = (CraftMetaItem) factory.getItemMeta(material);
if (meta == null) {
assertThat(material, is(Material.AIR));
} else {
assertTrue(factory.isApplicable(meta, material));
assertTrue(meta.applicableTo(material));
meta = meta.clone();
assertTrue(factory.isApplicable(meta, material));
assertTrue(meta.applicableTo(material));
}
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaItem in project Magma by magmafoundation.
the class FactoryItemMaterialTest method asMetaFor.
@Ignore
@Test
public void asMetaFor() {
final CraftMetaItem baseMeta = (CraftMetaItem) factory.getItemMeta(material);
if (baseMeta == null) {
assertThat(material, is(Material.AIR));
return;
}
for (Material other : materials) {
final ItemStack bukkitStack = new ItemStack(other);
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(bukkitStack);
final CraftMetaItem otherMeta = (CraftMetaItem) factory.asMetaFor(baseMeta, other);
final String testName = name(material, other);
if (otherMeta == null) {
assertThat(testName, other, is(Material.AIR));
continue;
}
assertTrue(testName, factory.isApplicable(otherMeta, craftStack));
assertTrue(testName, factory.isApplicable(otherMeta, bukkitStack));
assertTrue(testName, factory.isApplicable(otherMeta, other));
assertTrue(testName, otherMeta.applicableTo(other));
}
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaItem in project Magma by magmafoundation.
the class FactoryItemMaterialTest method blankEqualities.
@Test
public void blankEqualities() {
if (material == Material.AIR) {
return;
}
final CraftMetaItem baseMeta = (CraftMetaItem) factory.getItemMeta(material);
final CraftMetaItem baseMetaClone = baseMeta.clone();
final ItemStack baseMetaStack = new ItemStack(material);
baseMetaStack.setItemMeta(baseMeta);
assertThat(baseMeta, is(not(sameInstance(baseMetaStack.getItemMeta()))));
assertTrue(factory.equals(baseMeta, null));
assertTrue(factory.equals(null, baseMeta));
assertTrue(factory.equals(baseMeta, baseMetaClone));
assertTrue(factory.equals(baseMetaClone, baseMeta));
assertThat(baseMeta, is(not(sameInstance(baseMetaClone))));
assertThat(baseMeta, is(baseMetaClone));
assertThat(baseMetaClone, is(baseMeta));
for (Material other : materials) {
final String testName = name(material, other);
final CraftMetaItem otherMeta = (CraftMetaItem) factory.asMetaFor(baseMetaClone, other);
if (otherMeta == null) {
assertThat(testName, other, is(Material.AIR));
continue;
}
assertTrue(testName, factory.equals(baseMeta, otherMeta));
assertTrue(testName, factory.equals(otherMeta, baseMeta));
assertThat(testName, baseMeta, is(otherMeta));
assertThat(testName, otherMeta, is(baseMeta));
assertThat(testName, baseMeta.hashCode(), is(otherMeta.hashCode()));
}
}
Aggregations