Compare commits

...

26 Commits

Author SHA1 Message Date
Howard Stark d6c766fb66
Merge branch 'master' into mapping 2018-08-26 23:32:12 -07:00
Leijurv b2e69efbf2
integrate map directory 2018-08-22 15:43:44 -07:00
Leijurv 9746ed26be
Merge branch 'master' into mapping 2018-08-22 15:40:44 -07:00
Leijurv c9c807a319
accidental duplicate 2018-08-22 15:01:29 -07:00
Leijurv 1b83c243ec
merge 2018-08-22 15:00:10 -07:00
Leijurv 61b61ea07b
merge 2018-08-22 14:55:44 -07:00
Leijurv d16d5ba0e2
Merge pull request #76 from cabaletta/package-refactor
package refactor
2018-08-22 14:10:11 -07:00
Leijurv 9914620f10
another duplicate from an earlier refactor 2018-08-22 13:22:52 -07:00
Leijurv c5eda17154
intellij glitch 2018-08-22 13:17:20 -07:00
Leijurv 83a91be53c
package refactor 2018-08-22 13:15:56 -07:00
Howard Stark 3b5e2f9d87
Refactor map package 2018-08-22 13:12:20 -07:00
Leijurv 7aa071e074
refactored 2018-08-22 12:35:57 -07:00
Leijurv 91ce628ec2
removed print 2018-08-22 12:06:26 -07:00
Leijurv e6eac166d9
use top block in pathing, and reliability improvements 2018-08-22 12:05:02 -07:00
Leijurv 389748356a
rework chunk caching 2018-08-22 11:41:31 -07:00
Howard Stark dc6a9af9c5
Add beginning of surface block caching 2018-08-22 10:03:02 -07:00
Howard Stark 01bb5f1712
Merge branch 'master' into mapping 2018-08-21 21:21:40 -07:00
Howard Stark 0132dd4a20
Add water shading 2018-08-21 21:11:34 -07:00
Howard Stark 9bbb89f616
Merge branch 'master' into mapping 2018-08-21 18:05:33 -07:00
Howard Stark c89324be5b
Fix chunk stitch ordering, fix north border lines 2018-08-21 12:45:41 -07:00
Howard Stark 3abacb3b65
Add simple large map stitching 2018-08-21 11:52:12 -07:00
Howard Stark 64cf201953
Remove bitwise ops in favor of java.awt.Color 2018-08-21 10:45:51 -07:00
Howard Stark aa6f025ff0
Change visibility of getImage, Switch BlockPos impl 2018-08-21 10:44:42 -07:00
Howard Stark c301ea5878
Merge branch 'master' into mapping 2018-08-21 10:22:02 -07:00
Howard Stark 135149603f
Near-perfect match Minecraft map shading 2018-08-21 10:21:43 -07:00
Howard Stark dcd379f44c
Basic single-chunk map generation 2018-08-20 17:25:01 -07:00
5 changed files with 214 additions and 0 deletions

View File

@ -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 {

View File

@ -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() {

View 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");
}
}

View 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();
}
}

View File

@ -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());