Skip to content

Commit ea35d57

Browse files
author
Lieuwe Westra
committed
passed list of loaded models to worldpy
1 parent 5a172e3 commit ea35d57

File tree

3 files changed

+114
-37
lines changed

3 files changed

+114
-37
lines changed

overviewer_core/src/iterate.c

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ uint32_t max_data = 0;
2626
uint8_t* block_properties = NULL;
2727

2828
static PyObject* known_blocks = NULL;
29+
static PyObject* model_blocks = NULL;
2930
static PyObject* transparent_blocks = NULL;
3031
static PyObject* solid_blocks = NULL;
3132
static PyObject* fluid_blocks = NULL;
@@ -63,6 +64,9 @@ PyObject* init_chunk_render(void) {
6364
known_blocks = PyObject_GetAttrString(textures, "known_blocks");
6465
if (!known_blocks)
6566
return NULL;
67+
model_blocks = PyObject_GetAttrString(textures, "block_models");
68+
if (!model_blocks)
69+
return NULL;
6670
transparent_blocks = PyObject_GetAttrString(textures, "transparent_blocks");
6771
if (!transparent_blocks)
6872
return NULL;
@@ -137,6 +141,9 @@ bool load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required) {
137141
x += state->chunkx;
138142
z += state->chunkz;
139143

144+
145+
PyObject_CallMethod(state->regionset, "add_to_blockmap","O", model_blocks);
146+
140147
chunk = PyObject_CallMethod(state->regionset, "get_chunk", "ii", x, z);
141148
if (chunk == NULL) {
142149
// An exception is already set. RegionSet.get_chunk sets

overviewer_core/textures.py

+88-35
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
# global variables to collate information in @material decorators
3737
blockmap_generators = {}
38+
block_models = {}
3839

3940
known_blocks = set()
4041
used_datas = set()
@@ -133,11 +134,20 @@ def generate(self):
133134
# generate biome grass mask
134135
self.biome_grass_texture = self.build_block(self.load_image_texture("assets/minecraft/textures/block/grass_block_top.png"), self.load_image_texture("assets/minecraft/textures/block/grass_block_side_overlay.png"))
135136

137+
global max_blockid, block_models
138+
139+
models = self.find_models()
140+
max_blockid = max_blockid+1
141+
for model in models:
142+
solidmodelblock(blockid=max_blockid, name=model)
143+
block_models['minecraft:'+model] = (max_blockid, 0)
144+
145+
# print(str(block_models))
146+
136147
# generate the blocks
137148
global blockmap_generators
138-
global known_blocks, used_datas
139149
self.blockmap = [None] * max_blockid * max_data
140-
150+
141151
for (blockid, data), texgen in list(blockmap_generators.items()):
142152
tex = texgen(self, blockid, data)
143153
self.blockmap[blockid * max_data + data] = self.generate_texture_tuple(tex)
@@ -147,15 +157,55 @@ def generate(self):
147157
self.biome_grass_texture = self.biome_grass_texture.resize(self.texture_dimensions, Image.ANTIALIAS)
148158

149159
# rescale the rest
150-
for i, tex in enumerate(blockmap):
160+
for i, tex in enumerate(self.blockmap):
151161
if tex is None:
152162
continue
153163
block = tex[0]
154164
scaled_block = block.resize(self.texture_dimensions, Image.ANTIALIAS)
155-
blockmap[i] = self.generate_texture_tuple(scaled_block)
165+
self.blockmap[i] = self.generate_texture_tuple(scaled_block)
156166

157167
self.generated = True
158168

169+
#TODO: load models from resource packs, for now only client jars are used
170+
#TODO: load blockstate before models
171+
def find_models(self, verbose=False):
172+
filename = 'assets/minecraft/models/'
173+
versiondir = self.versiondir(verbose)
174+
available_versions = self.available_versions(versiondir, verbose)
175+
176+
if not available_versions:
177+
if verbose: logging.info("Did not find any non-snapshot minecraft jars >=1.8.0")
178+
while(available_versions):
179+
most_recent_version = available_versions.pop(0)
180+
if verbose: logging.info("Trying {0}. Searching it for the file...".format(".".join(str(x) for x in most_recent_version)))
181+
182+
jarname = ".".join(str(x) for x in most_recent_version)
183+
jarpath = os.path.join(versiondir, jarname, jarname + ".jar")
184+
185+
jar = {}
186+
187+
if jarpath in self.jars:
188+
jar = self.jars[jarpath]
189+
elif os.path.isfile(jarpath):
190+
try:
191+
jar = zipfile.ZipFile(jarpath)
192+
except (KeyError, IOError) as e:
193+
pass
194+
except (zipfile.BadZipFile) as e:
195+
logging.warning("Your jar {0} is corrupted, I'll be skipping it, but you "
196+
"should probably look into that.".format(jarpath))
197+
else:
198+
if verbose: logging.info("Did not find file {0} in jar {1}".format(filename, jarpath))
199+
continue
200+
201+
models = []
202+
for file in jar.namelist():
203+
if file.startswith('assets/minecraft/models/block'):
204+
model = Path(file).stem
205+
models.append(model)
206+
207+
return models
208+
159209
##
160210
## Helpers for opening textures
161211
##
@@ -264,6 +314,37 @@ def find_file(self, filename, mode="rb", verbose=False):
264314

265315
# Find an installed minecraft client jar and look in it for the texture
266316
# file we need.
317+
versiondir = self.versiondir(verbose)
318+
available_versions = self.available_versions(versiondir, verbose)
319+
320+
if not available_versions:
321+
if verbose: logging.info("Did not find any non-snapshot minecraft jars >=1.8.0")
322+
while(available_versions):
323+
most_recent_version = available_versions.pop(0)
324+
if verbose: logging.info("Trying {0}. Searching it for the file...".format(".".join(str(x) for x in most_recent_version)))
325+
326+
jarname = ".".join(str(x) for x in most_recent_version)
327+
jarpath = os.path.join(versiondir, jarname, jarname + ".jar")
328+
329+
if os.path.isfile(jarpath):
330+
try:
331+
jar = zipfile.ZipFile(jarpath)
332+
jar.getinfo(filename)
333+
if verbose: logging.info("Found %s in '%s'", filename, jarpath)
334+
self.jars[jarpath] = jar
335+
return jar.open(filename)
336+
except (KeyError, IOError) as e:
337+
pass
338+
except (zipfile.BadZipFile) as e:
339+
logging.warning("Your jar {0} is corrupted, I'll be skipping it, but you "
340+
"should probably look into that.".format(jarpath))
341+
342+
if verbose: logging.info("Did not find file {0} in jar {1}".format(filename, jarpath))
343+
344+
345+
raise TextureException("Could not find the textures while searching for '{0}'. Try specifying the 'texturepath' option in your config file.\nSet it to the path to a Minecraft Resource pack.\nAlternately, install the Minecraft client (which includes textures)\nAlso see <http://docs.overviewer.org/en/latest/running/#installing-the-textures>\n(Remember, this version of Overviewer requires a 1.19-compatible resource pack)\n(Also note that I won't automatically use snapshots; you'll have to use the texturepath option to use a snapshot jar)".format(filename))
346+
347+
def versiondir(self, verbose):
267348
versiondir = ""
268349
if "APPDATA" in os.environ and sys.platform.startswith("win"):
269350
versiondir = os.path.join(os.environ['APPDATA'], ".minecraft", "versions")
@@ -274,7 +355,9 @@ def find_file(self, filename, mode="rb", verbose=False):
274355
# For Mac:
275356
versiondir = os.path.join(os.environ['HOME'], "Library",
276357
"Application Support", "minecraft", "versions")
358+
return versiondir
277359

360+
def available_versions(self, versiondir, verbose):
278361
try:
279362
if verbose: logging.info("Looking in the following directory: \"%s\"" % versiondir)
280363
versions = os.listdir(versiondir)
@@ -306,32 +389,8 @@ def find_file(self, filename, mode="rb", verbose=False):
306389
available_versions.append(versionparts)
307390

308391
available_versions.sort(reverse=True)
309-
if not available_versions:
310-
if verbose: logging.info("Did not find any non-snapshot minecraft jars >=1.8.0")
311-
while(available_versions):
312-
most_recent_version = available_versions.pop(0)
313-
if verbose: logging.info("Trying {0}. Searching it for the file...".format(".".join(str(x) for x in most_recent_version)))
314392

315-
jarname = ".".join(str(x) for x in most_recent_version)
316-
jarpath = os.path.join(versiondir, jarname, jarname + ".jar")
317-
318-
if os.path.isfile(jarpath):
319-
try:
320-
jar = zipfile.ZipFile(jarpath)
321-
jar.getinfo(filename)
322-
if verbose: logging.info("Found %s in '%s'", filename, jarpath)
323-
self.jars[jarpath] = jar
324-
return jar.open(filename)
325-
except (KeyError, IOError) as e:
326-
pass
327-
except (zipfile.BadZipFile) as e:
328-
logging.warning("Your jar {0} is corrupted, I'll be skipping it, but you "
329-
"should probably look into that.".format(jarpath))
330-
331-
if verbose: logging.info("Did not find file {0} in jar {1}".format(filename, jarpath))
332-
333-
334-
raise TextureException("Could not find the textures while searching for '{0}'. Try specifying the 'texturepath' option in your config file.\nSet it to the path to a Minecraft Resource pack.\nAlternately, install the Minecraft client (which includes textures)\nAlso see <http://docs.overviewer.org/en/latest/running/#installing-the-textures>\n(Remember, this version of Overviewer requires a 1.19-compatible resource pack)\n(Also note that I won't automatically use snapshots; you'll have to use the texturepath option to use a snapshot jar)".format(filename))
393+
return available_versions
335394

336395
def load_image_texture(self, filename):
337396
# Textures may be animated or in a different resolution than 16x16.
@@ -376,8 +435,6 @@ def load_image(self, filename):
376435
self.texture_cache[filename] = img
377436
return img
378437

379-
380-
381438
def load_water(self):
382439
"""Special-case function for loading water."""
383440
watertexture = getattr(self, "watertexture", None)
@@ -525,7 +582,6 @@ def transform_image_slope(img):
525582

526583
return newimg
527584

528-
529585
@staticmethod
530586
def transform_image_angle(img, angle):
531587
"""Takes an image an shears it in arbitrary angle with the axis of
@@ -566,7 +622,6 @@ def transform_image_angle(img, angle):
566622

567623
return newimg
568624

569-
570625
def build_block(self, top, side):
571626
"""From a top texture and a side texture, build a block image.
572627
top and side should be 16x16 image objects. Returns a 24x24 image
@@ -899,7 +954,6 @@ def build_block_from_model(self, modelname, blockstate={}):
899954
# element has an invalid texture; skipping entire element
900955
continue
901956
# draw each face
902-
903957
# Manually touch up 6 pixels that leave a gap because of how the
904958
# shearing works out. This makes the blocks perfectly tessellate-able
905959
for x,y in [(13,23), (17,21), (21,19)]:
@@ -5577,7 +5631,6 @@ def structure_block(self, blockid, data):
55775631
raise Exception('unexpected structure block: ' + str(data))
55785632

55795633
# Jigsaw block
5580-
# doesnt actually render
55815634
@material(blockid=256, data=list(range(6)), solid=True)
55825635
def jigsaw_block(self, blockid, data):
55835636
facing = {0: 'down', 1: 'up', 2: 'north', 3: 'south', 4: 'west', 5: 'east'}[data%6]

overviewer_core/world.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class UnsupportedVersion(Exception):
4040
class UnknownBlockException(Exception):
4141
pass
4242

43+
modelblocks = {}
44+
4345
def log_other_exceptions(func):
4446
"""A decorator that prints out any errors that are not
4547
ChunkDoesntExist errors. This should decorate any functions or
@@ -1126,10 +1128,19 @@ def _get_block(self, palette_entry):
11261128
colors = ['white', 'orange', 'magenta', 'light_blue', 'yellow', 'lime', 'pink', 'gray', 'light_gray', 'cyan',
11271129
'purple', 'blue', 'brown', 'green', 'red', 'black']
11281130

1131+
global modelblocks
1132+
11291133
key = palette_entry['Name']
1130-
if key not in self._blockmap:
1134+
if key in self._blockmap:
1135+
(block, data) = self._blockmap[key]
1136+
elif key in modelblocks:
1137+
(block, data) = modelblocks[key]
1138+
print('found ' + str(block) + ' : ' + str(key))
1139+
else:
1140+
print(str(type(modelblocks)))
1141+
print('unknown key ' + key )
11311142
raise UnknownBlockException(key)
1132-
(block, data) = self._blockmap[key]
1143+
11331144
if key in ['minecraft:redstone_ore', 'minecraft:redstone_lamp']:
11341145
if palette_entry['Properties']['lit'] == 'true':
11351146
block += 1
@@ -1602,6 +1613,10 @@ def _get_blockdata_v112(self, section):
16021613

16031614
return (blocks, data_expanded)
16041615

1616+
def add_to_blockmap(self, blockmap):
1617+
global modelblocks
1618+
modelblocks = blockmap
1619+
16051620
#@log_other_exceptions
16061621
def get_chunk(self, x, z):
16071622
"""Returns a dictionary object representing the "Level" NBT Compound
@@ -1902,6 +1917,8 @@ def iterate_newer_chunks(self,filemtime):
19021917
return self._r.iterate_newer_chunks(filemtime)
19031918
def get_chunk_mtime(self, x, z):
19041919
return self._r.get_chunk_mtime(x,z)
1920+
def add_to_blockmap(self, blockmap):
1921+
return self._r.add_to_blockmap(blockmap)
19051922

19061923
# see RegionSet.rotate. These values are chosen so that they can be
19071924
# passed directly to rot90; this means that they're the number of

0 commit comments

Comments
 (0)