Search in sources :

Example 96 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound in project RoseStacker by Rosewood-Development.

the class NBTStackedEntityDataStorage method addAt.

private void addAt(int index, LivingEntity livingEntity) {
    NBTTagCompound compoundTag = new NBTTagCompound();
    ((CraftLivingEntity) livingEntity).getHandle().save(compoundTag);
    this.stripUnneeded(compoundTag);
    this.stripAttributeUuids(compoundTag);
    this.removeDuplicates(compoundTag);
    this.data.add(index, compoundTag);
}
Also used : NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound)

Example 97 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound in project RoseStacker by Rosewood-Development.

the class NBTStackedEntityDataStorage method serialize.

@Override
public byte[] serialize() {
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
        NBTCompressedStreamTools.a(this.base, (DataOutput) dataOutput);
        dataOutput.writeInt(this.data.size());
        for (NBTTagCompound compoundTag : new ArrayList<>(this.data)) NBTCompressedStreamTools.a(compoundTag, (DataOutput) dataOutput);
        dataOutput.close();
        return outputStream.toByteArray();
    } catch (Exception e) {
        throw new StackedEntityDataIOException(e);
    }
}
Also used : DataOutput(java.io.DataOutput) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) StackedEntityDataIOException(dev.rosewood.rosestacker.nms.storage.StackedEntityDataIOException) StackedEntityDataIOException(dev.rosewood.rosestacker.nms.storage.StackedEntityDataIOException)

Example 98 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method setItemStackNBT.

@Override
public ItemStack setItemStackNBT(ItemStack itemStack, String key, int value) {
    net.minecraft.server.v1_16_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
    tagCompound.setInt(key, value);
    return CraftItemStack.asBukkitCopy(nmsItem);
}
Also used : NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound)

Example 99 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound 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 100 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method applyNBTToEntity.

@Override
public void applyNBTToEntity(org.bukkit.entity.LivingEntity bukkitEntity, String nbt) {
    try {
        NBTTagCompound tagCompound = MojangsonParser.parse(nbt);
        ((CraftLivingEntity) bukkitEntity).getHandle().a(tagCompound);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound)

Aggregations

NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)64 ItemStack (org.bukkit.inventory.ItemStack)60 ArrayList (java.util.ArrayList)37 Map (java.util.Map)36 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)35 ItemMeta (org.bukkit.inventory.meta.ItemMeta)35 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)33 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)33 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)30 ListTag (com.wasteofplastic.org.jnbt.ListTag)30 StringTag (com.wasteofplastic.org.jnbt.StringTag)30 Tag (com.wasteofplastic.org.jnbt.Tag)30 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)23 Nullable (javax.annotation.Nullable)21 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)21 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)20 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)20 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)20 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)19 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)15