Search in sources :

Example 11 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project MechanicsMain by WeaponMechanics.

the class Block_1_15_R1 method getMultiBlockMaskPacket.

private PacketPlayOutMultiBlockChange getMultiBlockMaskPacket(List<Block> blocks, @Nullable IBlockData mask) {
    Chunk chunk = ((CraftChunk) blocks.get(0).getChunk()).getHandle();
    // Setup default information
    PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(0, new short[0], chunk);
    PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] changes = new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[blocks.size()];
    for (int i = 0; i < blocks.size(); i++) {
        Block block = blocks.get(i);
        // Where the block is relative to the chunk it is in
        int x = block.getX() & 0xF;
        int y = block.getY();
        int z = block.getZ() & 0xF;
        // Setting the (x, y, z) location into VarInt format
        short location = (short) (x << 12 | y | z << 8);
        // If mask is null, then undo the mask. Otherwise set the mask
        if (mask == null) {
            changes[i] = packet.new MultiBlockChangeInfo(location, chunk);
        } else {
            changes[i] = packet.new MultiBlockChangeInfo(location, mask);
        }
    }
    ReflectionUtil.setField(multiBlockChangeB, packet, changes);
    return packet;
}
Also used : PacketPlayOutMultiBlockChange(net.minecraft.server.v1_15_R1.PacketPlayOutMultiBlockChange) Block(org.bukkit.block.Block) Chunk(net.minecraft.server.v1_15_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk)

Example 12 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project MechanicsMain by WeaponMechanics.

the class Block_1_15_R1 method getMultiBlockMaskPacket.

@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable Material mask, byte data) {
    if (blocks == null || blocks.isEmpty()) {
        throw new IllegalArgumentException("No blocks are being changed!");
    }
    Map<org.bukkit.Chunk, List<Block>> sortedBlocks = new HashMap<>();
    for (Block block : blocks) {
        List<Block> list = sortedBlocks.computeIfAbsent(block.getChunk(), chunk -> new ArrayList<>());
        list.add(block);
    }
    List<Object> packets = new ArrayList<>(sortedBlocks.size());
    IBlockData theMask = mask == null ? null : ((CraftBlockData) mask.createBlockData()).getState();
    for (List<Block> entry : sortedBlocks.values()) {
        packets.add(getMultiBlockMaskPacket(entry, theMask));
    }
    return packets;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Chunk(net.minecraft.server.v1_15_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) IBlockData(net.minecraft.server.v1_15_R1.IBlockData) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method createEntityFromNBT.

@Override
public LivingEntity createEntityFromNBT(StackedEntityDataEntry<?> serialized, Location location, boolean addToWorld, EntityType entityType) {
    try {
        NBTTagCompound nbt = (NBTTagCompound) serialized.get();
        NBTTagList positionTagList = nbt.getList("Pos", 6);
        if (positionTagList == null)
            positionTagList = new NBTTagList();
        this.setTag(positionTagList, 0, NBTTagDouble.a(location.getX()));
        this.setTag(positionTagList, 1, NBTTagDouble.a(location.getY()));
        this.setTag(positionTagList, 2, NBTTagDouble.a(location.getZ()));
        nbt.set("Pos", positionTagList);
        NBTTagList rotationTagList = nbt.getList("Rotation", 5);
        if (rotationTagList == null)
            rotationTagList = new NBTTagList();
        this.setTag(rotationTagList, 0, NBTTagFloat.a(location.getYaw()));
        this.setTag(rotationTagList, 1, NBTTagFloat.a(location.getPitch()));
        nbt.set("Rotation", rotationTagList);
        // Reset the UUID to resolve possible duplicates
        nbt.a("UUID", UUID.randomUUID());
        Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType.getKey().getKey());
        if (optionalEntity.isPresent()) {
            WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
            Entity entity = this.createCreature(optionalEntity.get(), world, nbt, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), EnumMobSpawn.COMMAND);
            if (entity == null)
                throw new NullPointerException("Unable to create entity from NBT");
            // Load NBT
            entity.load(nbt);
            if (addToWorld) {
                IChunkAccess ichunkaccess = world.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, true);
                if (!(ichunkaccess instanceof Chunk))
                    throw new NullPointerException("Unable to spawn entity from NBT, couldn't get chunk");
                ichunkaccess.a(entity);
                method_WorldServer_registerEntity.invoke(world, entity);
                entity.noDamageTicks = 0;
            }
            return (LivingEntity) entity.getBukkitEntity();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : EntityTypes(net.minecraft.server.v1_16_R3.EntityTypes) IChunkAccess(net.minecraft.server.v1_16_R3.IChunkAccess) Entity(net.minecraft.server.v1_16_R3.Entity) GroupDataEntity(net.minecraft.server.v1_16_R3.GroupDataEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) TileEntity(net.minecraft.server.v1_16_R3.TileEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) Chunk(net.minecraft.server.v1_16_R3.Chunk) NBTTagList(net.minecraft.server.v1_16_R3.NBTTagList) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 14 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method createEntityFromNBT.

@Override
public LivingEntity createEntityFromNBT(StackedEntityDataEntry<?> serialized, Location location, boolean addToWorld, EntityType entityType) {
    try {
        NBTTagCompound nbt = (NBTTagCompound) serialized.get();
        NBTTagList positionTagList = nbt.getList("Pos", 6);
        if (positionTagList == null)
            positionTagList = new NBTTagList();
        this.setTag(positionTagList, 0, NBTTagDouble.a(location.getX()));
        this.setTag(positionTagList, 1, NBTTagDouble.a(location.getY()));
        this.setTag(positionTagList, 2, NBTTagDouble.a(location.getZ()));
        nbt.set("Pos", positionTagList);
        NBTTagList rotationTagList = nbt.getList("Rotation", 5);
        if (rotationTagList == null)
            rotationTagList = new NBTTagList();
        this.setTag(rotationTagList, 0, NBTTagFloat.a(location.getYaw()));
        this.setTag(rotationTagList, 1, NBTTagFloat.a(location.getPitch()));
        nbt.set("Rotation", rotationTagList);
        // Reset the UUID to resolve possible duplicates
        nbt.a("UUID", UUID.randomUUID());
        Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType.getKey().getKey());
        if (optionalEntity.isPresent()) {
            WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
            Entity entity = this.createCreature(optionalEntity.get(), world, nbt, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), EnumMobSpawn.COMMAND);
            if (entity == null)
                throw new NullPointerException("Unable to create entity from NBT");
            // Load NBT
            entity.load(nbt);
            if (addToWorld) {
                IChunkAccess ichunkaccess = world.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, true);
                if (!(ichunkaccess instanceof Chunk))
                    throw new NullPointerException("Unable to spawn entity from NBT, couldn't get chunk");
                ichunkaccess.a(entity);
                method_WorldServer_registerEntity.invoke(world, entity);
                entity.noDamageTicks = 0;
            }
            return (LivingEntity) entity.getBukkitEntity();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : EntityTypes(net.minecraft.server.v1_16_R2.EntityTypes) IChunkAccess(net.minecraft.server.v1_16_R2.IChunkAccess) Entity(net.minecraft.server.v1_16_R2.Entity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) TileEntity(net.minecraft.server.v1_16_R2.TileEntity) GroupDataEntity(net.minecraft.server.v1_16_R2.GroupDataEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity) BlockPosition(net.minecraft.server.v1_16_R2.BlockPosition) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound) WorldServer(net.minecraft.server.v1_16_R2.WorldServer) Chunk(net.minecraft.server.v1_16_R2.Chunk) NBTTagList(net.minecraft.server.v1_16_R2.NBTTagList) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R2.CraftWorld)

Example 15 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method spawnExistingEntity.

@Override
public void spawnExistingEntity(LivingEntity entity, SpawnReason spawnReason, boolean bypassSpawnEvent) {
    Location location = entity.getLocation();
    World world = location.getWorld();
    if (world == null)
        throw new IllegalArgumentException("Entity is not in a loaded world");
    if (bypassSpawnEvent) {
        IChunkAccess ichunkaccess = ((CraftWorld) world).getHandle().getChunkAt(MathHelper.floor(entity.getLocation().getX() / 16.0D), MathHelper.floor(entity.getLocation().getZ() / 16.0D), ChunkStatus.FULL, false);
        if (!(ichunkaccess instanceof Chunk))
            return;
        ichunkaccess.a(((CraftEntity) entity).getHandle());
        ((CraftWorld) world).getHandle().addEntityChunk(((CraftEntity) entity).getHandle());
    } else {
        ((CraftWorld) world).addEntity(((CraftEntity) entity).getHandle(), spawnReason);
    }
}
Also used : IChunkAccess(net.minecraft.server.v1_16_R2.IChunkAccess) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_16_R2.CraftWorld) Chunk(net.minecraft.server.v1_16_R2.Chunk) CraftWorld(org.bukkit.craftbukkit.v1_16_R2.CraftWorld) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)13 ArrayList (java.util.ArrayList)11 List (java.util.List)11 HashMap (java.util.HashMap)10 WildLoadersPlugin (com.bgsoftware.wildloaders.WildLoadersPlugin)8 Hologram (com.bgsoftware.wildloaders.api.holograms.Hologram)8 ChunkLoader (com.bgsoftware.wildloaders.api.loaders.ChunkLoader)8 ChunkLoaderNPC (com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC)8 ITileEntityChunkLoader (com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader)8 WChunkLoader (com.bgsoftware.wildloaders.loaders.WChunkLoader)8 Collection (java.util.Collection)8 Collections (java.util.Collections)8 Map (java.util.Map)8 UUID (java.util.UUID)8 Chunk (net.minecraft.server.v1_16_R3.Chunk)8 CraftChunk (org.bukkit.craftbukkit.v1_8_R3.CraftChunk)7 BlockPosition (net.minecraft.server.v1_8_R3.BlockPosition)6 Chunk (net.minecraft.server.v1_15_R1.Chunk)4 IBlockData (net.minecraft.server.v1_8_R3.IBlockData)4 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)4