Skip to content

Commit 5a172e3

Browse files
author
Lieuwe Westra
committed
referenced more blocks by enum
1 parent 2ee681c commit 5a172e3

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

overviewer_core/src/iterate.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ generate_pseudo_data(RenderState* state, uint16_t ancilData) {
263263
* Note that stained glass encodes 16 colors using 4 bits. this pushes us over the 8-bits of an uint8_t,
264264
* forcing us to use an uint16_t to hold 16 bits of pseudo ancil data
265265
* */
266-
if ((get_data(state, BLOCKS, x, y + 1, z) == 20) || (get_data(state, BLOCKS, x, y + 1, z) == 95)) {
266+
if ((get_data(state, BLOCKS, x, y + 1, z) == block_glass) || (get_data(state, BLOCKS, x, y + 1, z) == block_stained_glass)) {
267267
data = 0;
268268
} else {
269269
data = 16;
@@ -278,15 +278,15 @@ generate_pseudo_data(RenderState* state, uint16_t ancilData) {
278278
uint8_t above_level_data = 0, same_level_data = 0, below_level_data = 0, possibly_connected = 0, final_data = 0;
279279

280280
/* check for air in y+1, no air = no connection with upper level */
281-
if (get_data(state, BLOCKS, x, y + 1, z) == 0) {
281+
if (get_data(state, BLOCKS, x, y + 1, z) == block_air) {
282282
above_level_data = check_adjacent_blocks(state, x, y + 1, z, state->block);
283283
} /* else above_level_data = 0 */
284284

285285
/* check connection with same level (other redstone and trapped chests */
286-
same_level_data = check_adjacent_blocks(state, x, y, z, 55) | check_adjacent_blocks(state, x, y, z, 146);
286+
same_level_data = check_adjacent_blocks(state, x, y, z, block_redstone_wire) | check_adjacent_blocks(state, x, y, z, block_trapped_chest);
287287

288288
/* check the posibility of connection with y-1 level, check for air */
289-
possibly_connected = check_adjacent_blocks(state, x, y, z, 0);
289+
possibly_connected = check_adjacent_blocks(state, x, y, z, block_air );
290290

291291
/* check connection with y-1 level */
292292
below_level_data = check_adjacent_blocks(state, x, y - 1, z, state->block);
@@ -622,7 +622,7 @@ chunk_render(PyObject* self, PyObject* args) {
622622
/* if we found a proper texture, render it! */
623623
if (t != NULL && t != Py_None) {
624624
PyObject *src, *mask, *mask_light;
625-
int32_t do_rand = (state.block == block_tallgrass /*|| state.block == block_red_flower || state.block == block_double_plant*/);
625+
int32_t do_rand = (state.block == block_tallgrass);
626626
int32_t randx = 0, randy = 0;
627627
src = PyTuple_GetItem(t, 0);
628628
mask = PyTuple_GetItem(t, 0);

overviewer_core/src/primitives/base.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObjec
103103
* biome-compliant ones! The tinting is now all done here.
104104
*/
105105
if (/* grass, but not snowgrass */
106-
(state->block == block_grass && get_data(state, BLOCKS, state->x, state->y + 1, state->z) != 78) ||
106+
(state->block == block_grass && get_data(state, BLOCKS, state->x, state->y + 1, state->z) != block_snow_layer) ||
107107
block_class_is_subset(state->block, (mc_block_t[]){block_vine, block_waterlily, block_flowing_water, block_water, block_leaves, block_leaves2},
108108
6) ||
109109
/* tallgrass, but not dead shrubs */

overviewer_core/src/primitives/cave.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ cave_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
8383

8484
blockID = getArrayShort3D(state->blocks, x, y, z);
8585
blockUpID = get_data(state, BLOCKS, x, y + 1, z);
86-
if (blockID == 9 || blockID == 8 || blockUpID == 9 || blockUpID == 8) {
86+
if (blockID == block_water || blockID == block_flowing_water || blockUpID == block_water || blockUpID == block_flowing_water) {
8787
for (dy = y + 1; dy < (SECTIONS_PER_CHUNK - state->chunky) * 16; dy++) {
8888
/* go up and check for skylight */
8989
if (get_data(state, SKYLIGHT, x, dy, z) != 0) {
9090
return true;
9191
}
9292
blockUpID = get_data(state, BLOCKS, x, dy, z);
93-
if (blockUpID != 8 && blockUpID != 9) {
93+
if (blockUpID != block_flowing_water && blockUpID != block_water) {
9494
/* we are out of the water! and there's no skylight
9595
* , i.e. is a cave lake or something similar */
9696
break;

overviewer_core/textures.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
1515

1616
from collections import OrderedDict
17-
from locale import normalize
18-
import copy
17+
from copy import deepcopy
18+
from pathlib import Path
1919
import re
2020
import sys
2121
import imp
@@ -841,19 +841,19 @@ def normalize_model(self, modelname):
841841
match modelname:
842842
# observer top texture is inconsistent in rotation
843843
case 'block/loom':
844-
self.models[modelname] = copy.deepcopy(self.models[modelname])
844+
self.models[modelname] = deepcopy(self.models[modelname])
845845
self.models[modelname]['elements'][0]['faces']['up']['texturerotation'] = 180
846846
self.models[modelname]['elements'][0]['faces']['down']['texturerotation'] = 180
847847
case 'block/barrel' | 'block/barrel_open':
848-
self.models[modelname] = copy.deepcopy(self.models[modelname])
848+
self.models[modelname] = deepcopy(self.models[modelname])
849849
self.models[modelname]['elements'][0]['faces']['north']['texture'] = '#up'
850850
self.models[modelname]['elements'][0]['faces']['south']['texture'] = '#down'
851851
self.models[modelname]['elements'][0]['faces']['down']['texture'] = '#north'
852852
self.models[modelname]['elements'][0]['faces']['up']['texture'] = '#south'
853853
self.models[modelname]['elements'][0]['faces']['east']['texturerotation'] = 90
854854
self.models[modelname]['elements'][0]['faces']['west']['texturerotation'] = 90
855855
case 'block/dropper_vertical' | 'block/dispenser_vertical':
856-
self.models[modelname] = copy.deepcopy(self.models[modelname])
856+
self.models[modelname] = deepcopy(self.models[modelname])
857857
self.models[modelname]['elements'][0]['faces']['north']['texture'] = '#up'
858858
self.models[modelname]['elements'][0]['faces']['up']['texture'] = '#north'
859859

@@ -869,6 +869,9 @@ def build_block_from_model(self, modelname, blockstate={}):
869869

870870
img = Image.new("RGBA", (24,24), self.bgcolor)
871871

872+
if 'elements' not in colmodel:
873+
return None
874+
872875
# for each elements
873876
for elem in colmodel['elements']:
874877
try:
@@ -5382,11 +5385,11 @@ def hopper(self, blockid, data):
53825385
@material(blockid=168, data=list(range(3)), solid=True)
53835386
def prismarine_block(self, blockid, data):
53845387
if data == 0: # prismarine
5385-
t = self.build_block_from_model("prismarine")
5388+
return self.build_block_from_model("prismarine")
53865389
elif data == 1: # prismarine bricks
5387-
t = self.build_block_from_model("prismarine_bricks")
5390+
return self.build_block_from_model("prismarine_bricks")
53885391
elif data == 2: # dark prismarine
5389-
t = self.build_block_from_model("dark_prismarine")
5392+
return self.build_block_from_model("dark_prismarine")
53905393
else:
53915394
raise Exception('unexpected prismarine data: ' + str(data))
53925395

overviewer_core/world.py

+12-16
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
import os.path
1919
import logging
2020
import time
21-
import random
2221
import re
23-
import locale
2422

2523
import numpy
26-
import math
2724

2825
from . import nbt
2926
from . import cache
@@ -37,10 +34,11 @@
3734
class ChunkDoesntExist(Exception):
3835
pass
3936

40-
4137
class UnsupportedVersion(Exception):
4238
pass
4339

40+
class UnknownBlockException(Exception):
41+
pass
4442

4543
def log_other_exceptions(func):
4644
"""A decorator that prints out any errors that are not
@@ -1129,6 +1127,8 @@ def _get_block(self, palette_entry):
11291127
'purple', 'blue', 'brown', 'green', 'red', 'black']
11301128

11311129
key = palette_entry['Name']
1130+
if key not in self._blockmap:
1131+
raise UnknownBlockException(key)
11321132
(block, data) = self._blockmap[key]
11331133
if key in ['minecraft:redstone_ore', 'minecraft:redstone_lamp']:
11341134
if palette_entry['Properties']['lit'] == 'true':
@@ -1209,8 +1209,8 @@ def _get_block(self, palette_entry):
12091209
data = int(palette_entry['Properties']['age'])
12101210
elif key in ['minecraft:jigsaw']:
12111211
data = {'down_east': 0, 'down_east': 0, 'down_north': 0, 'down_south': 0, 'down_west': 0,
1212-
'up_east': 1, 'up_north': 1, 'up_south': 1, 'up_west': 1, 'north_up': 2, 'south_up': 3,
1213-
'west_up': 4, 'east_up': 5}[palette_entry['Properties']['facing']]
1212+
'up_east': 1, 'up_north': 1, 'up_south': 1, 'up_west': 1, 'north_up': 2, 'south_up': 3,
1213+
'west_up': 4, 'east_up': 5}[palette_entry['Properties']['orientation']]
12141214
elif (key.endswith('shulker_box') or key.endswith('piston') or
12151215
key in ['minecraft:observer', 'minecraft:dropper', 'minecraft:dispenser',
12161216
'minecraft:piston_head', 'minecraft:end_rod']):
@@ -1514,7 +1514,7 @@ def _packed_longarray_to_shorts_v116(self, long_array, n, num_palette):
15141514

15151515
return result
15161516

1517-
def _get_blockdata_v118(self, section, unrecognized_block_types, longarray_unpacker):
1517+
def _get_blockdata_v118(self, section, longarray_unpacker):
15181518
block_states = section['block_states']
15191519
palette = block_states.get('palette')
15201520
block_states_data = block_states.get('data')
@@ -1531,7 +1531,7 @@ def _get_blockdata_v118(self, section, unrecognized_block_types, longarray_unpac
15311531
key = palette[i]
15321532
try:
15331533
translated_blocks[i], translated_data[i] = self._get_block(key)
1534-
except KeyError:
1534+
except UnknownBlockException as e:
15351535
pass # We already have initialised arrays with 0 (= air)
15361536

15371537
# Turn the BlockStates array into a 16x16x16 numpy matrix of shorts.
@@ -1547,7 +1547,7 @@ def _get_blockdata_v118(self, section, unrecognized_block_types, longarray_unpac
15471547

15481548
return (blocks, data)
15491549

1550-
def _get_blockdata_v113(self, section, unrecognized_block_types, longarray_unpacker):
1550+
def _get_blockdata_v113(self, section, longarray_unpacker):
15511551
# Translate each entry in the palette to a 1.2-era (block, data) int pair.
15521552
num_palette_entries = len(section['Palette'])
15531553
translated_blocks = numpy.zeros((num_palette_entries,), dtype=numpy.uint16) # block IDs
@@ -1556,7 +1556,7 @@ def _get_blockdata_v113(self, section, unrecognized_block_types, longarray_unpac
15561556
key = section['Palette'][i]
15571557
try:
15581558
translated_blocks[i], translated_data[i] = self._get_block(key)
1559-
except KeyError:
1559+
except UnknownBlockException as e:
15601560
pass # We already have initialised arrays with 0 (= air)
15611561

15621562
# Turn the BlockStates array into a 16x16x16 numpy matrix of shorts.
@@ -1719,7 +1719,6 @@ def get_chunk(self, x, z):
17191719
chunk_data['Biomes'] = biomes
17201720
chunk_data['NewBiomes'] = (len(biomes.shape) == 3)
17211721

1722-
unrecognized_block_types = {}
17231722
for section in chunk_data['Sections']:
17241723

17251724
# Turn the skylight array into a 16x16x16 matrix. The array comes
@@ -1755,9 +1754,9 @@ def get_chunk(self, x, z):
17551754
section['BlockLight'] = blocklight_expanded
17561755

17571756
if 'block_states' in section:
1758-
(blocks, data) = self._get_blockdata_v118(section, unrecognized_block_types, longarray_unpacker)
1757+
(blocks, data) = self._get_blockdata_v118(section, longarray_unpacker)
17591758
elif 'Palette' in section:
1760-
(blocks, data) = self._get_blockdata_v113(section, unrecognized_block_types, longarray_unpacker)
1759+
(blocks, data) = self._get_blockdata_v113(section, longarray_unpacker)
17611760
elif 'Data' in section:
17621761
(blocks, data) = self._get_blockdata_v112(section)
17631762
else: # Special case introduced with 1.14
@@ -1773,9 +1772,6 @@ def get_chunk(self, x, z):
17731772
logging.debug("Full traceback:", exc_info=1)
17741773
raise nbt.CorruptChunkError()
17751774

1776-
for k in unrecognized_block_types:
1777-
logging.debug("Found %d blocks of unknown type %s" % (unrecognized_block_types[k], k))
1778-
17791775
return chunk_data
17801776

17811777

0 commit comments

Comments
 (0)