Skip to content

Instantly share code, notes, and snippets.

@StillManic
Created April 11, 2016 06:39
Show Gist options
  • Save StillManic/03e9ba79b7cb44887b3463ec53e940ca to your computer and use it in GitHub Desktop.
Save StillManic/03e9ba79b7cb44887b3463ec53e940ca to your computer and use it in GitHub Desktop.
public boolean saveTemplateToFile(MinecraftServer server, ResourceLocation id) {
if (this.blocks == null || this.blocks.isEmpty()) return false;
File file = server.getFile("templates");
if ((!file.exists() && !file.mkdirs()) || !file.isDirectory()) return false;
file = new File(file, id.getResourcePath());
NBTTagCompound compound = new NBTTagCompound();
OutputStream outputStream = null;
boolean success;
try {
FMLLog.info(file.getAbsolutePath());
this.write(compound);
outputStream = new FileOutputStream(file);
CompressedStreamTools.writeCompressed(compound, outputStream);
return true;
} catch (Throwable throwable) {
success = false;
} finally {
IOUtils.closeQuietly(outputStream);
}
return success;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment