Search in sources :

Example 21 with Item

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

the class NMSHandler method setNBTEntityID.

@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
    if (item == null || StringUtils.isBlank(entity)) {
        Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
        return null;
    }
    String prefixedEntity;
    if (!entity.startsWith("minecraft:")) {
        prefixedEntity = "minecraft:" + entity;
    } else {
        prefixedEntity = entity;
    }
    net.minecraft.server.v1_16_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getOrCreateTag();
    // Check for SilkSpawners key
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    // Check for Vanilla keys
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag = tag.getCompound("BlockEntityTag");
    // EntityId - Deprecated in 1.9
    tag.setString("EntityId", entity);
    tag.setString("id", TileEntityTypes.a(TileEntityTypes.MOB_SPAWNER).getKey());
    // SpawnData
    if (!tag.hasKey("SpawnData")) {
        tag.set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("SpawnData").setString("id", prefixedEntity);
    if (!tag.hasKey("SpawnPotentials")) {
        tag.set("SpawnPotentials", new NBTTagCompound());
    }
    // SpawnEgg data
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    tag.getCompound("EntityTag").setString("id", prefixedEntity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_16_R1.NBTTagCompound)

Example 22 with Item

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

the class NMSHandler method getSilkSpawnersNBTEntityID.

@Override
@Nullable
public String getSilkSpawnersNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_16_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    final NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("SilkSpawners")) {
        return null;
    }
    return tag.getCompound("SilkSpawners").getString("entity");
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_16_R1.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 23 with Item

use of net.minecraft.server.v1_16_R1.Item in project PGM by PGMDev.

the class NMSHacks method canMineBlock.

/**
 * Test if the given tool is capable of "efficiently" mining the given block.
 *
 * <p>Derived from CraftBlock.itemCausesDrops()
 */
static boolean canMineBlock(MaterialData blockMaterial, ItemStack tool) {
    if (!blockMaterial.getItemType().isBlock()) {
        throw new IllegalArgumentException("Material '" + blockMaterial + "' is not a block");
    }
    net.minecraft.server.v1_8_R3.Block nmsBlock = CraftMagicNumbers.getBlock(blockMaterial.getItemType());
    net.minecraft.server.v1_8_R3.Item nmsTool = tool == null ? null : CraftMagicNumbers.getItem(tool.getType());
    return nmsBlock != null && (nmsBlock.getMaterial().isAlwaysDestroyable() || (nmsTool != null && nmsTool.canDestroySpecialBlock(nmsBlock)));
}
Also used : Item(net.minecraft.server.v1_8_R3.Item) net.minecraft.server.v1_8_R3(net.minecraft.server.v1_8_R3)

Example 24 with Item

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

the class CraftItemStack method asNMSCopy.

public static net.minecraft.server.v1_12_R1.ItemStack asNMSCopy(ItemStack original) {
    if (original instanceof CraftItemStack) {
        CraftItemStack stack = (CraftItemStack) original;
        return stack.handle == null ? net.minecraft.server.v1_12_R1.ItemStack.a : stack.handle.cloneItemStack();
    }
    if (original == null || original.getTypeId() <= 0) {
        return net.minecraft.server.v1_12_R1.ItemStack.a;
    }
    Item item = CraftMagicNumbers.getItem(original.getType());
    if (item == null) {
        return net.minecraft.server.v1_12_R1.ItemStack.a;
    }
    net.minecraft.server.v1_12_R1.ItemStack stack = new net.minecraft.server.v1_12_R1.ItemStack(item, original.getAmount(), original.getDurability(), false);
    if (original.hasItemMeta()) {
        setItemMeta(stack, original.getItemMeta());
    } else {
        // Converted after setItemMeta
        stack.convertStack();
    }
    return stack;
}
Also used : Item(net.minecraft.server.v1_12_R1.Item) ItemStack(org.bukkit.inventory.ItemStack)

Example 25 with Item

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

the class ItemMetaTest method testBlockStateMeta.

@Test
public void testBlockStateMeta() {
    for (Item item : (Iterable<Item>) Item.REGISTRY) {
        Block block = null;
        if (item instanceof ItemBlock) {
            block = ((ItemBlock) item).getBlock();
        } else if (item instanceof ItemReed) {
            block = ((ItemReed) item).a;
        }
        if (block != null) {
            if (block instanceof ITileEntity) {
                ItemStack stack = CraftItemStack.asNewCraftStack(Item.getItemOf(block));
                // Command blocks aren't unit testable atm
                if (stack.getType() == Material.AIR || stack.getType() == Material.COMMAND || stack.getType() == Material.COMMAND_CHAIN || stack.getType() == Material.COMMAND_REPEATING) {
                    return;
                }
                ItemMeta meta = stack.getItemMeta();
                assertTrue(stack + " has meta of type " + meta + " expected BlockStateMeta", meta instanceof BlockStateMeta);
                BlockStateMeta blockState = (BlockStateMeta) meta;
                assertNotNull(stack + " has null block state", blockState.getBlockState());
                blockState.setBlockState(blockState.getBlockState());
            }
        }
    }
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) Item(net.minecraft.server.v1_12_R1.Item) ITileEntity(net.minecraft.server.v1_12_R1.ITileEntity) Block(net.minecraft.server.v1_12_R1.Block) ItemBlock(net.minecraft.server.v1_12_R1.ItemBlock) ItemBlock(net.minecraft.server.v1_12_R1.ItemBlock) ItemStack(org.bukkit.inventory.ItemStack) ItemReed(net.minecraft.server.v1_12_R1.ItemReed) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Test(org.junit.Test)

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 CraftItemStack (org.bukkit.craftbukkit.v1_16_R1.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_R1.NBTTagCompound)5 Items (org.orcid.jaxb.model.notification.permission_v2.Items)5 Container (net.minecraft.server.v1_16_R1.Container)3 CraftPlayer (org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer)3 Font (java.awt.Font)2 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)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_R1.ContainerAnvil)2