Skip to content

Commit

Permalink
Basic implementation of World is realised.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Fedin committed Nov 23, 2016
1 parent d44ef9b commit 9b6da97
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
42 changes: 41 additions & 1 deletion src/main/java/ru/wpstuio/amorphine/mcaliases/World.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
package ru.wpstuio.amorphine.mcaliases;

import net.minecraft.world.level.chunk.storage.RegionFile;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

/**
* Created by amorphine on 21.11.16.
*/
public class World {
private File save_dir;
private File world_dir;

private HashMap region_files = new HashMap<int[], File>();
private HashMap regions = new HashMap<int[], Region>();

public World(File world_dir) throws IOException {
this.world_dir = world_dir;
if (!world_dir.exists()) {
throw new IOException("Cannot access " + world_dir.getAbsolutePath() + ": No such file or directory");
}

String[] file_list = world_dir.list();
for(String file_name: file_list) {
if (file_name.endsWith(".mca")) {
String[] splitted_file_name = file_name.split("\\.");
if (splitted_file_name.length < 4) {
continue;
}

String path_to_region = world_dir.getAbsolutePath() + "/" + file_name;
File region_file = new File(path_to_region);

int[] cords = {
Integer.parseInt(splitted_file_name[1]),
Integer.parseInt(splitted_file_name[2])
};
region_files.put(cords, region_file);

RegionFile rg_file = new RegionFile(region_file);
Region region = new Region(rg_file);
regions.put(cords, region);
}
}
}

}
16 changes: 14 additions & 2 deletions src/test/java/TestWorld.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* Created by amorphine on 23.11.16.
*/
import static com.sun.javafx.PlatformUtil.isWindows;
import static org.junit.Assert.*;

import com.mojang.nbt.NbtIo;
import net.minecraft.world.level.chunk.storage.RegionFile;
Expand All @@ -11,16 +9,29 @@
import org.junit.Test;
import ru.wpstuio.amorphine.mcaliases.Chunk;
import ru.wpstuio.amorphine.mcaliases.Region;
import ru.wpstuio.amorphine.mcaliases.World;

import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class TestWorld {
@Test
public void testAdd() {

World world;

try {
world = new World(new File ("/home/amorphine/mine-thermos/world/region"));
} catch (IOException e) {
e.printStackTrace();
}

/*
String path_to_local_ini = "local_presets.ini";
String path_to_ini = "presets.ini";
Expand Down Expand Up @@ -65,5 +76,6 @@ public void testAdd() {
byte result = chunks[31][0].getBlockId(-3, 64, 6);
assertTrue(id_to_make == result);
*/
}
}

0 comments on commit 9b6da97

Please sign in to comment.