integrate map directory
This commit is contained in:
@@ -31,6 +31,10 @@ public class WorldData {
|
|||||||
this.waypoints = new Waypoints(directory.resolve("waypoints"));
|
this.waypoints = new Waypoints(directory.resolve("waypoints"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Path getMapDirectory() {
|
||||||
|
return directory.resolve("map");
|
||||||
|
}
|
||||||
|
|
||||||
void onClose() {
|
void onClose() {
|
||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package baritone.map;
|
package baritone.map;
|
||||||
|
|
||||||
import baritone.Baritone;
|
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
|
import baritone.chunk.WorldProvider;
|
||||||
import baritone.event.events.ChunkEvent;
|
import baritone.event.events.ChunkEvent;
|
||||||
import net.minecraft.util.math.ChunkPos;
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -22,17 +21,17 @@ public class Map extends Behavior {
|
|||||||
private Map() {
|
private Map() {
|
||||||
try {
|
try {
|
||||||
fullImage = ImageIO.read(getImagePath().toFile());
|
fullImage = ImageIO.read(getImagePath().toFile());
|
||||||
} catch(IOException ignored) { }
|
} catch (IOException ignored) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChunkEvent(ChunkEvent event) {
|
public void onChunkEvent(ChunkEvent event) {
|
||||||
if(event.getType() != ChunkEvent.Type.POPULATE)
|
if (event.getType() != ChunkEvent.Type.POPULATE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MapChunk map = new MapChunk(world().getChunk(event.getX(), event.getZ()));
|
MapChunk map = new MapChunk(world().getChunk(event.getX(), event.getZ()));
|
||||||
stitchMapChunk(map);
|
stitchMapChunk(map);
|
||||||
if(world().getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ() - 1)) {
|
if (world().getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ() - 1)) {
|
||||||
stitchMapChunk(new MapChunk(world().getChunk(event.getX(), event.getZ() - 1)));
|
stitchMapChunk(new MapChunk(world().getChunk(event.getX(), event.getZ() - 1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +46,7 @@ public class Map extends Behavior {
|
|||||||
|
|
||||||
public void writeImage() {
|
public void writeImage() {
|
||||||
Path image = getImagePath();
|
Path image = getImagePath();
|
||||||
if(!Files.exists(image.getParent())) {
|
if (!Files.exists(image.getParent())) {
|
||||||
try {
|
try {
|
||||||
Files.createDirectory(image.getParent());
|
Files.createDirectory(image.getParent());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -63,7 +62,7 @@ public class Map extends Behavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Path getImagePath() {
|
public Path getImagePath() {
|
||||||
return new File(new File(Baritone.INSTANCE.getDir(), "map"), "full-map.png").toPath();
|
return WorldProvider.INSTANCE.getCurrentWorld().getMapDirectory().resolve("full-map.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package baritone.map;
|
package baritone.map;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.chunk.WorldProvider;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.block.material.MapColor;
|
import net.minecraft.block.material.MapColor;
|
||||||
@@ -12,7 +12,6 @@ import net.minecraft.world.chunk.Chunk;
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -27,8 +26,8 @@ public class MapChunk {
|
|||||||
|
|
||||||
public BufferedImage generateOverview() {
|
public BufferedImage generateOverview() {
|
||||||
BufferedImage bufferedImage = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
|
BufferedImage bufferedImage = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
|
||||||
for(int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
for(int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
bufferedImage.setRGB(x, z, getColor(x, z));
|
bufferedImage.setRGB(x, z, getColor(x, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,7 +36,7 @@ public class MapChunk {
|
|||||||
|
|
||||||
public void writeImage() {
|
public void writeImage() {
|
||||||
Path image = getImagePath();
|
Path image = getImagePath();
|
||||||
if(!Files.exists(image.getParent())) {
|
if (!Files.exists(image.getParent())) {
|
||||||
try {
|
try {
|
||||||
Files.createDirectory(image.getParent());
|
Files.createDirectory(image.getParent());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -54,7 +53,7 @@ public class MapChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Path getImagePath() {
|
public Path getImagePath() {
|
||||||
return new File(new File(Baritone.INSTANCE.getDir(), "map"), "chunk" + chunk.x + "-" + chunk.z + ".png").toPath();
|
return WorldProvider.INSTANCE.getCurrentWorld().getMapDirectory().resolve("chunk" + chunk.x + "-" + chunk.z + ".png");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chunk getChunk() {
|
public Chunk getChunk() {
|
||||||
@@ -65,7 +64,7 @@ public class MapChunk {
|
|||||||
* getColor is a re-implementation of the Minecraft ItemMap's
|
* getColor is a re-implementation of the Minecraft ItemMap's
|
||||||
* surface mapping system. This is significantly less convoluted
|
* surface mapping system. This is significantly less convoluted
|
||||||
* than the poorly de-obfuscated code.
|
* than the poorly de-obfuscated code.
|
||||||
*
|
* <p>
|
||||||
* We perform shading of the given coordinate relative to the
|
* We perform shading of the given coordinate relative to the
|
||||||
* position one to the north of the coordinate, as can be seen
|
* position one to the north of the coordinate, as can be seen
|
||||||
* in Minecraft's maps.
|
* in Minecraft's maps.
|
||||||
@@ -83,7 +82,7 @@ public class MapChunk {
|
|||||||
|
|
||||||
// The chunk heightMap returns the first non-full block above the surface, including bushes.
|
// The chunk heightMap returns the first non-full block above the surface, including bushes.
|
||||||
// We have to check this and shift our block down by one if the color is "air" (as in, there's no real block there)
|
// We have to check this and shift our block down by one if the color is "air" (as in, there's no real block there)
|
||||||
if(mapColor == MapColor.AIR) {
|
if (mapColor == MapColor.AIR) {
|
||||||
blockPos = blockPos.down();
|
blockPos = blockPos.down();
|
||||||
blockState = BlockStateInterface.get(blockPos);
|
blockState = BlockStateInterface.get(blockPos);
|
||||||
mapColor = blockState.getMapColor(chunk.getWorld(), blockPos);
|
mapColor = blockState.getMapColor(chunk.getWorld(), blockPos);
|
||||||
@@ -103,24 +102,24 @@ public class MapChunk {
|
|||||||
// loaded, or the same as our target block if the shading chunk is not.
|
// loaded, or the same as our target block if the shading chunk is not.
|
||||||
offset = new BlockPos(offset.getX(), chunk.getWorld().getChunk(offset).getHeight(offset), offset.getZ());
|
offset = new BlockPos(offset.getX(), chunk.getWorld().getChunk(offset).getHeight(offset), offset.getZ());
|
||||||
// And once again, check to make sure we have an actual colored block an not "air"
|
// And once again, check to make sure we have an actual colored block an not "air"
|
||||||
if(BlockStateInterface.get(offset).getMapColor(chunk.getWorld(), offset) == MapColor.AIR)
|
if (BlockStateInterface.get(offset).getMapColor(chunk.getWorld(), offset) == MapColor.AIR)
|
||||||
offset = offset.down();
|
offset = offset.down();
|
||||||
|
|
||||||
float heightCoef;
|
float heightCoef;
|
||||||
// Check if we need to handle water depth shading
|
// Check if we need to handle water depth shading
|
||||||
if(blockState.getMaterial().isLiquid()) {
|
if (blockState.getMaterial().isLiquid()) {
|
||||||
heightCoef = 1.0f;
|
heightCoef = 1.0f;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
// Iterate over the 4 layers of water shading and color proportional to the depth
|
// Iterate over the 4 layers of water shading and color proportional to the depth
|
||||||
for(; i < 5; i++) {
|
for (; i < 5; i++) {
|
||||||
if(BlockStateInterface.get(blockPos.down(i * 2)).getMaterial().isLiquid()) {
|
if (BlockStateInterface.get(blockPos.down(i * 2)).getMaterial().isLiquid()) {
|
||||||
heightCoef -= 0.075f;
|
heightCoef -= 0.075f;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add checkerboard shading to the odd layers to give texture
|
// Add checkerboard shading to the odd layers to give texture
|
||||||
if(i % 2 == 0)
|
if (i % 2 == 0)
|
||||||
heightCoef += 0.075f * (((x + z) % 2 == 0) ? -1 : 1);
|
heightCoef += 0.075f * (((x + z) % 2 == 0) ? -1 : 1);
|
||||||
} else {
|
} else {
|
||||||
// We start the heightCoef at 0.8 to darken the colors similar to vanilla Minecraft's.
|
// We start the heightCoef at 0.8 to darken the colors similar to vanilla Minecraft's.
|
||||||
|
|||||||
Reference in New Issue
Block a user