Search in sources :

Example 21 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList in project RoseStacker by Rosewood-Development.

the class NBTStackedEntityDataStorage method stripAttributeUuids.

private void stripAttributeUuids(NBTTagCompound compoundTag) {
    NBTTagList attributes = compoundTag.getList("Attributes", 10);
    for (int i = 0; i < attributes.size(); i++) {
        NBTTagCompound attribute = attributes.getCompound(i);
        attribute.remove("UUID");
        NBTTagList modifiers = attribute.getList("Modifiers", 10);
        for (int j = 0; j < modifiers.size(); j++) {
            NBTTagCompound modifier = modifiers.getCompound(j);
            if (modifier.getString("Name").equals("Random spawn bonus")) {
                modifiers.remove(j);
                j--;
            } else {
                modifier.remove("UUID");
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.server.v1_16_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound)

Example 22 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList in project RoseStacker by Rosewood-Development.

the class NBTStackedEntityDataStorage method fillAttributeUuids.

private void fillAttributeUuids(NBTTagCompound compoundTag) {
    NBTTagList attributes = compoundTag.getList("Attributes", 10);
    for (int i = 0; i < attributes.size(); i++) {
        NBTTagCompound attribute = attributes.getCompound(i);
        attribute.a("UUID", UUID.randomUUID());
        NBTTagList modifiers = attribute.getList("Modifiers", 10);
        for (int j = 0; j < modifiers.size(); j++) {
            NBTTagCompound modifier = modifiers.getCompound(j);
            modifier.a("UUID", UUID.randomUUID());
        }
        if (modifiers.size() == 0)
            attribute.remove("Modifiers");
    }
}
Also used : NBTTagList(net.minecraft.server.v1_16_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound)

Example 23 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList 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 24 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList in project custom-items-gradle by knokko.

the class ItemAttributes method setAttribute.

public static ItemStack setAttribute(ItemStack original, String attribute, double value, String slot, int operation) {
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(original);
    NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
    NBTTagList modifiers = compound.getList("AttributeModifiers", 10);
    if (modifiers == null)
        modifiers = new NBTTagList();
    setAttribute(modifiers, attribute, value, slot, operation);
    compound.set("AttributeModifiers", modifiers);
    nmsStack.setTag(compound);
    return CraftItemStack.asBukkitCopy(nmsStack);
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 25 with NBTTagList

use of net.minecraft.server.v1_16_R2.NBTTagList in project custom-items-gradle by knokko.

the class ItemAttributes method clearAttributes.

public static ItemStack clearAttributes(ItemStack original) {
    net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(original);
    NBTTagCompound compound = nmsStack.hasTag() ? nmsStack.getTag() : new NBTTagCompound();
    NBTTagList modifiers = new NBTTagList();
    setAttribute(modifiers, "dummy", 0, "dummyslot", 0);
    compound.set("AttributeModifiers", modifiers);
    nmsStack.setTag(compound);
    return CraftItemStack.asBukkitCopy(nmsStack);
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)23 ArrayList (java.util.ArrayList)22 ItemMeta (org.bukkit.inventory.meta.ItemMeta)22 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)20 ListTag (com.wasteofplastic.org.jnbt.ListTag)20 StringTag (com.wasteofplastic.org.jnbt.StringTag)20 Tag (com.wasteofplastic.org.jnbt.Tag)20 Map (java.util.Map)20 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)17 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)17 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)8 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)6 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)6 NBTTagList (net.minecraft.server.v1_8_R3.NBTTagList)6 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)5 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)5 NBTTagList (net.minecraft.server.v1_16_R3.NBTTagList)5 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)5