Add simple large map stitching
This commit is contained in:
@@ -23,6 +23,7 @@ import baritone.bot.behavior.impl.MemoryBehavior;
|
||||
import baritone.bot.behavior.impl.PathingBehavior;
|
||||
import baritone.bot.event.GameEventHandler;
|
||||
import baritone.bot.utils.InputOverrideHandler;
|
||||
import baritone.map.Map;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.io.File;
|
||||
@@ -71,6 +72,7 @@ public enum Baritone {
|
||||
registerBehavior(PathingBehavior.INSTANCE);
|
||||
registerBehavior(LookBehavior.INSTANCE);
|
||||
registerBehavior(MemoryBehavior.INSTANCE);
|
||||
registerBehavior(Map.INSTANCE);
|
||||
}
|
||||
|
||||
this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone");
|
||||
|
||||
@@ -28,6 +28,7 @@ import baritone.bot.pathing.movement.ActionCosts;
|
||||
import baritone.bot.pathing.movement.CalculationContext;
|
||||
import baritone.bot.pathing.movement.Movement;
|
||||
import baritone.bot.utils.pathing.BetterBlockPos;
|
||||
import baritone.map.Map;
|
||||
import baritone.map.MapChunk;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@@ -179,8 +180,7 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
}
|
||||
}
|
||||
if(msg.toLowerCase().equals("map")) {
|
||||
MapChunk chunk = new MapChunk(world().getChunk(player().getPosition()));
|
||||
chunk.writeImage();
|
||||
Map.INSTANCE.writeImage();
|
||||
}
|
||||
if (Baritone.settings().byLowerName.containsKey(msg.toLowerCase())) {
|
||||
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg.toLowerCase());
|
||||
|
||||
@@ -1,5 +1,68 @@
|
||||
package baritone.map;
|
||||
|
||||
public class Map {
|
||||
import baritone.bot.Baritone;
|
||||
import baritone.bot.behavior.Behavior;
|
||||
import baritone.bot.event.events.ChunkEvent;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class Map extends Behavior {
|
||||
|
||||
public static final Map INSTANCE = new Map();
|
||||
|
||||
private Map() {}
|
||||
|
||||
private BufferedImage fullImage = new BufferedImage(4080, 4080, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
@Override
|
||||
public void onChunkEvent(ChunkEvent event) {
|
||||
if(event.getType() != ChunkEvent.Type.POPULATE)
|
||||
return;
|
||||
|
||||
MapChunk map = new MapChunk(world().getChunk(event.getX(), event.getZ()));
|
||||
ChunkPos pos = map.getChunk().getPos();
|
||||
int startX;
|
||||
int startZ;
|
||||
if(pos.x == 0 && pos.z == 0) {
|
||||
startX = (fullImage.getWidth() / 2) - 9;
|
||||
startZ = (fullImage.getHeight() / 2) - 9;
|
||||
} else {
|
||||
int widthOffset = (((fullImage.getWidth() / 2) - 1) + (int) Math.signum(pos.x) * -8);
|
||||
int heightOffset = (((fullImage.getHeight() / 2) - 1) + (int) Math.signum(pos.z) * -8);
|
||||
startX = widthOffset + (16 * (pos.x + (pos.x > 0 ? -1 : 0)));
|
||||
startZ = heightOffset + (16 * (pos.z + (pos.z > 0 ? -1 : 0)));
|
||||
}
|
||||
|
||||
Graphics graphics = fullImage.getGraphics();
|
||||
graphics.drawImage(map.generateOverview(), startX, startZ, null);
|
||||
}
|
||||
|
||||
public void writeImage() {
|
||||
Path image = getImagePath();
|
||||
if(!Files.exists(image.getParent())) {
|
||||
try {
|
||||
Files.createDirectory(image.getParent());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
ImageIO.write(fullImage, "PNG", image.toFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Path getImagePath() {
|
||||
return new File(new File(Baritone.INSTANCE.getDir(), "map"), "full-map.png").toPath();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import baritone.bot.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -25,6 +24,16 @@ public class MapChunk {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
public BufferedImage generateOverview() {
|
||||
BufferedImage bufferedImage = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
bufferedImage.setRGB(x, z, getColor(x, z));
|
||||
}
|
||||
}
|
||||
return bufferedImage;
|
||||
}
|
||||
|
||||
public void writeImage() {
|
||||
Path image = getImagePath();
|
||||
if(!Files.exists(image.getParent())) {
|
||||
@@ -34,12 +43,7 @@ public class MapChunk {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
BufferedImage bufferedImage = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
bufferedImage.setRGB(x, z, getColor(x, z));
|
||||
}
|
||||
}
|
||||
BufferedImage bufferedImage = generateOverview();
|
||||
try {
|
||||
ImageIO.write(bufferedImage, "PNG", image.toFile());
|
||||
} catch (IOException e) {
|
||||
@@ -52,6 +56,10 @@ public class MapChunk {
|
||||
return new File(new File(Baritone.INSTANCE.getDir(), "map"), "chunk" + chunk.x + "-" + chunk.z + ".png").toPath();
|
||||
}
|
||||
|
||||
public Chunk getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* getColor is a re-implementation of the Minecraft ItemMap's
|
||||
* surface mapping system. This is significantly less convoluted
|
||||
|
||||
Reference in New Issue
Block a user