0

Add mushroom block & vine variants

- Add all possible variants of mushroom blocks introduced in 1.13
- Render mushroom stems similarly to red/brown mushroom blocks
- Add vine variants where vines are on the upwards facing side
This commit is contained in:
Joseph Camp
2020-02-13 23:51:57 +00:00
parent b6716a898a
commit 7e0c880a58
3 changed files with 73 additions and 129 deletions

View File

@@ -142,6 +142,7 @@ enum mc_block_id {
block_jungle_stairs = 136,
block_command_block = 137,
block_beacon = 138,
block_mushroom_stem = 139,
block_flower_pot = 140,
block_carrots = 141,
block_potatoes = 142,

View File

@@ -3876,87 +3876,44 @@ def stone_brick(self, blockid, data):
return img
# huge brown and red mushroom
@material(blockid=[99,100], data= list(range(11)) + [14,15], solid=True)
# huge brown/red mushrooms, and mushroom stems
@material(blockid=[99, 100, 139], data=list(range(64)), solid=True)
def huge_mushroom(self, blockid, data):
# rotation
if self.rotation == 1:
if data == 1: data = 3
elif data == 2: data = 6
elif data == 3: data = 9
elif data == 4: data = 2
elif data == 6: data = 8
elif data == 7: data = 1
elif data == 8: data = 4
elif data == 9: data = 7
elif self.rotation == 2:
if data == 1: data = 9
elif data == 2: data = 8
elif data == 3: data = 7
elif data == 4: data = 6
elif data == 6: data = 4
elif data == 7: data = 3
elif data == 8: data = 2
elif data == 9: data = 1
elif self.rotation == 3:
if data == 1: data = 7
elif data == 2: data = 4
elif data == 3: data = 1
elif data == 4: data = 2
elif data == 6: data = 8
elif data == 7: data = 9
elif data == 8: data = 6
elif data == 9: data = 3
# Re-arrange the bits in data based on self.rotation
# rotation bit: 654321
# 0 DUENWS
# 1 DUNWSE
# 2 DUWSEN
# 3 DUSENW
if self.rotation in [1, 2, 3]:
bit_map = {1: [6, 5, 3, 2, 1, 4],
2: [6, 5, 2, 1, 4, 3],
3: [6, 5, 1, 4, 3, 2]}
new_data = 0
# Add the ith bit to new_data then shift left one at a time,
# re-ordering data's bits in the order specified in bit_map
for i in bit_map[self.rotation]:
new_data = new_data << 1
new_data |= (data >> (i - 1)) & 1
data = new_data
# texture generation
if blockid == 99: # brown
cap = self.load_image_texture("assets/minecraft/textures/block/brown_mushroom_block.png")
else: # red
cap = self.load_image_texture("assets/minecraft/textures/block/red_mushroom_block.png")
stem = self.load_image_texture("assets/minecraft/textures/block/mushroom_stem.png")
texture_map = {99: "brown_mushroom_block",
100: "red_mushroom_block",
139: "mushroom_stem"}
cap = self.load_image_texture("assets/minecraft/textures/block/%s.png" % texture_map[blockid])
porous = self.load_image_texture("assets/minecraft/textures/block/mushroom_block_inside.png")
if data == 0: # fleshy piece
img = self.build_full_block(porous, None, None, porous, porous)
# Faces visible after amending data for rotation are: up, West, and South
side_up = cap if data & 0b010000 else porous # Up
side_west = cap if data & 0b000010 else porous # West
side_south = cap if data & 0b000001 else porous # South
side_south = side_south.transpose(Image.FLIP_LEFT_RIGHT)
if data == 1: # north-east corner
img = self.build_full_block(cap, None, None, cap, porous)
return self.build_full_block(side_up, None, None, side_west, side_south)
if data == 2: # east side
img = self.build_full_block(cap, None, None, porous, cap)
if data == 3: # south-east corner
img = self.build_full_block(cap, None, None, porous, cap)
if data == 4: # north side
img = self.build_full_block(cap, None, None, cap, porous)
if data == 5: # top piece
img = self.build_full_block(cap, None, None, porous, porous)
if data == 6: # south side
img = self.build_full_block(cap, None, None, cap, porous)
if data == 7: # north-west corner
img = self.build_full_block(cap, None, None, cap, cap)
if data == 8: # west side
img = self.build_full_block(cap, None, None, porous, cap)
if data == 9: # south-west corner
img = self.build_full_block(cap, None, None, porous, cap)
if data == 10: # stem
img = self.build_full_block(porous, None, None, stem, stem)
if data == 14: # all cap
img = self.build_block(cap,cap)
if data == 15: # all stem
img = self.build_block(stem,stem)
return img
# iron bars and glass pane
# TODO glass pane is not a sprite, it has a texture for the side,
@@ -4033,45 +3990,38 @@ def stem(self, blockid, data):
# vines
@material(blockid=106, data=list(range(16)), transparent=True)
@material(blockid=106, data=list(range(32)), transparent=True, solid=False, nospawn=True)
def vines(self, blockid, data):
# rotation
# vines data is bit coded. decode it first.
# NOTE: the directions used in this function are the new ones used
# in minecraft 1.0.0, no the ones used by overviewer
# (i.e. north is top-left by defalut)
# Re-arrange the bits in data based on self.rotation
# rotation bit: 54321
# 0 UENWS
# 1 UNWSE
# 2 UWSEN
# 3 USENW
if self.rotation in [1, 2, 3]:
bit_map = {1: [5, 3, 2, 1, 4],
2: [5, 2, 1, 4, 3],
3: [5, 1, 4, 3, 2]}
new_data = 0
# rotate the data by bitwise shift
shifts = 0
if self.rotation == 1:
shifts = 1
elif self.rotation == 2:
shifts = 2
elif self.rotation == 3:
shifts = 3
for i in range(shifts):
data = data * 2
if data & 16:
data = (data - 16) | 1
# Add the ith bit to new_data then shift left one at a time,
# re-ordering data's bits in the order specified in bit_map
for i in bit_map[self.rotation]:
new_data = new_data << 1
new_data |= (data >> (i - 1)) & 1
data = new_data
# decode data and prepare textures
raw_texture = self.load_image_texture("assets/minecraft/textures/block/vine.png")
s = w = n = e = None
if data & 1: # south
s = raw_texture
if data & 2: # west
w = raw_texture
if data & 4: # north
n = raw_texture
if data & 8: # east
e = raw_texture
side_up = raw_texture if data & 0b10000 else None # Up
side_east = raw_texture if data & 0b01000 else None # East
side_north = raw_texture if data & 0b00100 else None # North
side_west = raw_texture if data & 0b00010 else None # West
side_south = raw_texture if data & 0b00001 else None # South
# texture generation
img = self.build_full_block(None, n, e, w, s)
return self.build_full_block(side_up, side_north, side_east, side_west, side_south)
return img
# fence gates
@material(blockid=[107, 183, 184, 185, 186, 187], data=list(range(8)), transparent=True, nospawn=True)

View File

@@ -470,7 +470,6 @@ class RegionSet(object):
'minecraft:infested_chiseled_stone_bricks': (98, 3),
'minecraft:brown_mushroom_block': (99, 0),
'minecraft:red_mushroom_block': (100, 0),
'minecraft:mushroom_stem': (100,10),
'minecraft:iron_bars': (101, 0),
'minecraft:glass_pane': (102, 0),
'minecraft:melon': (103,0),
@@ -514,6 +513,7 @@ class RegionSet(object):
'minecraft:jungle_stairs': (136, 0),
'minecraft:command_block': (137, 0),
'minecraft:beacon': (138, 0),
'minecraft:mushroom_stem': (139, 0),
'minecraft:flower_pot': (140, 0),
'minecraft:potted_poppy': (140, 0), # Pots not rendering
'minecraft:potted_blue_orchid': (140, 0),
@@ -1064,32 +1064,25 @@ class RegionSet(object):
data = {'east': 1, 'west': 2, 'south': 3, 'north': 4}[facing]
else:
data = 5
elif key in ['minecraft:brown_mushroom_block','minecraft:red_mushroom_block']:
p = palette_entry['Properties']
if p['up'] == 'true': data = 5
else: data = 0
if p['north'] == 'true':
if p['south'] == 'true': data = 14
elif p['east'] == 'true': data = 3
elif p['west'] == 'true': data = 1
else: data = 2
elif p['east'] == 'true':
if p['west'] == 'true': data = 14
elif p['south'] == 'true': data = 9
else: data = 6
elif p['south'] == 'true':
if p['west'] == 'true': data = 7
else: data = 8
elif p['west'] == 'true': data = 4
elif key in ['minecraft:carved_pumpkin', 'minecraft:jack_o_lantern'] or key.endswith('glazed_terracotta'):
facing = palette_entry['Properties']['facing']
data = {'south': 0, 'west': 1, 'north': 2, 'east': 3}[facing]
elif key == 'minecraft:vine':
elif key in ['minecraft:vine', 'minecraft:brown_mushroom_block',
'minecraft:red_mushroom_block', 'minecraft:mushroom_stem']:
p = palette_entry['Properties']
if p['south'] == 'true': data |= 1
if p['west'] == 'true': data |= 2
if p['north'] == 'true': data |= 4
if p['east'] == 'true': data |= 8
if p['south'] == 'true':
data |= 1
if p['west'] == 'true':
data |= 2
if p['north'] == 'true':
data |= 4
if p['east'] == 'true':
data |= 8
if p['up'] == 'true':
data |= 16
# Not all blocks here have the down property, so use dict.get() to avoid errors
if p.get('down', 'false') == 'true':
data |= 32
elif key.endswith('anvil'):
facing = palette_entry['Properties']['facing']
if facing == 'west': data += 1