Search in sources :

Example 1 with NBTTagCompound

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

the class DimensionManager method saveDimensionDataMap.

public static NBTTagCompound saveDimensionDataMap() {
    int[] data = new int[(dimensionMap.length() + Integer.SIZE - 1) / Integer.SIZE];
    NBTTagCompound dimMap = new NBTTagCompound();
    for (int i = 0; i < data.length; i++) {
        int val = 0;
        for (int j = 0; j < Integer.SIZE; j++) {
            val |= dimensionMap.get(i * Integer.SIZE + j) ? (1 << j) : 0;
        }
        data[i] = val;
    }
    dimMap.setIntArray("DimensionArray", data);
    return dimMap;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound 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 3 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound 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 4 with NBTTagCompound

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

the class FMLClientHandler method tryLoadExistingWorld.

public void tryLoadExistingWorld(GuiWorldSelection selectWorldGUI, WorldSummary comparator) {
    File dir = new File(getSavesDir(), comparator.getFileName());
    NBTTagCompound leveldat;
    try {
        leveldat = CompressedStreamTools.readCompressed(new FileInputStream(new File(dir, "level.dat")));
    } catch (Exception e) {
        try {
            leveldat = CompressedStreamTools.readCompressed(new FileInputStream(new File(dir, "level.dat_old")));
        } catch (Exception e1) {
            FMLLog.warning("There appears to be a problem loading the save %s, both level files are unreadable.", comparator.getFileName());
            return;
        }
    }
    NBTTagCompound fmlData = leveldat.getCompoundTag("FML");
    if (fmlData.hasKey("ModItemData")) {
        showGuiScreen(new GuiOldSaveLoadConfirm(comparator.getFileName(), comparator.getDisplayName(), selectWorldGUI));
    } else {
        try {
            client.launchIntegratedServer(comparator.getFileName(), comparator.getDisplayName(), null);
        } catch (StartupQuery.AbortedException e) {
        // ignore
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) StartupQuery(net.minecraftforge.fml.common.StartupQuery) File(java.io.File) FileInputStream(java.io.FileInputStream) WrongMinecraftVersionException(net.minecraftforge.fml.common.WrongMinecraftVersionException) DuplicateModsFoundException(net.minecraftforge.fml.common.DuplicateModsFoundException) LoaderException(net.minecraftforge.fml.common.LoaderException) IOException(java.io.IOException) ModSortingException(net.minecraftforge.fml.common.toposort.ModSortingException) MissingModsException(net.minecraftforge.fml.common.MissingModsException) Java8VersionException(net.minecraftforge.fml.common.Java8VersionException)

Example 5 with NBTTagCompound

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

the class GameRegistry method makeItemStack.

/**
     * Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible
     * <p/>
     * Will return null if the item doesn't exist (because it's not from a loaded mod for example)
     * Will throw a {@link RuntimeException} if the nbtString is invalid for use in an {@link ItemStack}
     *
     * @param itemName  a registry name reference
     * @param meta      the meta
     * @param stackSize the stack size
     * @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT}
     * @return a new itemstack
     */
@Nonnull
public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString) {
    if (itemName == null) {
        throw new IllegalArgumentException("The itemName cannot be null");
    }
    Item item = GameData.getItemRegistry().getObject(new ResourceLocation(itemName));
    if (item == null) {
        FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
        return ItemStack.EMPTY;
    }
    ItemStack is = new ItemStack(item, stackSize, meta);
    if (!Strings.isNullOrEmpty(nbtString)) {
        NBTBase nbttag = null;
        try {
            nbttag = JsonToNBT.getTagFromJson(nbtString);
        } catch (NBTException e) {
            FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e);
            throw Throwables.propagate(e);
        }
        if (!(nbttag instanceof NBTTagCompound)) {
            FMLLog.getLogger().log(Level.WARN, "Unexpected NBT string - multiple values {}", nbtString);
            throw new RuntimeException("Invalid NBT JSON");
        } else {
            is.setTagCompound((NBTTagCompound) nbttag);
        }
    }
    return is;
}
Also used : Item(net.minecraft.item.Item) NBTBase(net.minecraft.nbt.NBTBase) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) NBTException(net.minecraft.nbt.NBTException) Nonnull(javax.annotation.Nonnull)

Aggregations

NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3985 NBTTagList (net.minecraft.nbt.NBTTagList)1052 ItemStack (net.minecraft.item.ItemStack)883 BlockPos (net.minecraft.util.math.BlockPos)229 TileEntity (net.minecraft.tileentity.TileEntity)173 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)148 ArrayList (java.util.ArrayList)99 Block (net.minecraft.block.Block)98 ResourceLocation (net.minecraft.util.ResourceLocation)96 IBlockState (net.minecraft.block.state.IBlockState)92 EntityPlayer (net.minecraft.entity.player.EntityPlayer)81 NBTTagString (net.minecraft.nbt.NBTTagString)79 Nonnull (javax.annotation.Nonnull)74 Map (java.util.Map)71 UUID (java.util.UUID)69 NBTBase (net.minecraft.nbt.NBTBase)66 HashMap (java.util.HashMap)64 EnumFacing (net.minecraft.util.EnumFacing)61 NotNull (org.jetbrains.annotations.NotNull)60 Item (net.minecraft.item.Item)55