Search in sources :

Example 26 with net.minecraft.server.v1_15_R1

use of net.minecraft.server.v1_15_R1 in project THP-Engine by TheHollowPlanetMC.

the class PacketManager method sendClearChunkMultiBlockChangePacketAtPrimaryThread.

public static void sendClearChunkMultiBlockChangePacketAtPrimaryThread(Player player, ParallelChunk parallelChunk, NMSHandler nmsHandler) {
    if (!Bukkit.isPrimaryThread())
        throw new IllegalStateException("DO NOT CALL FROM ASYNC THREAD!");
    org.bukkit.World world = Bukkit.getWorld(parallelChunk.getWorld().getName());
    if (world == null)
        return;
    if (player.getWorld() != world)
        return;
    List<Short> coordList = new ArrayList<>();
    boolean has = false;
    for (int sectionIndex = 0; sectionIndex < 16; sectionIndex++) {
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionIndex);
        if (sectionTypeArray == null)
            continue;
        int finalSectionIndex = sectionIndex;
        boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
            short loc = (short) (x << 12 | z << 8 | (y + (finalSectionIndex << 4)));
            coordList.add(loc);
        });
        if (notEmpty)
            has = true;
    }
    if (!has)
        return;
    if (coordList.size() == 0)
        return;
    org.bukkit.Chunk chunk = world.getChunkAt(parallelChunk.getChunkX(), parallelChunk.getChunkZ());
    net.minecraft.server.v1_15_R1.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
    short[] array = new short[coordList.size()];
    for (int i = 0; i < coordList.size(); i++) {
        array[i] = coordList.get(i);
    }
    PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(coordList.size(), array, nmsChunk);
    nmsHandler.sendPacket(player, packet);
}
Also used : SectionTypeArray(thpmc.engine.util.SectionTypeArray) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk)

Example 27 with net.minecraft.server.v1_15_R1

use of net.minecraft.server.v1_15_R1 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_15_R1.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_15_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound) Material(org.bukkit.Material) CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)10 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)9 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)7 ItemStack (org.bukkit.inventory.ItemStack)7 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)5 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)5 CraftChunk (org.bukkit.craftbukkit.v1_15_R1.CraftChunk)5 Container (net.minecraft.server.v1_15_R1.Container)3 CraftWorld (org.bukkit.craftbukkit.v1_15_R1.CraftWorld)3 Player (org.bukkit.entity.Player)3 UUID (java.util.UUID)2 Nullable (javax.annotation.Nullable)2 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)2 ChunkSection (net.minecraft.server.v1_15_R1.ChunkSection)2 ContainerAnvil (net.minecraft.server.v1_15_R1.ContainerAnvil)2 EntityLiving (net.minecraft.server.v1_15_R1.EntityLiving)2 Chunk (org.bukkit.Chunk)2 Location (org.bukkit.Location)2 CraftEntity (org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity)2 CraftContainer (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftContainer)2