Search in sources :

Example 46 with ListTag

use of net.minecraft.nbt.ListTag in project Denizen-For-Bukkit by DenizenScript.

the class ImprovedOfflinePlayerImpl method setInventory.

@Override
public void setInventory(org.bukkit.inventory.PlayerInventory inventory) {
    CraftInventoryPlayer inv = (CraftInventoryPlayer) inventory;
    net.minecraft.nbt.CompoundTag nbtTagCompound = ((CompoundTagImpl) compound).toNMSTag();
    nbtTagCompound.put("Inventory", inv.getInventory().save(new ListTag()));
    this.compound = CompoundTagImpl.fromNMSTag(nbtTagCompound);
    if (this.autosave) {
        savePlayerData();
    }
}
Also used : CraftInventoryPlayer(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryPlayer) ListTag(net.minecraft.nbt.ListTag) CompoundTagImpl(com.denizenscript.denizen.nms.v1_17.impl.jnbt.CompoundTagImpl)

Example 47 with ListTag

use of net.minecraft.nbt.ListTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemHelperImpl method getLore.

@Override
public List<String> getLore(ItemTag item) {
    if (!item.getItemMeta().hasLore()) {
        return null;
    }
    net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item.getItemStack());
    ListTag list = ((net.minecraft.nbt.CompoundTag) nmsItemStack.getTag().get("display")).getList("Lore", 8);
    List<String> outList = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
        BaseComponent[] lineComponent = ComponentSerializer.parse(list.getString(i));
        outList.add(FormattedTextHelper.stringify(lineComponent, ChatColor.WHITE));
    }
    return outList;
}
Also used : BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ListTag(net.minecraft.nbt.ListTag)

Example 48 with ListTag

use of net.minecraft.nbt.ListTag in project Tropicraft by Tropicraft.

the class SpawnerProcessor method process.

@Override
@Nullable
public StructureTemplate.StructureBlockInfo process(LevelReader world, BlockPos pos, BlockPos pos2, StructureTemplate.StructureBlockInfo originalBlockInfo, StructureTemplate.StructureBlockInfo blockInfo, StructurePlaceSettings settings, @Nullable StructureTemplate template) {
    final Block block = blockInfo.state.getBlock();
    if (block != Blocks.SPAWNER) {
        return blockInfo;
    } else {
        final CompoundTag tag = new CompoundTag();
        String typeName = Registry.ENTITY_TYPE.getKey(entityTypes.get(0)).toString();
        tag.putString("id", entityTypes.get(0).getRegistryName().getPath());
        blockInfo.nbt.getCompound("SpawnData").putString("id", typeName);
        // TODO not working
        final ListTag list = blockInfo.nbt.getList("SpawnPotentials", 9);
        for (int i = 0; i < list.size(); i++) {
            final CompoundTag nbt = list.getCompound(i);
            nbt.getCompound("Entity").putString("id", typeName);
        }
        return blockInfo;
    }
}
Also used : Block(net.minecraft.world.level.block.Block) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) Nullable(javax.annotation.Nullable)

Example 49 with ListTag

use of net.minecraft.nbt.ListTag in project Tropicraft by Tropicraft.

the class EntityKoaBase method addAdditionalSaveData.

@Override
public void addAdditionalSaveData(CompoundTag compound) {
    super.addAdditionalSaveData(compound);
    compound.putInt("home_X", getRestrictCenter().getX());
    compound.putInt("home_Y", getRestrictCenter().getY());
    compound.putInt("home_Z", getRestrictCenter().getZ());
    if (posLastFireplaceFound != null) {
        compound.putInt("fireplace_X", posLastFireplaceFound.getX());
        compound.putInt("fireplace_Y", posLastFireplaceFound.getY());
        compound.putInt("fireplace_Z", posLastFireplaceFound.getZ());
    }
    compound.putLong("lastTimeFished", lastTimeFished);
    ListTag nbttaglist = new ListTag();
    for (int i = 0; i < this.inventory.getContainerSize(); ++i) {
        ItemStack itemstack = this.inventory.getItem(i);
        if (!itemstack.isEmpty()) {
            CompoundTag nbttagcompound = new CompoundTag();
            nbttagcompound.putByte("Slot", (byte) i);
            itemstack.save(nbttagcompound);
            nbttaglist.add(nbttagcompound);
        }
    }
    compound.put("koa_inventory", nbttaglist);
    compound.putInt("role_id", this.getEntityData().get(ROLE));
    compound.putInt("gender_id", this.getEntityData().get(GENDER));
    compound.putInt("village_id", villageID);
    if (villageDimension != null) {
        compound.putString("village_dimension", villageDimension.location().toString());
    }
    compound.putLong("lastTradeTime", lastTradeTime);
    for (int i = 0; i < listPosDrums.size(); i++) {
        compound.putInt("drum_" + i + "_X", listPosDrums.get(i).getX());
        compound.putInt("drum_" + i + "_Y", listPosDrums.get(i).getY());
        compound.putInt("drum_" + i + "_Z", listPosDrums.get(i).getZ());
    }
    compound.putInt("druggedTime", druggedTime);
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 50 with ListTag

use of net.minecraft.nbt.ListTag in project Tropicraft by Tropicraft.

the class CocktailItem method makeCocktail.

@Nonnull
public static ItemStack makeCocktail(final NonNullList<ItemStack> itemStacks) {
    // TODO fixme this is so ugly ugh
    final ItemStack stack = new ItemStack(TropicraftItems.COCKTAILS.get(Drink.COCKTAIL).get());
    CompoundTag nbt = new CompoundTag();
    nbt.putByte("DrinkID", (byte) Drink.COCKTAIL.drinkId);
    ListTag tagList = new ListTag();
    List<Ingredient> ingredients = new ArrayList<>();
    for (ItemStack ingredientStack : itemStacks) {
        ingredients.addAll(Ingredient.listIngredients(ingredientStack));
    }
    Collections.sort(ingredients);
    Ingredient primary = null;
    List<Ingredient> additives = new LinkedList<>();
    for (Ingredient ingredient : ingredients) {
        CompoundTag ingredientNbt = new CompoundTag();
        ingredientNbt.putByte("IngredientID", (byte) ingredient.id);
        tagList.add(ingredientNbt);
        if (ingredient.isPrimary()) {
            primary = ingredient;
        } else {
            additives.add(ingredient);
        }
    }
    nbt.put("Ingredients", tagList);
    int color = primary == null ? DEFAULT_COLOR : primary.getColor();
    for (Ingredient additive : additives) {
        color = ColorMixer.getInstance().alphaBlendRGBA(color, additive.getColor(), additive.getAlpha());
    }
    nbt.putInt("Color", color);
    stack.setTag(nbt);
    return stack;
}
Also used : Ingredient(net.tropicraft.core.common.drinks.Ingredient) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.world.item.ItemStack) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull)

Aggregations

ListTag (net.minecraft.nbt.ListTag)52 CompoundTag (net.minecraft.nbt.CompoundTag)38 ItemStack (net.minecraft.world.item.ItemStack)10 TagCompound (de.keyle.knbt.TagCompound)8 TagList (de.keyle.knbt.TagList)8 List (java.util.List)7 IntArrayTag (net.minecraft.nbt.IntArrayTag)7 ResourceLocation (net.minecraft.resources.ResourceLocation)7 TagString (de.keyle.knbt.TagString)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 StringTag (net.minecraft.nbt.StringTag)5 ByteArrayTag (net.minecraft.nbt.ByteArrayTag)4 IntTag (net.minecraft.nbt.IntTag)4 Tag (net.minecraft.nbt.Tag)4 ByteTag (net.minecraft.nbt.ByteTag)3 DoubleTag (net.minecraft.nbt.DoubleTag)3 FloatTag (net.minecraft.nbt.FloatTag)3 LongTag (net.minecraft.nbt.LongTag)3 ShortTag (net.minecraft.nbt.ShortTag)3