Search in sources :

Example 46 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project TheAPI by TheDevTec.

the class v1_12_R1 method openAnvilGUI.

@Override
public void openAnvilGUI(Player player, Object con, String title, ItemStack[] items) {
    ContainerAnvil container = (ContainerAnvil) con;
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = container.windowId;
    net.minecraft.server.v1_12_R1.ItemStack[] nmsItems = new net.minecraft.server.v1_12_R1.ItemStack[items.length];
    for (int i = 0; i < items.length; ++i) {
        ItemStack is = items[i];
        if (is == null || is.getType() == Material.AIR)
            continue;
        net.minecraft.server.v1_12_R1.ItemStack item = null;
        container.setItem(i, item = (net.minecraft.server.v1_12_R1.ItemStack) asNMSItem(is));
        nmsItems[i] = item;
    }
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, "minecraft:anvil", 0, title));
    int i = 0;
    for (net.minecraft.server.v1_12_R1.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
    nmsPlayer.activeContainer.transferTo((Container) container, (CraftPlayer) player);
    nmsPlayer.activeContainer = (Container) container;
    ((Container) container).addSlotListener(nmsPlayer);
    container.checkReachable = false;
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer) Container(net.minecraft.server.v1_12_R1.Container) ContainerAnvil(net.minecraft.server.v1_12_R1.ContainerAnvil) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 47 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method setItem.

@Override
public void setItem(int index, ItemStack item) {
    // Instead of updating one container, update all the containers
    // That are looking at the table, basically the viewers
    items.set(index, item == null ? ItemStack.a : item);
    for (Container container : containers) {
        container.a(this);
    }
    // Update the armorstand grid
    display.update();
}
Also used : SelfContainer(io.github.bananapuncher714.crafters.implementation.v1_12_R1.ContainerManager_v1_12_R1.SelfContainer) Container(net.minecraft.server.v1_12_R1.Container)

Example 48 with Item

use of net.minecraft.server.v1_12_R1.DataWatcher.Item in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method remove.

@Override
public void remove() {
    display.stop();
    for (ItemStack item : items) {
        org.bukkit.inventory.ItemStack is = CraftItemStack.asBukkitCopy(item);
        if (is.getType() != Material.AIR) {
            bloc.getWorld().dropItem(bloc.clone().add(.5, .9, .5), is);
        }
    }
    items.clear();
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack)

Example 49 with Item

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

the class NMSHandler method getSilkSpawnersNBTEntityID.

@Override
@Nullable
public String getSilkSpawnersNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_12_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;
    }
    final NBTTagCompound silkSpawnersTag = tag.getCompound("SilkSpawners");
    if (silkSpawnersTag.hasKey("entity")) {
        return silkSpawnersTag.getString("entity");
    }
    if (silkSpawnersTag.hasKey("entityID")) {
        return getEntityFromNumericalID(silkSpawnersTag.getShort("entityID"));
    }
    return null;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 50 with Item

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

the class NMSHandler method getVanillaNBTEntityID.

@Override
public String getVanillaNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_12_R1.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).get(0).getCompound("Entity").getString("id");
    } else {
        return null;
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)30 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)27 ItemStack (org.bukkit.inventory.ItemStack)22 ItemMeta (org.bukkit.inventory.meta.ItemMeta)12 ArrayList (java.util.ArrayList)10 Player (org.bukkit.entity.Player)9 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)8 ChannelPromise (io.netty.channel.ChannelPromise)8 PreparedStatement (java.sql.PreparedStatement)7 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)7 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 Item (net.minecraft.server.v1_12_R1.Item)5 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)5 Location (org.bukkit.Location)5 OfflinePlayer (org.bukkit.OfflinePlayer)5 PlayerInventory (org.bukkit.inventory.PlayerInventory)5