Search in sources :

Example 6 with net.minecraft.server.v1_16_R2

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

the class NMSHandler method getVanillaEggNBTEntityID.

@Override
public String getVanillaEggNBTEntityID(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("EntityTag")) {
        final MinecraftKey vanillaKey = IRegistry.ITEM.getKey(itemStack.getItem());
        if (vanillaKey != null) {
            return vanillaKey.getKey().replace("minecraft:", "").replace("_spawn_egg", "");
        }
    } else {
        tag = tag.getCompound("EntityTag");
        if (tag.hasKey("id")) {
            return tag.getString("id").replace("minecraft:", "");
        }
    }
    return null;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound) MinecraftKey(net.minecraft.server.v1_16_R2.MinecraftKey)

Example 7 with net.minecraft.server.v1_16_R2

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

the class NMSHandler method newEggItem.

@SuppressWarnings("deprecation")
@Override
public ItemStack newEggItem(final String entityID, final int amount, final String displayName) {
    Material spawnEgg = Material.matchMaterial(entityID.toUpperCase() + "_SPAWN_EGG");
    if (spawnEgg == null) {
        spawnEgg = Material.LEGACY_MONSTER_EGG;
    }
    final ItemStack item = new ItemStack(spawnEgg, amount);
    if (displayName != null) {
        final ItemMeta itemMeta = item.getItemMeta();
        itemMeta.setDisplayName(displayName);
        item.setItemMeta(itemMeta);
    }
    net.minecraft.server.v1_16_R2.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    final NBTTagCompound tag = itemStack.getOrCreateTag();
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entityID);
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    String prefixedEntity;
    if (!entityID.startsWith("minecraft:")) {
        prefixedEntity = "minecraft:" + entityID;
    } else {
        prefixedEntity = entityID;
    }
    tag.getCompound("EntityTag").setString("id", prefixedEntity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound) Material(org.bukkit.Material) CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 8 with net.minecraft.server.v1_16_R2

use of net.minecraft.server.v1_16_R2 in project TheAPI by TheDevTec.

the class v1_16_R2 method openGUI.

@Override
public void openGUI(Player player, Object container, String legacy, int size, String title, ItemStack[] items) {
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = ((Container) container).windowId;
    net.minecraft.server.v1_16_R2.ItemStack[] nmsItems = new net.minecraft.server.v1_16_R2.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_16_R2.ItemStack item = null;
        ((Container) container).setItem(i, item = (net.minecraft.server.v1_16_R2.ItemStack) asNMSItem(is));
        nmsItems[i] = item;
    }
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, legacy, size, title));
    int i = 0;
    for (net.minecraft.server.v1_16_R2.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) container).checkReachable = false;
}
Also used : Container(net.minecraft.server.v1_16_R2.Container) CraftContainer(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer) EntityPlayer(net.minecraft.server.v1_16_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 9 with net.minecraft.server.v1_16_R2

use of net.minecraft.server.v1_16_R2 in project TheAPI by TheDevTec.

the class v1_16_R2 method setBlock.

@Override
public void setBlock(Object chunk, int x, int y, int z, Object IblockData, int data) {
    net.minecraft.server.v1_16_R2.Chunk c = (net.minecraft.server.v1_16_R2.Chunk) chunk;
    ChunkSection sc = c.getSections()[y >> 4];
    if (sc == null) {
        c.getSections()[y >> 4] = sc = new ChunkSection(y >> 4 << 4);
    }
    BlockPosition pos = new BlockPosition(x, y, z);
    // REMOVE TILE ENTITY
    c.tileEntities.remove(pos);
    sc.getBlocks().b(x & 15, y & 15, z & 15, (IBlockData) IblockData);
    // ADD TILE ENTITY
    if (IblockData instanceof ITileEntity) {
        TileEntity ent = ((ITileEntity) IblockData).createTile(c);
        c.tileEntities.put(pos, ent);
        Object packet = ent.getUpdatePacket();
        Bukkit.getOnlinePlayers().forEach(player -> BukkitLoader.getPacketHandler().send(player, packet));
    }
}
Also used : TileEntity(net.minecraft.server.v1_16_R2.TileEntity) ITileEntity(net.minecraft.server.v1_16_R2.ITileEntity) ITileEntity(net.minecraft.server.v1_16_R2.ITileEntity) BlockPosition(net.minecraft.server.v1_16_R2.BlockPosition) Chunk(org.bukkit.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_16_R2.CraftChunk) ChunkSection(net.minecraft.server.v1_16_R2.ChunkSection)

Example 10 with net.minecraft.server.v1_16_R2

use of net.minecraft.server.v1_16_R2 in project TheAPI by TheDevTec.

the class v1_16_R2 method setGUITitle.

@Override
public void setGUITitle(Player player, Object container, String legacy, int size, String title) {
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = ((Container) container).windowId;
    NonNullList<net.minecraft.server.v1_16_R2.ItemStack> nmsItems = ((Container) container).items;
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, legacy, size, title));
    int i = 0;
    for (net.minecraft.server.v1_16_R2.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
    nmsPlayer.activeContainer = (Container) container;
    ((Container) container).addSlotListener(nmsPlayer);
    ((Container) container).checkReachable = false;
}
Also used : Container(net.minecraft.server.v1_16_R2.Container) CraftContainer(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer) EntityPlayer(net.minecraft.server.v1_16_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack)11 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)9 ItemStack (org.bukkit.inventory.ItemStack)7 CraftChunk (org.bukkit.craftbukkit.v1_16_R2.CraftChunk)4 Container (net.minecraft.server.v1_16_R2.Container)3 EntityPlayer (net.minecraft.server.v1_16_R2.EntityPlayer)3 Chunk (org.bukkit.Chunk)3 CraftPlayer (org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer)3 CraftContainer (org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer)3 PacketContainer (com.comphenix.protocol.events.PacketContainer)2 Pair (com.mojang.datafixers.util.Pair)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 net.minecraft.server.v1_16_R2 (net.minecraft.server.v1_16_R2)2 BlockPosition (net.minecraft.server.v1_16_R2.BlockPosition)2 ChunkSection (net.minecraft.server.v1_16_R2.ChunkSection)2 ContainerAnvil (net.minecraft.server.v1_16_R2.ContainerAnvil)2 EnumItemSlot (net.minecraft.server.v1_16_R2.EnumItemSlot)2 PacketPlayOutEntityEquipment (net.minecraft.server.v1_16_R2.PacketPlayOutEntityEquipment)2 Material (org.bukkit.Material)2