0

Fixes glass pane/iron bar connection/adjacent rendering

This commit is contained in:
Bernd Buschinski
2021-05-13 20:00:09 +02:00
parent 86963c5de9
commit 9a34b4578f
5 changed files with 250 additions and 17 deletions

View File

@@ -271,3 +271,157 @@ const mc_block_t block_class_nether_roof[] = {
block_soul_soil,
block_nether_gold_ore};
const size_t block_class_nether_roof_len = COUNT_OF(block_class_nether_roof);
const mc_block_t block_connects_to_glass_pane[] = {
block_stone,
block_grass,
block_dirt,
block_cobblestone,
block_planks,
block_bedrock,
block_sand,
block_gravel,
block_gold_ore,
block_iron_ore,
block_coal_ore,
block_log,
block_sponge,
block_glass,
block_lapis_ore,
block_lapis_block,
block_dispenser,
block_sandstone,
block_noteblock,
block_sticky_piston,
block_piston,
block_wool,
block_gold_block,
block_iron_block,
block_double_stone_slab,
block_brick_block,
block_tnt,
block_bookshelf,
block_mossy_cobblestone,
block_obsidian,
block_mob_spawner,
block_diamond_ore,
block_diamond_block,
block_crafting_table,
block_furnace,
block_lit_furnace,
block_redstone_ore,
block_lit_redstone_ore,
block_ice,
block_snow,
block_clay,
block_jukebox,
block_netherrack,
block_soul_sand,
block_glowstone,
block_stained_glass,
block_stonebrick,
block_brown_mushroom_block,
block_red_mushroom_block,
block_iron_bars,
block_glass_pane,
block_mycelium,
block_nether_brick,
block_cauldron,
block_end_stone,
block_redstone_lamp,
block_lit_redstone_lamp,
block_double_wooden_slab,
block_emerald_ore,
block_emerald_block,
block_beacon,
block_mushroom_stem,
block_redstone_block,
block_quartz_ore,
block_hopper,
block_quartz_block,
block_dropper,
block_stained_hardened_clay,
block_stained_glass_pane,
block_prismarine,
block_sea_lantern,
block_hay_block,
block_hardened_clay,
block_coal_block,
block_packed_ice,
block_red_sandstone,
block_double_stone_slab2,
block_chorus_flower,
block_purpur_block,
block_purpur_pillar,
block_purpur_double_slab,
block_end_bricks,
block_frosted_ice,
block_magma,
block_nether_wart_block,
block_red_nether_brick,
block_bone_block,
block_observer,
block_white_glazed_terracotta,
block_orange_glazed_terracotta,
block_magenta_glazed_terracotta,
block_light_blue_glazed_terracotta,
block_yellow_glazed_terracotta,
block_lime_glazed_terracotta,
block_pink_glazed_terracotta,
block_gray_glazed_terracotta,
block_light_gray_glazed_terracotta,
block_cyan_glazed_terracotta,
block_purple_glazed_terracotta,
block_blue_glazed_terracotta,
block_brown_glazed_terracotta,
block_green_glazed_terracotta,
block_red_glazed_terracotta,
block_black_glazed_terracotta,
block_concrete,
block_concrete_powder,
block_ancient_debris,
block_basalt,
block_polished_basalt,
block_blackstone,
block_netherite_block,
block_warped_wart_block,
block_shroomlight,
block_soul_soil,
block_nether_gold_ore,
block_andesite_wall,
block_brick_wall,
block_cobblestone_wall,
block_diorite_wall,
block_end_stone_brick_wall,
block_granite_wall,
block_mossy_cobblestone_wall,
block_mossy_stone_brick_wall,
block_nether_brick_wall,
block_prismarine_wall,
block_red_nether_brick_wall,
block_red_sandstone_wall,
block_sandstone_wall,
block_stone_brick_wall,
block_fletching_table,
block_cartography_table,
block_smithing_table,
block_blast_furnace,
block_smoker,
block_loom,
block_composter,
block_beehive,
block_bee_nest,
block_honeycomb_block
};
const size_t block_connects_to_glass_pane_len = COUNT_OF(block_connects_to_glass_pane);
const mc_block_t block_class_trapdoor[] = {
block_trapdoor,
block_iron_trapdoor,
block_spruce_trapdoor,
block_birch_trapdoor,
block_jungle_trapdoor,
block_acacia_trapdoor,
block_dark_oak_trapdoor
};
const size_t block_class_trapdoor_len = COUNT_OF(block_class_trapdoor);

View File

@@ -51,4 +51,10 @@ extern const size_t block_class_alt_height_len;
extern const mc_block_t block_class_nether_roof[];
extern const size_t block_class_nether_roof_len;
extern const mc_block_t block_class_trapdoor[];
extern const size_t block_class_trapdoor_len;
extern const mc_block_t block_connects_to_glass_pane[];
extern const size_t block_connects_to_glass_pane_len;
#endif

View File

@@ -317,13 +317,73 @@ generate_pseudo_data(RenderState* state, uint16_t ancilData) {
return final_data;
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_iron_bars, block_glass_pane, block_stained_glass_pane}, 3)) {
/* iron bars and glass panes:
* they seem to stick to almost everything but air,
* not sure yet! Still a TODO! */
/* return check adjacent blocks with air, bit inverted */
uint8_t pdata = 0;
PyObject* texrot;
int32_t northdir;
struct {
int32_t x;
int32_t y;
int32_t z;
uint8_t direction; /*!< direction bit if glass pane should connect */
} blocks[] = { {x + 1, y, z, 1 << 3},
{x, y, z + 1, 1 << 2},
{x - 1, y, z, 1 << 1},
{x, y, z - 1, 1 << 0} };
texrot = PyObject_GetAttrString(state->textures, "rotation");
northdir = PyLong_AsLong(texrot) & 0x3;
for (size_t i = 0; i < sizeof(blocks)/sizeof(blocks[0]); ++i) {
mc_block_t block = get_data(state, BLOCKS, blocks[i].x, blocks[i].y, blocks[i].z);
if (block_class_is_subset(block, block_connects_to_glass_pane, block_connects_to_glass_pane_len)) {
pdata |= blocks[i].direction;
} else if (block_class_is_subset(block, block_class_stair, block_class_stair_len)) {
uint8_t stair_direction[4][4] = {
{ 1, 3, 0, 2 }, // 'northdirection': 'upper-left'
{ 2, 1, 3, 0 }, // 'northdirection': 'upper-right'
{ 0, 2, 1, 3 }, // 'northdirection': 'lower-right'
{ 3, 0, 2, 1 } // 'northdirection': 'lower-left'
};
mc_block_t block_data = get_data(state, DATA, blocks[i].x, blocks[i].y, blocks[i].z);
if ((block_data & 0xf) == stair_direction[northdir][i]) {
pdata |= blocks[i].direction;
}
} else if (block_class_is_subset(block, block_class_trapdoor, block_class_trapdoor_len)) {
uint8_t trapdoor_direction[4][4] = {
{ 3, 1, 2, 0 }, // 'northdirection': 'upper-left'
{ 0, 3, 1, 2 }, // 'northdirection': 'upper-right'
{ 2, 0, 3, 1 }, // 'northdirection': 'lower-right'
{ 1, 2, 0, 3 } // 'northdirection': 'lower-left'
};
mc_block_t block_data = get_data(state, DATA, blocks[i].x, blocks[i].y, blocks[i].z);
// only connects to "open" trapdoors
if ((block_data & 0x4) == 0x4 && (block_data & 0x3) == trapdoor_direction[northdir][i]) {
pdata |= blocks[i].direction;
}
} else if (block == block_snow_layer) {
// glass pane only connect to full high snow layers
mc_block_t skylight_data = get_data(state, SKYLIGHT, blocks[i].x, blocks[i].y, blocks[i].z);
if (skylight_data == 0) {
pdata |= blocks[i].direction;
}
}
}
// shift up 4 bits because the lower 4 bits encode color
data = (check_adjacent_blocks(state, x, y, z, 0) ^ 0x0f);
return (data << 4) | (ancilData & 0xf);
return (pdata << 4) | (ancilData & 0xf);
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_portal, block_nether_brick_fence}, 2)) {
/* portal and nether brick fences */

View File

@@ -377,7 +377,13 @@ enum mc_block_id {
block_honey_block = 11504,
block_sweet_berry_bush = 11505,
block_campfire = 11506,
block_bell = 11507
block_bell = 11507,
block_spruce_trapdoor = 11332,
block_birch_trapdoor = 11333,
block_jungle_trapdoor = 11334,
block_acacia_trapdoor = 11335,
block_dark_oak_trapdoor = 11336
};
typedef uint16_t mc_block_t;

View File

@@ -4157,11 +4157,15 @@ def panes(self, blockid, data):
t = self.load_image_texture("assets/minecraft/textures/block/glass.png")
left = t.copy()
right = t.copy()
center = t.copy()
# generate the four small pieces of the glass pane
ImageDraw.Draw(right).rectangle((0,0,7,15),outline=(0,0,0,0),fill=(0,0,0,0))
ImageDraw.Draw(left).rectangle((8,0,15,15),outline=(0,0,0,0),fill=(0,0,0,0))
ImageDraw.Draw(center).rectangle((0,0,6,15),outline=(0,0,0,0),fill=(0,0,0,0))
ImageDraw.Draw(center).rectangle((9,0,15,15),outline=(0,0,0,0),fill=(0,0,0,0))
up_center = self.transform_image_side(center)
up_left = self.transform_image_side(left)
up_right = self.transform_image_side(right).transpose(Image.FLIP_TOP_BOTTOM)
dw_right = self.transform_image_side(right)
@@ -4178,13 +4182,16 @@ def panes(self, blockid, data):
# the lower 4 bits encode color, the upper 4 encode adjencies
data = data >> 4
if (data & 0b0001) == 1 or data == 0:
if data == 0:
alpha_over(img,up_center,(6,3),up_center) # center
else:
if (data & 0b0001) == 1:
alpha_over(img,up_left, (6,3),up_left) # top left
if (data & 0b1000) == 8 or data == 0:
if (data & 0b1000) == 8:
alpha_over(img,up_right, (6,3),up_right) # top right
if (data & 0b0010) == 2 or data == 0:
if (data & 0b0010) == 2:
alpha_over(img,dw_left, (6,3),dw_left) # bottom left
if (data & 0b0100) == 4 or data == 0:
if (data & 0b0100) == 4:
alpha_over(img,dw_right, (6,3),dw_right) # bottom right
return img