Search in sources :

Example 1 with TObjectByteHashMap

use of gnu.trove.map.hash.TObjectByteHashMap 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)

Aggregations

TByteArrayList (gnu.trove.list.array.TByteArrayList)1 TObjectByteHashMap (gnu.trove.map.hash.TObjectByteHashMap)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 NBTTagString (net.minecraft.nbt.NBTTagString)1 ChunkPos (net.minecraft.util.math.ChunkPos)1