forked from RepoMirrors/baritone
Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d6c766fb66 | ||
|
b2e69efbf2 | ||
|
9746ed26be | ||
|
c9c807a319 | ||
|
1b83c243ec | ||
|
61b61ea07b | ||
|
d16d5ba0e2 | ||
|
9914620f10 | ||
|
c5eda17154 | ||
|
83a91be53c | ||
|
3b5e2f9d87 | ||
|
7aa071e074 | ||
|
91ce628ec2 | ||
|
e6eac166d9 | ||
|
389748356a | ||
|
dc6a9af9c5 | ||
|
01bb5f1712 | ||
|
0132dd4a20 | ||
|
9bbb89f616 | ||
|
c89324be5b | ||
|
3abacb3b65 | ||
|
64cf201953 | ||
|
aa6f025ff0 | ||
|
c301ea5878 | ||
|
135149603f | ||
|
dcd379f44c |
@ -23,6 +23,7 @@ import baritone.behavior.impl.MemoryBehavior;
|
||||
import baritone.behavior.impl.PathingBehavior;
|
||||
import baritone.behavior.impl.LocationTrackingBehavior;
|
||||
import baritone.event.GameEventHandler;
|
||||
import baritone.map.Map;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@ -71,8 +72,10 @@ public enum Baritone {
|
||||
registerBehavior(PathingBehavior.INSTANCE);
|
||||
registerBehavior(LookBehavior.INSTANCE);
|
||||
registerBehavior(MemoryBehavior.INSTANCE);
|
||||
registerBehavior(Map.INSTANCE);
|
||||
registerBehavior(LocationTrackingBehavior.INSTANCE);
|
||||
}
|
||||
|
||||
this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone");
|
||||
if (!Files.exists(dir.toPath())) {
|
||||
try {
|
||||
|
@ -36,6 +36,10 @@ public class WorldData {
|
||||
this.waypoints = new Waypoints(directory.resolve("waypoints"));
|
||||
}
|
||||
|
||||
public Path getMapDirectory() {
|
||||
return directory.resolve("map");
|
||||
}
|
||||
|
||||
void onClose() {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
|
68
src/main/java/baritone/map/Map.java
Normal file
68
src/main/java/baritone/map/Map.java
Normal file
@ -0,0 +1,68 @@
|
||||
package baritone.map;
|
||||
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.event.events.ChunkEvent;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
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 BufferedImage fullImage = new BufferedImage(4080, 4080, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
private Map() {
|
||||
try {
|
||||
fullImage = ImageIO.read(getImagePath().toFile());
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkEvent(ChunkEvent event) {
|
||||
if (event.getType() != ChunkEvent.Type.POPULATE)
|
||||
return;
|
||||
|
||||
MapChunk map = new MapChunk(world().getChunk(event.getX(), event.getZ()));
|
||||
stitchMapChunk(map);
|
||||
if (world().getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ() - 1)) {
|
||||
stitchMapChunk(new MapChunk(world().getChunk(event.getX(), event.getZ() - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
private void stitchMapChunk(MapChunk map) {
|
||||
ChunkPos pos = map.getChunk().getPos();
|
||||
int startX = pos.x * 16 + (fullImage.getWidth() / 2) - 8;
|
||||
int startZ = pos.z * 16 + (fullImage.getHeight() / 2) - 8;
|
||||
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 WorldProvider.INSTANCE.getCurrentWorld().getMapDirectory().resolve("full-map.png");
|
||||
}
|
||||
|
||||
}
|
135
src/main/java/baritone/map/MapChunk.java
Normal file
135
src/main/java/baritone/map/MapChunk.java
Normal file
@ -0,0 +1,135 @@
|
||||
package baritone.map;
|
||||
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class MapChunk {
|
||||
|
||||
private Chunk chunk;
|
||||
|
||||
public MapChunk(Chunk chunk) {
|
||||
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())) {
|
||||
try {
|
||||
Files.createDirectory(image.getParent());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
BufferedImage bufferedImage = generateOverview();
|
||||
try {
|
||||
ImageIO.write(bufferedImage, "PNG", image.toFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Path getImagePath() {
|
||||
return WorldProvider.INSTANCE.getCurrentWorld().getMapDirectory().resolve("chunk" + chunk.x + "-" + chunk.z + ".png");
|
||||
}
|
||||
|
||||
public Chunk getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* getColor is a re-implementation of the Minecraft ItemMap's
|
||||
* surface mapping system. This is significantly less convoluted
|
||||
* than the poorly de-obfuscated code.
|
||||
* <p>
|
||||
* We perform shading of the given coordinate relative to the
|
||||
* position one to the north of the coordinate, as can be seen
|
||||
* in Minecraft's maps.
|
||||
*
|
||||
* @param x relative x coordinate to the start of the chunk
|
||||
* @param z relative z coord.
|
||||
* @return Integer RGB value with contextual shading
|
||||
*/
|
||||
private int getColor(int x, int z) {
|
||||
int chunkX = chunk.getPos().getXStart() + x;
|
||||
int chunkZ = chunk.getPos().getZStart() + z;
|
||||
BlockPos blockPos = new BetterBlockPos(chunkX, chunk.getHeight(new BetterBlockPos(chunkX, 0, chunkZ)), chunkZ);
|
||||
IBlockState blockState = BlockStateInterface.get(blockPos);
|
||||
MapColor mapColor = blockState.getMapColor(chunk.getWorld(), blockPos);
|
||||
|
||||
// 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)
|
||||
if (mapColor == MapColor.AIR) {
|
||||
blockPos = blockPos.down();
|
||||
blockState = BlockStateInterface.get(blockPos);
|
||||
mapColor = blockState.getMapColor(chunk.getWorld(), blockPos);
|
||||
}
|
||||
|
||||
Color color = new Color(mapColor.colorValue);
|
||||
int red = color.getRed();
|
||||
int green = color.getGreen();
|
||||
int blue = color.getBlue();
|
||||
|
||||
// Now we get the proper block for the position one to the north.
|
||||
BlockPos offset = blockPos.offset(EnumFacing.NORTH);
|
||||
// If we are at the north border of the chunk, we need to get the next chunk
|
||||
// to the north to ensure that we shade properly.
|
||||
offset = chunk.getWorld().getChunk(offset).isLoaded() ? offset : offset.south();
|
||||
// We adjust the height of the offset to the proper height value if the shading chunk is
|
||||
// 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());
|
||||
// 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)
|
||||
offset = offset.down();
|
||||
|
||||
float heightCoef;
|
||||
// Check if we need to handle water depth shading
|
||||
if (blockState.getMaterial().isLiquid()) {
|
||||
heightCoef = 1.0f;
|
||||
int i = 1;
|
||||
// Iterate over the 4 layers of water shading and color proportional to the depth
|
||||
for (; i < 5; i++) {
|
||||
if (BlockStateInterface.get(blockPos.down(i * 2)).getMaterial().isLiquid()) {
|
||||
heightCoef -= 0.075f;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Add checkerboard shading to the odd layers to give texture
|
||||
if (i % 2 == 0)
|
||||
heightCoef += 0.075f * (((x + z) % 2 == 0) ? -1 : 1);
|
||||
} else {
|
||||
// We start the heightCoef at 0.8 to darken the colors similar to vanilla Minecraft's.
|
||||
heightCoef = 0.8f + (Math.signum(blockPos.getY() - offset.getY()) * 0.2f);
|
||||
}
|
||||
red = Math.min(255, (int) (red * heightCoef));
|
||||
green = Math.min(255, (int) (green * heightCoef));
|
||||
blue = Math.min(255, (int) (blue * heightCoef));
|
||||
|
||||
return new Color(red, green, blue).getRGB();
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ import baritone.chunk.ChunkPacker;
|
||||
import baritone.chunk.Waypoint;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.event.events.ChatEvent;
|
||||
import baritone.map.Map;
|
||||
import baritone.pathing.calc.AStarPathFinder;
|
||||
import baritone.pathing.goals.*;
|
||||
import baritone.pathing.movement.ActionCosts;
|
||||
@ -328,6 +329,9 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (msg.toLowerCase().equals("map")) {
|
||||
Map.INSTANCE.writeImage();
|
||||
}
|
||||
if (Baritone.settings().byLowerName.containsKey(msg.toLowerCase())) {
|
||||
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg.toLowerCase());
|
||||
displayChatMessageRaw(setting.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user