Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.manusoftar.minefinder.io;
- import java.awt.Point;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.Iterator;
- import java.util.LinkedList;
- import net.minecraft.nbt.CompressedStreamTools;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.util.BlockPos;
- import net.minecraftforge.common.DimensionManager;
- import net.minecraftforge.common.util.Constants.NBT;
- public final class FileIO {
- private static NBTTagCompound ublocks;
- private static NBTTagCompound mines;
- private static File getDataFile() {
- return new File(DimensionManager.getCurrentSaveRootDirectory(), "minefinder/mines.dat");
- }
- public static LinkedList<BlockPos> readUnbrekableBlocks() {
- LinkedList<BlockPos> blocks = new LinkedList<BlockPos>();
- try {
- InputStream is = new FileInputStream(getDataFile());
- NBTTagCompound nbc = CompressedStreamTools.readCompressed(is);
- if (nbc.hasKey("UnbreakableBlocks")){
- NBTTagList list = nbc.getTagList("UnbreakableBlocks", NBT.TAG_COMPOUND);
- for ( int i = 0; i < list.tagCount(); i++){
- NBTTagCompound ntc = list.getCompoundTagAt(i);
- int x,y,z;
- x = ntc.getInteger("X");
- y = ntc.getInteger("Y");
- z = ntc.getInteger("Z");
- BlockPos bp = new BlockPos(x,y,z);
- blocks.push(bp);
- }
- return blocks;
- }
- } catch (Exception ex){
- ex.printStackTrace();
- }
- return null;
- }
- public static LinkedList<Point> readMinesFound(){
- LinkedList<Point> blocks = new LinkedList<Point>();
- try {
- InputStream is = new FileInputStream(getDataFile());
- NBTTagCompound nbc = CompressedStreamTools.readCompressed(is);
- if (nbc.hasKey("UnbreakableBlocks")){
- NBTTagList list = nbc.getTagList("UnbreakableBlocks", NBT.TAG_COMPOUND);
- for ( int i = 0; i < list.tagCount(); i++){
- NBTTagCompound ntc = list.getCompoundTagAt(i);
- int x,y,z;
- x = ntc.getInteger("X");
- z = ntc.getInteger("Z");
- Point pt = new Point(x,z);
- blocks.push(pt);
- }
- return blocks;
- }
- } catch (Exception ex){
- ex.printStackTrace();
- }
- return null;
- }
- public static void prepareUnbreakableBlocks(LinkedList<BlockPos> blocks){
- try {
- Iterator<BlockPos> it = blocks.iterator();
- InputStream is = new FileInputStream(getDataFile());
- NBTTagCompound nbt = CompressedStreamTools.readCompressed(is);
- NBTTagList list = new NBTTagList();
- if (nbt.hasKey("UnbreakableBlocks")) {
- list = nbt.getTagList("UnbreakableBlocks", NBT.TAG_COMPOUND);
- }
- while (it.hasNext()){
- BlockPos pos = it.next();
- NBTTagCompound ntc = new NBTTagCompound();
- ntc.setInteger("X", pos.getX());
- ntc.setInteger("Y", pos.getY());
- ntc.setInteger("Z", pos.getZ());
- list.appendTag(ntc);
- }
- NBTTagCompound nbc = new NBTTagCompound();
- nbc.setTag("UnbreakableBlocks", list);
- //OutputStream os = new FileOutputStream(getDataFile());
- //CompressedStreamTools.writeCompressed(nbc, os);
- ublocks = (NBTTagCompound) nbc.copy();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- public static void prepareMinesFound(LinkedList<Point> blocks){
- try {
- Iterator<Point> it = blocks.iterator();
- InputStream is = new FileInputStream(getDataFile());
- NBTTagCompound nbt = CompressedStreamTools.readCompressed(is);
- NBTTagList list = new NBTTagList();
- if (nbt.hasKey("MinesFound")){
- list = nbt.getTagList("MinesFound", NBT.TAG_COMPOUND);
- }
- while (it.hasNext()){
- Point pos = it.next();
- NBTTagCompound ntc = new NBTTagCompound();
- ntc.setInteger("X", pos.x);
- ntc.setInteger("Y", pos.y);
- list.appendTag(ntc);
- }
- NBTTagCompound nbc = new NBTTagCompound();
- nbc.setTag("MinesFound", list);
- /*OutputStream os = new FileOutputStream(getDataFile());
- CompressedStreamTools.writeCompressed(nbc, os);*/
- mines = (NBTTagCompound) nbc.copy();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- public static void saveChanges(){
- try {
- OutputStream os = new FileOutputStream(getDataFile());
- NBTTagCompound nbc = new NBTTagCompound();
- nbc.setTag("", mines);
- nbc.setTag("",ublocks);
- } catch (Exception ex) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement