From 210e65730fb6d265d35e8f892a41f413252ef1a2 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Wed, 10 Nov 2010 20:07:02 -0500 Subject: [PATCH] Hacky work on biome tinting Currently this requires python-gearman, gearman-java, and a java SDK. This code will probably be all thrown away, but if you really want to play, first compile Biome.java, then run the resulting Biome.class. Note you'll probably need to hack the signatures out of minecraft.jar to get it to run. Then copy grasscolor.png into the cwd, and run gmap.py as usual. It is slowwwww. Perhaps running Biome.class on multiple machines might speed things up? Here's the kind of output produced: http://smp.em32.net/biome_test/ --- Biome.java | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ chunk.py | 3 ++ template.html | 2 +- textures.py | 38 +++++++++++++++++++++++-- 4 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 Biome.java diff --git a/Biome.java b/Biome.java new file mode 100644 index 0000000..cd7c49e --- /dev/null +++ b/Biome.java @@ -0,0 +1,78 @@ +import java.io.File; +import java.lang.*; +import org.gearman.worker.*; +import org.gearman.util.*; +import org.gearman.common.*; +import org.gearman.client.*; + +public class Biome extends AbstractGearmanFunction { + + public static cu MCSave; + public static pb BioGen; + + public String getName() { + System.out.println("getname"); + return "GetBiome"; + } + + public GearmanJobResult executeFunction() { + //System.out.println("executing"); + String data = new String((byte[])this.data); + //System.out.println("got data -->" + data + "<--"); + String[] s = data.split(","); + + int x = Integer.parseInt(s[0]); + int y = Integer.parseInt(s[1]); + + BioGen.a(x,y,1,1); + double temp = BioGen.a[0]; + double moisture = BioGen.b[0]; + + String result = Double.toString(temp) + "/" + Double.toString(moisture); + //System.out.println(result); + GearmanJobResult gjr = new GearmanJobResultImpl(this.jobHandle,true, result.getBytes(), + new byte[0], new byte[0], 0, 0); + return gjr; + } + + + public static void main(String[] args) { + + System.out.println("Locating Minecraft save..."); + + MCSave = new cu(new File("/home/achin/devel/overviewer-fork"), "world.test"); + + /* if (MinecraftSave.q) + System.out.println("Loading level..."); + else + { + System.out.println("Failed to load level! Aborting."); + return; + }*/ + + + BioGen = new pb(MCSave); + + /* BiomeGenerator.a(0,1,1,1); + double temp = BiomeGenerator.a[0]; + double moisture = BiomeGenerator.b[0]; + + System.out.println("Got biome vals at (0,0)"); + System.out.println("Temperature: " + Double.toString(temp)); + System.out.println("Moisture: " + Double.toString(moisture)); + */ + + + org.gearman.worker.GearmanWorker w = new org.gearman.worker.GearmanWorkerImpl(); + + w.addServer(new GearmanNIOJobServerConnection("localhost")); + + w.registerFunction(Biome.class); + + System.out.println("working..."); + w.work(); + + } + + +} diff --git a/chunk.py b/chunk.py index 3285ab1..400d7ca 100644 --- a/chunk.py +++ b/chunk.py @@ -528,6 +528,9 @@ class ChunkRenderer(object): if not t: continue + if blockid in (2,18): # grass or leaves, tint according to biome + t = textures.tintForBiome(t, (16*self.chunkX) + x,y+(16*self.chunkY)) + # Check if this block is occluded if cave and ( x == 0 and y != 15 and z != 127 diff --git a/template.html b/template.html index 99b33ca..f346a33 100644 --- a/template.html +++ b/template.html @@ -16,7 +16,7 @@ defaultZoom: 1, maxZoom: {maxzoom}, cacheMinutes: 0, // Change this to have browsers automatically request new images every x minutes - debug: false + debug: true }; // our custom projection maps Latitude to Y, and Longitude to X as normal, diff --git a/textures.py b/textures.py index 64ae583..6f782b7 100644 --- a/textures.py +++ b/textures.py @@ -26,6 +26,13 @@ from PIL import Image, ImageEnhance, ImageOps import util import composite +sys.path.append("../python-gearman") + +from gearman.client import GearmanClient + +gmc = GearmanClient(["localhost"]) + + def _find_file(filename, mode="rb"): """Searches for the given file and returns an open handle to it. This searches the following locations in this order: @@ -531,9 +538,34 @@ def tintTexture(im, c): i.putalpha(im.split()[3]); # copy the alpha band back in. assuming RGBA return i +## prepare grasscolor.png +grasscolor = list(Image.open("grasscolor.png").getdata()) + + + +def tintForBiome(im, x, y): + result = gmc.submit_job("GetBiome", "%d,%d" % (x,y)) + temp, moisture = map(lambda x: float(x),result.result.split("/")) + + #print result.result + moisture *= temp + i = int((1.0 - temp) * 255) + j = int((1.0 - moisture) * 255) + #print "tintInfo for %d,%d is %f,%f coord %d, %d" % (x,y, temp, moisture, i, j) + #print "resulting color: %r" % (grasscolor.getpixel((i,j))[:-1],) + #t = tintTexture(im[0], grasscolor.getpixel((i, j))[:-1]) + #im[0] = t + #c = grasscolor.getpixel((j,i))[:-1] + c = grasscolor[(j << 8 | i)] + #print "grass color: %r" % (c,) + i = ImageOps.colorize(ImageOps.grayscale(im[0]), (0,0,0), c) + i.putalpha(im[1]) + return (i, im[1]) + + # This set holds block ids that require special pre-computing. These are typically # things that require ancillary data to render properly (i.e. ladder plus orientation) -special_blocks = set([66,59,61,62, 65,64,71,91,86,2,18]) +special_blocks = set([66,59,61,62, 65,64,71,91,86]) # this is a map of special blockIDs to a list of all # possible values for ancillary data that it might have. @@ -550,8 +582,8 @@ special_map[86] = range(5) # pumpkin # apparently pumpkins and jack-o-lanterns have ancillary data, but it's unknown # what that data represents. For now, assume that the range for data is 0 to 5 # like torches -special_map[2] = (0,) # grass -special_map[18] = range(16) # leaves +#special_map[2] = (0,) # grass +#special_map[18] = range(16) # leaves # grass and leaves are now graysacle in terrain.png # we treat them as special so we can manually tint them # it is unknown how the specific tint (biomes) is calculated