Search in sources :

Example 76 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project MinecraftForge by MinecraftForge.

the class FluidRegistry method loadFluidDefaults.

public static void loadFluidDefaults(NBTTagCompound tag) {
    Set<String> defaults = Sets.newHashSet();
    if (tag.hasKey("DefaultFluidList", 9)) {
        FMLLog.getLogger().log(Level.DEBUG, "Loading persistent fluid defaults from world");
        NBTTagList tl = tag.getTagList("DefaultFluidList", 8);
        for (int i = 0; i < tl.tagCount(); i++) {
            defaults.add(tl.getStringTagAt(i));
        }
    } else {
        FMLLog.getLogger().log(Level.DEBUG, "World is missing persistent fluid defaults - using local defaults");
    }
    loadFluidDefaults(HashBiMap.create(fluidIDs), defaults);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 77 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method saveWorld.

static void saveWorld(World world) {
    // only persist persistent worlds
    if (!(world instanceof WorldServer)) {
        return;
    }
    WorldServer worldServer = (WorldServer) world;
    File chunkDir = worldServer.getChunkSaveLocation();
    File chunkLoaderData = new File(chunkDir, "forcedchunks.dat");
    NBTTagCompound forcedChunkData = new NBTTagCompound();
    NBTTagList ticketList = new NBTTagList();
    forcedChunkData.setTag("TicketList", ticketList);
    Multimap<String, Ticket> ticketSet = tickets.get(worldServer);
    if (ticketSet == null)
        return;
    for (String modId : ticketSet.keySet()) {
        NBTTagCompound ticketHolder = new NBTTagCompound();
        ticketList.appendTag(ticketHolder);
        ticketHolder.setString("Owner", modId);
        NBTTagList tickets = new NBTTagList();
        ticketHolder.setTag("Tickets", tickets);
        for (Ticket tick : ticketSet.get(modId)) {
            NBTTagCompound ticket = new NBTTagCompound();
            ticket.setByte("Type", (byte) tick.ticketType.ordinal());
            ticket.setByte("ChunkListDepth", (byte) tick.maxDepth);
            if (tick.isPlayerTicket()) {
                ticket.setString("ModId", tick.modId);
                ticket.setString("Player", tick.player);
            }
            if (tick.modData != null) {
                ticket.setTag("ModData", tick.modData);
            }
            if (tick.ticketType == Type.ENTITY && tick.entity != null && tick.entity.writeToNBTOptional(new NBTTagCompound())) {
                ticket.setInteger("chunkX", MathHelper.floor(tick.entity.chunkCoordX));
                ticket.setInteger("chunkZ", MathHelper.floor(tick.entity.chunkCoordZ));
                ticket.setLong("PersistentIDMSB", tick.entity.getPersistentID().getMostSignificantBits());
                ticket.setLong("PersistentIDLSB", tick.entity.getPersistentID().getLeastSignificantBits());
                tickets.appendTag(ticket);
            } else if (tick.ticketType != Type.ENTITY) {
                tickets.appendTag(ticket);
            }
        }
    }
    try {
        CompressedStreamTools.write(forcedChunkData, chunkLoaderData);
    } catch (IOException e) {
        FMLLog.log(Level.WARN, e, "Unable to write forced chunk data to %s - chunkloading won't work", chunkLoaderData.getAbsolutePath());
        return;
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) IOException(java.io.IOException) File(java.io.File)

Example 78 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project MinecraftForge by MinecraftForge.

the class FMLContainer method getDataForWriting.

@Override
public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info) {
    NBTTagCompound fmlData = new NBTTagCompound();
    NBTTagList modList = new NBTTagList();
    for (ModContainer mc : Loader.instance().getActiveModList()) {
        NBTTagCompound mod = new NBTTagCompound();
        mod.setString("ModId", mc.getModId());
        mod.setString("ModVersion", mc.getVersion());
        modList.appendTag(mod);
    }
    fmlData.setTag("ModList", modList);
    NBTTagCompound registries = new NBTTagCompound();
    fmlData.setTag("Registries", registries);
    FMLLog.fine("Gathering id map for writing to world save %s", info.getWorldName());
    PersistentRegistryManager.GameDataSnapshot dataSnapshot = PersistentRegistryManager.takeSnapshot();
    for (Map.Entry<ResourceLocation, PersistentRegistryManager.GameDataSnapshot.Entry> e : dataSnapshot.entries.entrySet()) {
        NBTTagCompound data = new NBTTagCompound();
        registries.setTag(e.getKey().toString(), data);
        NBTTagList ids = new NBTTagList();
        for (Entry<ResourceLocation, Integer> item : e.getValue().ids.entrySet()) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString("K", item.getKey().toString());
            tag.setInteger("V", item.getValue());
            ids.appendTag(tag);
        }
        data.setTag("ids", ids);
        NBTTagList aliases = new NBTTagList();
        for (Entry<ResourceLocation, ResourceLocation> entry : e.getValue().aliases.entrySet()) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString("K", entry.getKey().toString());
            tag.setString("V", entry.getValue().toString());
            aliases.appendTag(tag);
        }
        data.setTag("aliases", aliases);
        NBTTagList subs = new NBTTagList();
        for (ResourceLocation entry : e.getValue().substitutions) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString("K", entry.toString());
            subs.appendTag(tag);
        }
        data.setTag("substitutions", subs);
        int[] blocked = new int[e.getValue().blocked.size()];
        int idx = 0;
        for (Integer i : e.getValue().blocked) {
            blocked[idx++] = i;
        }
        data.setIntArray("blocked", blocked);
        NBTTagList dummied = new NBTTagList();
        for (ResourceLocation entry : e.getValue().dummied) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString("K", entry.toString());
            dummied.appendTag(tag);
        }
        data.setTag("dummied", dummied);
    }
    return fmlData;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PersistentRegistryManager(net.minecraftforge.fml.common.registry.PersistentRegistryManager) NBTTagList(net.minecraft.nbt.NBTTagList) Entry(java.util.Map.Entry) ResourceLocation(net.minecraft.util.ResourceLocation) Map(java.util.Map)

Example 79 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project MinecraftForge by MinecraftForge.

the class ItemStackHandler method serializeNBT.

@Override
public NBTTagCompound serializeNBT() {
    NBTTagList nbtTagList = new NBTTagList();
    for (int i = 0; i < stacks.size(); i++) {
        if (!stacks.get(i).isEmpty()) {
            NBTTagCompound itemTag = new NBTTagCompound();
            itemTag.setInteger("Slot", i);
            stacks.get(i).writeToNBT(itemTag);
            nbtTagList.appendTag(itemTag);
        }
    }
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setTag("Items", nbtTagList);
    nbt.setInteger("Size", stacks.size());
    return nbt;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 80 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project Minechem by iopleke.

the class AugmentedItem method getAugments.

@Override
public Map<IAugment, Integer> getAugments(ItemStack stack) {
    Map<IAugment, Integer> result = new HashMap<IAugment, Integer>();
    if (stack.hasTagCompound() && stack.getTagCompound().hasKey(augmentList, Compendium.NBTTags.tagList)) {
        NBTTagList augments = stack.getTagCompound().getTagList(augmentList, Compendium.NBTTags.tagString);
        for (int i = 0; i < augments.tagCount(); i++) {
            String key = augments.getStringTagAt(i);
            result.put(AugmentRegistry.getAugment(key), (int) stack.getTagCompound().getCompoundTag(key).getByte(level));
        }
    }
    return result;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) HashMap(java.util.HashMap) IAugment(minechem.item.augment.augments.IAugment) NBTTagString(net.minecraft.nbt.NBTTagString)

Aggregations

NBTTagList (net.minecraft.nbt.NBTTagList)451 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)385 ItemStack (net.minecraft.item.ItemStack)69 NBTTagString (net.minecraft.nbt.NBTTagString)42 BlockPos (net.minecraft.util.math.BlockPos)18 HashMap (java.util.HashMap)17 Map (java.util.Map)17 NotNull (org.jetbrains.annotations.NotNull)17 ArrayList (java.util.ArrayList)14 AMVector3 (am2.api.math.AMVector3)9 ChunkPosition (net.minecraft.world.ChunkPosition)9 NBTBase (net.minecraft.nbt.NBTBase)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 Vec3d (net.minecraft.util.math.Vec3d)7 WorldCoordinate (mods.railcraft.api.core.WorldCoordinate)6 Block (net.minecraft.block.Block)6 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)5 Entity (net.minecraft.entity.Entity)5 TileEntity (net.minecraft.tileentity.TileEntity)5 ChunkPos (net.minecraft.util.math.ChunkPos)5