textures: clean up chest code
- drop 1.14 compatibility - code style fixes
This commit is contained in:
@@ -2184,14 +2184,6 @@ def chests(self, blockid, data):
|
||||
# the first 3 bits are the orientation as stored in minecraft,
|
||||
# bits 0x8 and 0x10 indicate which half of the double chest is it.
|
||||
|
||||
# This is an annoying little check, but when normal_left.png exists we are using 1.15 textures
|
||||
# which are different from 1.14 and before.
|
||||
try:
|
||||
t = self.load_image("assets/minecraft/textures/entity/chest/normal_left.png")
|
||||
is115 = True
|
||||
except (TextureException, IOError):
|
||||
is115 = False
|
||||
|
||||
# first, do the rotation if needed
|
||||
orientation_data = data & 7
|
||||
if self.rotation == 1:
|
||||
@@ -2223,53 +2215,52 @@ def chests(self, blockid, data):
|
||||
except (TextureException, IOError):
|
||||
t = self.load_image("assets/minecraft/textures/entity/chest/chest.png")
|
||||
|
||||
if is115:
|
||||
t = ImageOps.flip(t) # for some reason the 1.15 images are upside down
|
||||
|
||||
# the textures is no longer in terrain.png, get it from
|
||||
# item/chest.png and get by cropping all the needed stuff
|
||||
if t.size != (64, 64): t = t.resize((64, 64), Image.ANTIALIAS)
|
||||
# top
|
||||
top = t.crop((28,50,42,64)) if is115 else t.crop((14,0,28,14))
|
||||
top = t.crop((28, 50, 42, 64))
|
||||
top.load() # every crop need a load, crop is a lazy operation
|
||||
# see PIL manual
|
||||
img = Image.new("RGBA", (16, 16), self.bgcolor)
|
||||
alpha_over(img, top, (1, 1))
|
||||
top = img
|
||||
# front
|
||||
front_top = t.crop((42,45,56,50)) if is115 else t.crop((14,14,28,19))
|
||||
front_top = t.crop((42, 45, 56, 50))
|
||||
front_top.load()
|
||||
front_bottom = t.crop((42,21,56,31)) if is115 else t.crop((14,34,28,43))
|
||||
front_bottom = t.crop((42, 21, 56, 31))
|
||||
front_bottom.load()
|
||||
front_lock = t.crop((1,59,3,63)) if is115 else t.crop((1,0,3,4))
|
||||
front_lock = t.crop((1, 59, 3, 63))
|
||||
front_lock.load()
|
||||
front = Image.new("RGBA", (16, 16), self.bgcolor)
|
||||
alpha_over(front, front_top, (1, 1))
|
||||
alpha_over(front, front_bottom, (1, 5))
|
||||
alpha_over(front, front_lock, (7, 3))
|
||||
# left side
|
||||
# left side, right side, and back are esentially the same for
|
||||
# left side, right side, and back are essentially the same for
|
||||
# the default texture, we take it anyway just in case other
|
||||
# textures make use of it.
|
||||
side_l_top = t.crop((14,45,28,50)) if is115 else t.crop((0,14,14,19))
|
||||
side_l_top = t.crop((14, 45, 28, 50))
|
||||
side_l_top.load()
|
||||
side_l_bottom = t.crop((14,21,28,31)) if is115 else t.crop((0,34,14,43))
|
||||
side_l_bottom = t.crop((14, 21, 28, 31))
|
||||
side_l_bottom.load()
|
||||
side_l = Image.new("RGBA", (16, 16), self.bgcolor)
|
||||
alpha_over(side_l, side_l_top, (1, 1))
|
||||
alpha_over(side_l, side_l_bottom, (1, 5))
|
||||
# right side
|
||||
side_r_top = t.crop((28,45,42,50)) if is115 else t.crop((28,14,43,20))
|
||||
side_r_top = t.crop((28, 45, 42, 50))
|
||||
side_r_top.load()
|
||||
side_r_bottom = t.crop((28,21,42,31)) if is115 else t.crop((28,33,42,43))
|
||||
side_r_bottom = t.crop((28, 21, 42, 31))
|
||||
side_r_bottom.load()
|
||||
side_r = Image.new("RGBA", (16, 16), self.bgcolor)
|
||||
alpha_over(side_r, side_r_top, (1, 1))
|
||||
alpha_over(side_r, side_r_bottom, (1, 5))
|
||||
# back
|
||||
back_top = t.crop((0,45,14,50)) if is115 else t.crop((42,14,56,18))
|
||||
back_top = t.crop((0, 45, 14, 50))
|
||||
back_top.load()
|
||||
back_bottom = t.crop((0,21,14,31)) if is115 else t.crop((42,33,56,43))
|
||||
back_bottom = t.crop((0, 21, 14, 31))
|
||||
back_bottom.load()
|
||||
back = Image.new("RGBA", (16, 16), self.bgcolor)
|
||||
alpha_over(back, back_top, (1, 1))
|
||||
@@ -2279,7 +2270,6 @@ def chests(self, blockid, data):
|
||||
# large chest
|
||||
# the textures is no longer in terrain.png, get it from
|
||||
# item/chest.png and get all the needed stuff
|
||||
if is115:
|
||||
t_left = self.load_image("assets/minecraft/textures/entity/chest/normal_left.png")
|
||||
t_right = self.load_image("assets/minecraft/textures/entity/chest/normal_right.png")
|
||||
# for some reason the 1.15 images are upside down
|
||||
@@ -2333,48 +2323,19 @@ def chests(self, blockid, data):
|
||||
alpha_over(back, back_top_right, (16, 1))
|
||||
alpha_over(back, back_bottom_left, (1, 5))
|
||||
alpha_over(back, back_bottom_right, (16, 5))
|
||||
else:
|
||||
t = self.load_image("assets/minecraft/textures/entity/chest/normal_double.png")
|
||||
if t.size != (128,64): t = t.resize((128,64), Image.ANTIALIAS)
|
||||
|
||||
# top
|
||||
top = t.crop((14,0,44,14))
|
||||
top.load()
|
||||
img = Image.new("RGBA", (32,16), self.bgcolor)
|
||||
alpha_over(img,top,(1,1))
|
||||
top = img
|
||||
# front
|
||||
front_top = t.crop((14,14,44,18))
|
||||
front_top.load()
|
||||
front_bottom = t.crop((14,33,44,43))
|
||||
front_bottom.load()
|
||||
front_lock = t.crop((1,0,3,5))
|
||||
front_lock.load()
|
||||
front = Image.new("RGBA", (32,16), self.bgcolor)
|
||||
alpha_over(front,front_top,(1,1))
|
||||
alpha_over(front,front_bottom,(1,5))
|
||||
alpha_over(front,front_lock,(15,3))
|
||||
# back
|
||||
back_top = t.crop((58,14,88,18))
|
||||
back_top.load()
|
||||
back_bottom = t.crop((58,33,88,43))
|
||||
back_bottom.load()
|
||||
back = Image.new("RGBA", (32,16), self.bgcolor)
|
||||
alpha_over(back,back_top,(1,1))
|
||||
alpha_over(back,back_bottom,(1,5))
|
||||
|
||||
# left side
|
||||
side_l_top = t_left.crop((29,45,43,50)) if is115 else t.crop((0,14,14,18))
|
||||
side_l_top = t_left.crop((29, 45, 43, 50))
|
||||
side_l_top.load()
|
||||
side_l_bottom = t_left.crop((29,21,43,31)) if is115 else t.crop((0,33,14,43))
|
||||
side_l_bottom = t_left.crop((29, 21, 43, 31))
|
||||
side_l_bottom.load()
|
||||
side_l = Image.new("RGBA", (16, 16), self.bgcolor)
|
||||
alpha_over(side_l, side_l_top, (1, 1))
|
||||
alpha_over(side_l, side_l_bottom, (1, 5))
|
||||
# right side
|
||||
side_r_top = t_right.crop((0,45,14,50)) if is115 else t.crop((44,14,58,18))
|
||||
side_r_top = t_right.crop((0, 45, 14, 50))
|
||||
side_r_top.load()
|
||||
side_r_bottom = t_right.crop((0,21,14,31)) if is115 else t.crop((44,33,58,43))
|
||||
side_r_bottom = t_right.crop((0, 21, 14, 31))
|
||||
side_r_bottom.load()
|
||||
side_r = Image.new("RGBA", (16, 16), self.bgcolor)
|
||||
alpha_over(side_r, side_r_top, (1, 1))
|
||||
|
||||
Reference in New Issue
Block a user