Search in sources :

Example 51 with Item

use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.

the class NMSHandler method setSpawnersUnstackable.

@Override
public void setSpawnersUnstackable() {
    try {
        final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
        final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
        maxStackSize.setAccessible(true);
        maxStackSize.set(spawner, 1);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_16_R2.Item) Field(java.lang.reflect.Field) MinecraftKey(net.minecraft.server.v1_16_R2.MinecraftKey)

Example 52 with Item

use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.

the class NMSHandler method getVanillaNBTEntityID.

@Override
@Nullable
public String getVanillaNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_16_R2.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("BlockEntityTag")) {
        return null;
    }
    tag = tag.getCompound("BlockEntityTag");
    if (tag.hasKey("EntityId")) {
        return tag.getString("EntityId");
    } else if (tag.hasKey("SpawnData") && tag.getCompound("SpawnData").hasKey("id")) {
        return tag.getCompound("SpawnData").getString("id");
    } else if (tag.hasKey("SpawnPotentials") && !tag.getList("SpawnPotentials", 8).isEmpty()) {
        return tag.getList("SpawnPotentials", 8).getCompound(0).getCompound("Entity").getString("id");
    } else {
        return null;
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 53 with Item

use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.

the class NMSHandler method setSpawnersUnstackable.

@Override
public void setSpawnersUnstackable() {
    try {
        final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
        final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
        maxStackSize.setAccessible(true);
        maxStackSize.set(spawner, 1);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_16_R3.Item) Field(java.lang.reflect.Field) MinecraftKey(net.minecraft.server.v1_16_R3.MinecraftKey)

Example 54 with Item

use of net.minecraft.server.v1_16_R2.Item in project PaperDev by Kamillaova.

the class MaterialTest method verifyMapping.

@Test
public void verifyMapping() {
    Map<Integer, Material> materials = Maps.newHashMap();
    for (Material material : Material.values()) {
        if (INVALIDATED_MATERIALS.contains(material)) {
            continue;
        }
        materials.put(material.getId(), material);
    }
    Iterator<Item> items = Item.REGISTRY.iterator();
    while (items.hasNext()) {
        Item item = items.next();
        if (item == null)
            continue;
        int id = CraftMagicNumbers.getId(item);
        String name = item.getName();
        Material material = materials.remove(id);
        assertThat("Missing " + name + "(" + id + ")", material, is(not(nullValue())));
    }
    assertThat(materials, is(Collections.EMPTY_MAP));
}
Also used : Item(net.minecraft.server.v1_12_R1.Item) Test(org.junit.Test)

Example 55 with Item

use of net.minecraft.server.v1_16_R2.Item in project PaperDev by Kamillaova.

the class CraftStatistic method getMaterialFromStatistic.

public static Material getMaterialFromStatistic(net.minecraft.server.v1_12_R1.Statistic statistic) {
    String statisticString = statistic.name;
    String val = statisticString.substring(statisticString.lastIndexOf(".") + 1);
    Item item = (Item) Item.REGISTRY.get(new MinecraftKey(val));
    if (item != null) {
        return Material.getMaterial(Item.getId(item));
    }
    Block block = (Block) Block.REGISTRY.get(new MinecraftKey(val));
    if (block != null) {
        return Material.getMaterial(Block.getId(block));
    }
    try {
        return Material.getMaterial(Integer.parseInt(val));
    } catch (NumberFormatException e) {
        return null;
    }
}
Also used : Item(net.minecraft.server.v1_12_R1.Item) Block(net.minecraft.server.v1_12_R1.Block) MinecraftKey(net.minecraft.server.v1_12_R1.MinecraftKey)

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 CraftItemStack (org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack)9 ItemStack (org.bukkit.inventory.ItemStack)9 Test (org.junit.Test)7 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 Field (java.lang.reflect.Field)6 Item (net.minecraft.server.v1_12_R1.Item)5 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)5 Items (org.orcid.jaxb.model.notification.permission_v2.Items)5 CraftPlayer (org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer)4 ArrayList (java.util.ArrayList)3 Container (net.minecraft.server.v1_16_R2.Container)3 Font (java.awt.Font)2 Point (java.awt.Point)2 Nullable (javax.annotation.Nullable)2 Block (net.minecraft.server.v1_12_R1.Block)2 Item (net.minecraft.server.v1_13_R2.Item)2 Item (net.minecraft.server.v1_14_R1.Item)2 Item (net.minecraft.server.v1_15_R1.Item)2 ContainerAnvil (net.minecraft.server.v1_16_R2.ContainerAnvil)2