Search in sources :

Example 66 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project BuildCraft by BuildCraft.

the class RetroGenData method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    Set<String> allNames = new HashSet<>();
    for (Set<String> used : gennedChunks.values()) {
        allNames.addAll(used);
    }
    TObjectByteHashMap<String> map = new TObjectByteHashMap<>();
    List<String> list = new ArrayList<>(allNames);
    NBTTagList registry = new NBTTagList();
    for (int i = 0; i < list.size(); i++) {
        String name = list.get(i);
        map.put(name, (byte) i);
        registry.appendTag(new NBTTagString(name));
    }
    nbt.setTag("registry", registry);
    NBTTagCompound data = new NBTTagCompound();
    for (Entry<ChunkPos, Set<String>> entry : gennedChunks.entrySet()) {
        String key = serializeChunkPos(entry.getKey());
        Set<String> names = entry.getValue();
        TByteArrayList ids = new TByteArrayList();
        for (String s : names) {
            byte b = map.get(s);
            ids.add(b);
        }
        data.setByteArray(key, ids.toArray());
    }
    nbt.setTag("data", data);
    return nbt;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TByteArrayList(gnu.trove.list.array.TByteArrayList) TObjectByteHashMap(gnu.trove.map.hash.TObjectByteHashMap) ArrayList(java.util.ArrayList) TByteArrayList(gnu.trove.list.array.TByteArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString) ChunkPos(net.minecraft.util.math.ChunkPos) HashSet(java.util.HashSet)

Example 67 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project BuildCraft by BuildCraft.

the class GatePluggable method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbt) {
    nbt.setByte(ItemGate.NBT_TAG_MAT, (byte) material.ordinal());
    nbt.setByte(ItemGate.NBT_TAG_LOGIC, (byte) logic.ordinal());
    NBTTagList expansionsList = nbt.getTagList(ItemGate.NBT_TAG_EX, Constants.NBT.TAG_STRING);
    for (IGateExpansion expansion : expansions) {
        expansionsList.appendTag(new NBTTagString(expansion.getUniqueIdentifier()));
    }
    nbt.setTag(ItemGate.NBT_TAG_EX, expansionsList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IGateExpansion(buildcraft.api.gates.IGateExpansion) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 68 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project BuildCraft by BuildCraft.

the class TileAssemblyTable method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);
    NBTTagList list = new NBTTagList();
    for (String recipe : plannedOutput) {
        list.appendTag(new NBTTagString(recipe));
    }
    nbt.setTag("plannedIds", list);
    if (currentRecipe != null) {
        nbt.setString("recipeId", currentRecipe.getId());
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 69 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project BuildCraft by BuildCraft.

the class NbtSquishMap method addTag.

public void addTag(NBTBase nbt) {
    if (nbt instanceof NBTTagString) {
        String val = ((NBTTagString) nbt).getString();
        if (!strings.contains(val)) {
            strings.add(val);
        }
    } else if (nbt instanceof NBTTagByte) {
        byte val = ((NBTTagByte) nbt).getByte();
        if (!bytes.contains(val)) {
            bytes.add(val);
        }
    } else if (nbt instanceof NBTTagShort) {
        short val = ((NBTTagShort) nbt).getShort();
        if (!shorts.contains(val)) {
            shorts.add(val);
        }
    } else if (nbt instanceof NBTTagInt) {
        int val = ((NBTTagInt) nbt).getInt();
        if (!ints.contains(val)) {
            ints.add(val);
        }
    } else if (nbt instanceof NBTTagLong) {
        long val = ((NBTTagLong) nbt).getLong();
        if (!longs.contains(val)) {
            longs.add(val);
        }
    } else if (nbt instanceof NBTTagFloat) {
        float val = ((NBTTagFloat) nbt).getFloat();
        if (!floats.contains(val)) {
            floats.add(val);
        }
    } else if (nbt instanceof NBTTagDouble) {
        double val = ((NBTTagDouble) nbt).getDouble();
        if (!doubles.contains(val)) {
            doubles.add(val);
        }
    } else if (nbt instanceof NBTTagByteArray) {
        byte[] val = ((NBTTagByteArray) nbt).getByteArray();
        TByteArrayList array = new TByteArrayList(val);
        if (!byteArrays.contains(array)) {
            byteArrays.add(array);
        }
    } else if (nbt instanceof NBTTagIntArray) {
        int[] val = ((NBTTagIntArray) nbt).getIntArray();
        TIntArrayList array = new TIntArrayList(val);
        if (!intArrays.contains(array)) {
            intArrays.add(array);
        }
    } else if (nbt instanceof NBTTagList) {
        NBTTagList list = (NBTTagList) nbt;
        if (!complex.contains(list)) {
            for (int i = 0; i < list.tagCount(); i++) {
                addTag(list.get(i));
            }
            complex.add(list);
        }
    } else if (nbt instanceof NBTTagCompound) {
        NBTTagCompound compound = (NBTTagCompound) nbt;
        if (!complex.contains(compound)) {
            for (String key : compound.getKeySet()) {
                if (!strings.contains(key)) {
                    strings.add(key);
                }
                addTag(compound.getTag(key));
            }
            complex.add(compound);
        }
    } else {
        throw new IllegalArgumentException("Cannot handle tag " + nbt);
    }
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) TByteArrayList(gnu.trove.list.array.TByteArrayList) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) TIntArrayList(gnu.trove.list.array.TIntArrayList) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagShort(net.minecraft.nbt.NBTTagShort) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagLong(net.minecraft.nbt.NBTTagLong) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Example 70 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project BuildCraft by BuildCraft.

the class NbtSquishMap method indexOfTag.

public int indexOfTag(NBTBase nbt) {
    int offset = 0;
    if (nbt instanceof NBTTagByte) {
        return bytes.indexOf(((NBTTagByte) nbt).getByte());
    } else {
        offset += bytes.size();
    }
    if (nbt instanceof NBTTagShort) {
        return offset + shorts.indexOf(((NBTTagShort) nbt).getShort());
    } else {
        offset += shorts.size();
    }
    if (nbt instanceof NBTTagInt) {
        return offset + ints.indexOf(((NBTTagInt) nbt).getInt());
    } else {
        offset += ints.size();
    }
    if (nbt instanceof NBTTagLong) {
        return offset + longs.indexOf(((NBTTagLong) nbt).getLong());
    } else {
        offset += longs.size();
    }
    if (nbt instanceof NBTTagFloat) {
        return offset + floats.indexOf(((NBTTagFloat) nbt).getFloat());
    } else {
        offset += floats.size();
    }
    if (nbt instanceof NBTTagDouble) {
        return offset + doubles.indexOf(((NBTTagDouble) nbt).getDouble());
    } else {
        offset += doubles.size();
    }
    if (nbt instanceof NBTTagByteArray) {
        byte[] val = ((NBTTagByteArray) nbt).getByteArray();
        TByteArrayList array = new TByteArrayList(val);
        return offset + byteArrays.indexOf(array);
    } else {
        offset += byteArrays.size();
    }
    if (nbt instanceof NBTTagIntArray) {
        int[] val = ((NBTTagIntArray) nbt).getIntArray();
        TIntArrayList array = new TIntArrayList(val);
        return offset + intArrays.indexOf(array);
    } else {
        offset += intArrays.size();
    }
    if (nbt instanceof NBTTagString) {
        return offset + strings.indexOf(((NBTTagString) nbt).getString());
    } else {
        offset += strings.size();
    }
    if (nbt instanceof NBTTagList) {
        return offset + complex.indexOf(nbt);
    } else if (nbt instanceof NBTTagCompound) {
        return offset + complex.indexOf(nbt);
    }
    throw new IllegalArgumentException("Cannot handle tag " + nbt);
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) TByteArrayList(gnu.trove.list.array.TByteArrayList) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TIntArrayList(gnu.trove.list.array.TIntArrayList) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagShort(net.minecraft.nbt.NBTTagShort) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagLong(net.minecraft.nbt.NBTTagLong) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Aggregations

NBTTagString (net.minecraft.nbt.NBTTagString)101 NBTTagList (net.minecraft.nbt.NBTTagList)82 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 ItemStack (net.minecraft.item.ItemStack)18 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)11 NBTBase (net.minecraft.nbt.NBTBase)10 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)10 NBTTagInt (net.minecraft.nbt.NBTTagInt)10 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)9 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)9 NBTTagByte (net.minecraft.nbt.NBTTagByte)8 NBTTagLong (net.minecraft.nbt.NBTTagLong)8 ResourceLocation (net.minecraft.util.ResourceLocation)8 List (java.util.List)7 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Item (net.minecraft.item.Item)4