Skip to content

Commit

Permalink
Allow offset coordinates to be negative
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels-NTG committed Dec 17, 2022
1 parent abd60a8 commit 42d6cb3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '0.6.2'
version = '0.6.3'
group = 'com.nilsgawlik.gdmchttp' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'gdmchttp'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,22 @@ protected void internalHandle(HttpExchange httpExchange) throws IOException {

if (method.equals("get")) {
ServerLevel serverLevel = getServerLevel(dimension);
int xOffset = x + dx;
int xMin = Math.min(x, xOffset);
int xMax = Math.max(x, xOffset);

int yOffset = y + dy;
int yMin = Math.min(y, yOffset);
int yMax = Math.max(y, yOffset);

int zOffset = z + dz;
int zMin = Math.min(z, zOffset);
int zMax = Math.max(z, zOffset);
if (returnJson) {
JsonArray jsonArray = new JsonArray();
for (int rangeX = x; rangeX < x + dx; rangeX++) {
for (int rangeY = y; rangeY < y + dy; rangeY++) {
for (int rangeZ = z; rangeZ < z + dz; rangeZ++) {
for (int rangeX = xMin; rangeX < xMax; rangeX++) {
for (int rangeY = yMin; rangeY < yMax; rangeY++) {
for (int rangeZ = zMin; rangeZ < zMax; rangeZ++) {
BlockPos blockPos = new BlockPos(rangeX, rangeY, rangeZ);
String biomeName = serverLevel.getBiome(blockPos).unwrapKey().get().location().toString();
JsonObject json = new JsonObject();
Expand All @@ -73,9 +84,9 @@ protected void internalHandle(HttpExchange httpExchange) throws IOException {
responseString = new Gson().toJson(jsonArray);
} else {
ArrayList<String> biomesList = new ArrayList<>();
for (int rangeX = x; rangeX < x + dx; rangeX++) {
for (int rangeY = y; rangeY < y + dy; rangeY++) {
for (int rangeZ = z; rangeZ < z + dz; rangeZ++) {
for (int rangeX = xMin; rangeX < xMax; rangeX++) {
for (int rangeY = yMin; rangeY < yMax; rangeY++) {
for (int rangeZ = zMin; rangeZ < zMax; rangeZ++) {
BlockPos blockPos = new BlockPos(rangeX, rangeY, rangeZ);
String biomeName = serverLevel.getBiome(blockPos).unwrapKey().get().location().toString();
biomesList.add(rangeX + " " + rangeY + " " + rangeZ + " " + biomeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,23 @@ public void internalHandle(HttpExchange httpExchange) throws IOException {
responseString = String.join("\n", returnValues);
}
} else if (method.equals("get")) {
int xOffset = x + dx;
int xMin = Math.min(x, xOffset);
int xMax = Math.max(x, xOffset);

int yOffset = y + dy;
int yMin = Math.min(y, yOffset);
int yMax = Math.max(y, yOffset);

int zOffset = z + dz;
int zMin = Math.min(z, zOffset);
int zMax = Math.max(z, zOffset);

if (returnJson) {
JsonArray jsonArray = new JsonArray();
for (int rangeX = x; rangeX < x + dx; rangeX++) {
for (int rangeY = y; rangeY < y + dy; rangeY++) {
for (int rangeZ = z; rangeZ < z + dz; rangeZ++) {
for (int rangeX = xMin; rangeX < xMax; rangeX++) {
for (int rangeY = yMin; rangeY < yMax; rangeY++) {
for (int rangeZ = zMin; rangeZ < zMax; rangeZ++) {
BlockPos blockPos = new BlockPos(rangeX, rangeY, rangeZ);
String blockId = getBlockAsStr(blockPos);
JsonObject json = new JsonObject();
Expand All @@ -185,9 +197,9 @@ public void internalHandle(HttpExchange httpExchange) throws IOException {
responseString = new Gson().toJson(jsonArray);
} else {
ArrayList<String> responseList = new ArrayList<>();
for (int rangeX = x; rangeX < x + dx; rangeX++) {
for (int rangeY = y; rangeY < y + dy; rangeY++) {
for (int rangeZ = z; rangeZ < z + dz; rangeZ++) {
for (int rangeX = xMin; rangeX < xMax; rangeX++) {
for (int rangeY = yMin; rangeY < yMax; rangeY++) {
for (int rangeZ = zMin; rangeZ < zMax; rangeZ++) {
BlockPos blockPos = new BlockPos(rangeX, rangeY, rangeZ);
String listItem = rangeX + " " + rangeY + " " + rangeZ + " " + getBlockAsStr(blockPos);
if (includeState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ public void internalHandle(HttpExchange httpExchange) throws IOException {
ServerLevel serverLevel = getServerLevel(dimension);

CompletableFuture<ListTag> cfs = CompletableFuture.supplyAsync(() -> {
int xOffset = chunkX + chunkDX;
int xMin = Math.min(chunkX, xOffset);
int xMax = Math.max(chunkX, xOffset);

int zOffset = chunkZ + chunkDZ;
int zMin = Math.min(chunkZ, zOffset);
int zMax = Math.max(chunkZ, zOffset);
ListTag returnList = new ListTag();
for(int z = chunkZ; z < chunkZ + chunkDZ; z++)
for(int x = chunkX; x < chunkX + chunkDX; x++) {
for(int z = zMin; z < zMax; z++)
for(int x = xMin; x < xMax; x++) {
LevelChunk chunk = serverLevel.getChunk(x, z);

CompoundTag chunkNBT = ChunkSerializer.write(serverLevel, chunk);
returnList.add(chunkNBT);
}
Expand Down

0 comments on commit 42d6cb3

Please sign in to comment.