forked from boskee/Minecraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocks.py
1875 lines (1548 loc) · 48.7 KB
/
blocks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# Imports, sorted alphabetically.
# Future imports
from math import floor
# Python packages
# Nothing for now...
import struct # for update_tile_entity
# Third-party packages
import pyglet
from pyglet.gl import *
from pyglet.image.atlas import TextureAtlas
import custom_types
from custom_types import iVector
from utils import load_image, make_nbt_from_dict, extract_nbt
# Modules from this project
import globals as G
from random import randint
import sounds
from entity import CropEntity, FurnaceEntity
from textures import TexturePackList
BLOCK_TEXTURE_DIR = {}
def get_texture_coordinates(x, y, tileset_size=G.TILESET_SIZE):
if x == -1 and y == -1:
return ()
m = 1.0 / tileset_size
dx = x * m
dy = y * m
return dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + m
#To enable, extract a texture pack's blocks folder to resources/texturepacks/textures/blocks/
#For MC 1.5 Texture Packs
class TextureGroupIndividual(pyglet.graphics.Group):
def __init__(self, names, height=1.0, width=1.0, background_color=None):
super(TextureGroupIndividual, self).__init__()
atlas = None
# self.texture = atlas.texture
self.texture_data = []
i=0
texture_pack = G.texture_pack_list.selected_texture_pack
for name in names:
if not name in BLOCK_TEXTURE_DIR:
BLOCK_TEXTURE_DIR[name] = texture_pack.load_texture(['textures', 'blocks', name + '.png'])
if not BLOCK_TEXTURE_DIR[name]:
continue
texture_size = BLOCK_TEXTURE_DIR[name].width
# remove background color for crack textures
if background_color is not None:
data = bytearray(BLOCK_TEXTURE_DIR[name].get_image_data().get_data('RGBA', texture_size * 4))
for i in range(len(data)):
if data [i] == background_color:
data[i] = 0
BLOCK_TEXTURE_DIR[name].get_image_data().set_data('RGBA', texture_size * 4, bytes(data))
if atlas == None:
atlas = TextureAtlas(texture_size * len(names), texture_size)
self.texture = atlas.texture
subtex = atlas.add(BLOCK_TEXTURE_DIR[name].get_region(0,0,texture_size,texture_size))
for val in subtex.tex_coords:
i += 1
if i % 3 != 0: self.texture_data.append(val) #tex_coords has a z component we don't utilize
if atlas == None:
atlas = TextureAtlas(1, 1)
self.texture = atlas.texture
#Repeat the last texture for the remaining sides
# (top, bottom, side, side, side, side)
# ie: ("dirt",) ("grass_top","dirt","grass_side")
# Becomes ("dirt","dirt","dirt","dirt","dirt","dirt") ("grass_top","dirt","grass_side","grass_side","grass_side","grass_side")
self.texture_data += self.texture_data[-8:]*(6-len(names))
# resize the texture
if height != 1.0 or width != 1.0 :
if len(self.texture_data) == 0:
return
tex_width = tex_height = self.texture_data[2] - self.texture_data[0]
h_margin = tex_height * (1.0 - height)
w_margin = tex_width * (1.0 - width) / 2
# top and bottom
for i in (0, 1):
for j in (0, 1, 3, 6): self.texture_data[i * 8 + j] += w_margin
for j in (2, 4, 5, 7): self.texture_data[i * 8 + j] -= w_margin
# side
for i in range(2, 6):
for j in (0, 6): self.texture_data[i * 8 + j] += w_margin
for j in (2, 4): self.texture_data[i * 8 + j] -= w_margin
for j in (5, 7): self.texture_data[i * 8 + j] -= h_margin
def set_state(self):
if self.texture:
glBindTexture(self.texture.target, self.texture.id)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glEnable(self.texture.target)
def unset_state(self):
if self.texture:
glDisable(self.texture.target)
class BlockID:
"""
Datatype for Block and Item IDs
Creation: BlockID(1) BlockID(35) BlockID(35, 3) BlockID((35,
3)) BlockID("35.3")
str(id) : "1.0" "35.0" "35.3" "35.3"
"35.3"
Typical uses: id == 1 id == BlockID(35, 3) id < 255
"""
main = 0
sub = 0 # A.k.a. DataID, damageID, metadata, etc
icon_name = None
def __init__(self, main, sub=0, icon_name=None):
if isinstance(main, tuple):
self.main, self.sub = main
elif isinstance(main, str):
# Allow "35", "35.0", or "35,0"
spl = main.split(".") if "." in main else main.split(",") if "," in main else (main, 0)
if len(spl) == 2:
a, b = spl
elif len(spl) == 1:
a = spl[0]
b = 0
else:
raise ValueError("Expected #.# or #,#. Got %s" % main)
self.main = int(a)
self.sub = int(b or 0)
elif isinstance(main, self.__class__):
self.main = main.main
self.sub = main.sub
else:
self.main = int(main)
self.sub = int(sub)
self.icon_name = icon_name
def __repr__(self):
return '%d.%d' % (self.main, self.sub)
def __hash__(self):
return hash((self.main, self.sub))
def __eq__(self, other):
if isinstance(other, tuple):
return (self.main, self.sub) == other
if isinstance(other, float):
return float(repr(self.main)) == other
if isinstance(other, int):
return self.main == other
if isinstance(other, BlockID):
return self.main == other.main and self.sub == other.sub
def __ne__(self, other):
return not (self == other)
def __bool__(self):
"""Checks whether it is an AirBlock."""
return self.main != 0
def is_item(self):
return self.main >= G.ITEM_ID_MIN
def filename(self):
if self.icon_name != None: return ["textures", "items" if self.is_item() else "blocks", str(self.icon_name) + ".png"]
if self.sub == 0: return ["textures", "icons", str(self.main) + ".png"]
return ["textures", "icons", '%d.%d.png' % (self.main, self.sub)]
class Block:
id = None # Original minecraft id (also called data value).
# Verify on http://www.minecraftwiki.net/wiki/Data_values
# when creating a new "official" block.
_drop_id = None
_drop_quantity = None
player_damage = 0
@property
def drop_id(self):
return self._drop_id
@drop_id.setter
def drop_id(self, value):
self._drop_id = value
@property
def drop_quantity(self):
return self._drop_quantity
@drop_quantity.setter
def drop_quantity(self, value):
self._drop_quantity = value
_texture_data = None
@property
def texture_data(self):
return self._texture_data
@texture_data.setter
def texture_data(self, value):
self._texture_data = value
width = 1.0
height = 1.0
# Texture coordinates from the tileset.
top_texture = ()
bottom_texture = ()
side_texture = ()
front_texture = None
vertex_mode = G.VERTEX_CUBE
group = None # The texture (group) the block renders from
texture_name = None # A list of block faces, named what Mojang names their blocks/"file".png
icon_name = None
# Sounds
break_sound = sounds.wood_break
# Physical attributes
hardness = 0.0 # hardness can be found on http://www.minecraftwiki.net/wiki/Digging#Blocks_by_hardness
density = 1
transparent = False
regenerated_health = 0
# Inventory attributes
max_stack_size = 64
amount_label_color = 255, 255, 255, 255
name = "Block"
digging_tool = -1
# How long can this item burn (-1 for non-fuel items)
burning_time = -1
# How long does it take to smelt this item (-1 for unsmeltable items)
smelting_time = -1
render_as_normal_block = True
# if sub_id_as_metadata, we will create an instance for this block when it's being added to the world
# and use its sub id as metadata
sub_id_as_metadata = False
def __init__(self, width=None, height=None):
self.id = BlockID(self.id or 0, 0, self.icon_name)
self.drop_id = self.id
self.drop_quantity = 1
if width is not None:
self.width = width
if height is not None:
self.height = height
G.BLOCKS_DIR[self.id] = self
if not self.render_as_normal_block:
return
self.update_texture()
def __str__(self):
return self.name
def get_texture_data(self):
textures = self.top_texture + self.bottom_texture \
+ self.front_texture + self.side_texture
if self.vertex_mode != G.VERTEX_CROSS:
textures += self.side_texture * 2
return list(textures)
def get_vertices(self, x, y, z):
w = self.width / 2.0
h = self.height / 2.0
y_offset = (1.0 - self.height) / 2
y -= y_offset
xm = x - w
xp = x + w
ym = y - h
yp = y + h
zm = z - w
zp = z + w
vertices = ()
if len(self.top_texture) > 0 or len(self.side_texture) == 0:
vertices += (
xm, yp, zm, xm, yp, zp, xp, yp, zp, xp, yp, zm # top
)
if len(self.bottom_texture) > 0 or len(self.side_texture) == 0:
vertices += (
xm, ym, zm, xp, ym, zm, xp, ym, zp, xm, ym, zp # bottom
)
if self.vertex_mode == G.VERTEX_CROSS:
vertices += (
xm, ym, zm, xp, ym, zp, xp, yp, zp, xm, yp, zm,
xm, ym, zp, xp, ym, zm, xp, yp, zm, xm, yp, zp,
)
elif self.vertex_mode == G.VERTEX_GRID:
xm2 = x - w / 2.0
xp2 = x + w / 2.0
zm2 = z - w / 2.0
zp2 = z + w / 2.0
vertices += (
xm2, ym, zm, xm2, ym, zp, xm2, yp, zp, xm2, yp, zm, # left
xp2, ym, zp, xp2, ym, zm, xp2, yp, zm, xp2, yp, zp, # right
xm, ym, zp2, xp, ym, zp2, xp, yp, zp2, xm, yp, zp2, # front
xp, ym, zm2, xm, ym, zm2, xm, yp, zm2, xp, yp, zm2, # back
)
else:
vertices += (
xm, ym, zm, xm, ym, zp, xm, yp, zp, xm, yp, zm, # left
xp, ym, zp, xp, ym, zm, xp, yp, zm, xp, yp, zp, # right
xm, ym, zp, xp, ym, zp, xp, yp, zp, xm, yp, zp, # front
xp, ym, zm, xm, ym, zm, xm, yp, zm, xp, yp, zm, # back
)
return vertices
def get_metadata(self):
if self.sub_id_as_metadata:
return self.id.sub
def set_metadata(self, metadata):
if self.sub_id_as_metadata:
self.id.sub = metadata
def play_break_sound(self, player: custom_types.Player, position=None):
if self.break_sound is not None:
sounds.play_sound(self.break_sound, player=player, position=position)
def update_tile_entity(self, value):
pass
def update_texture(self):
if self.texture_name:
self.group = TextureGroupIndividual(self.texture_name, self.height, self.width)
if self.group:
self.texture_data = self.group.texture_data
if self.top_texture == ():
return
if self.front_texture is None:
self.front_texture = self.side_texture
if not self.texture_data:
# Applies get_texture_coordinates to each of the faces to be textured.
for k in ('top_texture', 'bottom_texture', 'side_texture', 'front_texture'):
v = getattr(self, k)
if v:
setattr(self, k, get_texture_coordinates(*v))
self.texture_data = self.get_texture_data()
def on_neighbor_change(self, world, neighbor_pos, self_pos):
pass
def can_place_on(self, block_id):
return False
class BlockColorizer:
def __init__(self, filename):
self.color_data = G.texture_pack_list.selected_texture_pack.load_texture(['misc', filename])
# if the texture is not available, don't colorize it
if self.color_data is None:
return
self.color_data = self.color_data.get_data('RGB', self.color_data.width * 3)
def get_color(self, temperature, humidity):
temperature = 1 - temperature
if temperature + humidity > 1:
delta = (temperature + humidity - 1) / 2
temperature -= delta
humidity -= delta
if self.color_data is None:
return 1, 1, 1
pos = int(floor(humidity * 255) * BYTE_PER_LINE + 3 * floor((temperature) * 255))
return float(self.color_data[pos]) / 255, float(self.color_data[pos + 1]) / 255, float(self.color_data[pos + 2]) / 255
class AirBlock(Block):
max_stack_size = 0
density = 0
id = 0
name = "Air"
class WoodBlock(Block):
break_sound = sounds.wood_break
digging_tool = G.AXE
class HardBlock(Block):
break_sound = sounds.stone_break
class StoneBlock(HardBlock):
texture_name = "stone",
icon_name = "stone"
hardness = 1.5
id = 1
name = "Stone"
digging_tool = G.PICKAXE
def __init__(self):
super(StoneBlock, self).__init__()
self.drop_id = BlockID(CobbleBlock.id)
colorizer = BlockColorizer('stonecolor.png')
def get_color(self, temperature, humidity):
ret = []
ret.extend(list(self.colorizer.get_color(temperature, humidity)) * 24)
return ret
PIXEL_PER_LINE = 256
BYTE_PER_LINE = PIXEL_PER_LINE * 3
class GrassBlock(Block):
texture_name = "grass_top", "dirt", "grass_side"
icon_name = "grass_side"
hardness = 0.6
id = 2
break_sound = sounds.dirt_break
name = 'Grass'
digging_tool = G.SHOVEL
colorizer = BlockColorizer('grasscolor.png')
def __init__(self):
super(GrassBlock, self).__init__()
self.drop_id = BlockID(DirtBlock.id)
def get_color(self, temperature, humidity):
ret = []
# colorize only the top of the grass block
ret.extend(list(self.colorizer.get_color(temperature, humidity)) * 4)
ret.extend([1] * 60)
return ret
def on_neighbor_change(self, world, neighbor_pos, self_pos):
# something has been put on this grass block, which makes it become dirt block
if (self_pos[0], self_pos[1] + 1, self_pos[-1]) in world:
world.remove_block(None, self_pos)
world.add_block(self_pos, dirt_block)
class DirtBlock(Block):
texture_name = "dirt",
icon_name = "dirt"
hardness = 0.5
id = 3
name = "Dirt"
digging_tool = G.SHOVEL
break_sound = sounds.dirt_break
class SnowBlock(Block):
texture_name = "snow",
icon_name = "snow"
hardness = 0.5
id = 80
name = "Snow"
amount_label_color = 0, 0, 0, 255
break_sound = sounds.dirt_break
class SandBlock(Block):
texture_name = "sand",
icon_name = "sand"
hardness = 0.5
amount_label_color = 0, 0, 0, 255
id = 12
name = "Sand"
digging_tool = G.SHOVEL
break_sound = sounds.sand_break
colorizer = BlockColorizer('sandcolor.png')
def get_color(self, temperature, humidity):
ret = []
ret.extend(list(self.colorizer.get_color(temperature, humidity)) * 24)
return ret
class GoldOreBlock(HardBlock):
texture_name = "oreGold",
icon_name = "oreGold"
hardness = 3
id = 14
digging_tool = G.PICKAXE
name = "Gold Ore"
class IronOreBlock(HardBlock):
texture_name = "oreIron",
icon_name = "oreIron"
hardness = 3
id = 15
digging_tool = G.PICKAXE
name = "Iron Ore"
smelting_time = 10
class DiamondOreBlock(HardBlock):
texture_name = "oreDiamond",
icon_name = "oreDiamond"
hardness = 3
id = 56
digging_tool = G.PICKAXE
def __init__(self):
super(DiamondOreBlock, self).__init__()
self.drop_id = BlockID(264)
name = "Diamond Ore"
class CoalOreBlock(HardBlock):
texture_name = "oreCoal",
icon_name = "oreCoal"
hardness = 3
id = 16
digging_tool = G.PICKAXE
def __init__(self):
super(CoalOreBlock, self).__init__()
self.drop_id = BlockID(263)
name = "Coal Ore"
class BrickBlock(HardBlock):
texture_name = "brick",
icon_name = "brick"
hardness = 2
id = 45
digging_tool = G.PICKAXE
name = "Bricks"
class LampBlock(Block):
top_texture = 3, 1
bottom_texture = 3, 1
side_texture = 3, 1
hardness = 0.3
amount_label_color = 0, 0, 0, 255
id = 124
name = "Lamp"
break_sound = sounds.glass_break
class GlassBlock(Block):
texture_name = "glass",
icon_name = "glass"
transparent = True
hardness = 0.2
amount_label_color = 0, 0, 0, 255
id = 20
name = "Glass"
break_sound = sounds.glass_break
class GravelBlock(Block):
texture_name = "gravel",
icon_name = "gravel"
hardness = 0.4
amount_label_color = 0, 0, 0, 255
id = 13
name = "Gravel"
digging_tool = G.SHOVEL
break_sound = sounds.gravel_break
@property
def drop_id(self):
# 10% chance of dropping flint
if randint(0, 10) == 0:
return BlockID(318)
else:
return self._drop_id
@drop_id.setter
def drop_id(self, value):
self._drop_id = value
class BedrockBlock(HardBlock):
texture_name = "bedrock",
icon_name = "bedrock"
hardness = -1 # Unbreakable
id = 7
name = "Bedrock"
class WaterBlock(Block):
height = 0.8
texture_name = "water",
transparent = True
hardness = -1 # Unobtainable
density = 0.5
id = 8
name = "Water"
break_sound = sounds.water_break
colorizer = BlockColorizer('watercolor.png')
def get_color(self, temperature, humidity):
ret = []
ret.extend(list(self.colorizer.get_color(temperature, humidity)) * 24)
return ret
class CraftTableBlock(WoodBlock):
texture_name = "workbench_top","wood","workbench_front","workbench_side",
icon_name = "workbench_front"
hardness = 2.5
id = 58
name = "Crafting Table"
burning_time = 15
class MetaBlock(WoodBlock): # this is a experimental block.
hardness = 2.5
id = 0.1
name = "Action"
class SandstoneBlock(HardBlock):
texture_name = "sandstone_top","sandstone_bottom","sandstone_side"
icon_name = "sandstone_side"
amount_label_color = 0, 0, 0, 255
hardness = 0.8
id = 24
name = "Sandstone"
class EmeraldOreBlock(HardBlock):
texture_name = "oreEmerald",
icon_name = "oreEmerald"
hardness = 2
id = 129,0
name = "Emerald Ore"
class LapisOreBlock(HardBlock):
texture_name = "oreLapis",
icon_name = "oreLapis"
hardness = 2
id = 21
name = "Lapis Ore"
class RubyOreBlock(HardBlock):
top_texture = 12, 0
bottom_texture = 12, 0
side_texture = 12, 0
hardness = 2
id = 129,1 # not in MC
name = "Ruby Ore"
class SapphireOreBlock(HardBlock):
top_texture = 12, 2
bottom_texture = 12, 2
side_texture = 12, 2
hardness = 2
id = 129,2 # not in MC
name = "Sapphire Ore"
# Changed Marble to Quartz -- It seems that Quartz is MC's answer to Tekkit's Marble.
class QuartzBlock(HardBlock):
texture_name = "quartzblock_top","quartzblock_bottom","quartzblock_side"
icon_name = "quartzblock_side"
id = 155,0
hardness = 2
name = "Quartz"
amount_label_color = 0, 0, 0, 255
digging_tool = G.PICKAXE
class ChiseledQuartzBlock(HardBlock):
texture_name = "quartzblock_chiseled_top","quartzblock_chiseled_top","quartzblock_chiseled"
icon_name = "quartzblock_chiseled"
id = 155,1
hardness = 2
name = "Chiseled Quartz"
amount_label_color = 0, 0, 0, 255
digging_tool = G.PICKAXE
class ColumnQuartzBlock(HardBlock):
texture_name = "quartzblock_lines_top","quartzblock_lines_top","quartzblock_lines"
icon_name = "quartzblock_lines"
id = 155,2
hardness = 2
name = "Column Quartz"
amount_label_color = 0, 0, 0, 255
digging_tool = G.PICKAXE
class QuartzBrickBlock(HardBlock):
top_texture = 9, 7
bottom_texture = 9, 7
side_texture = 9, 7
id = 155,3
hardness = 2
name = "Quartz Brick"
amount_label_color = 0, 0, 0, 255
digging_tool = G.PICKAXE
class BirchWoodPlankBlock(WoodBlock):
texture_name = "wood_birch",
icon_name = "wood_birch"
hardness = 2
id = 5,0
burning_time = 15
name = "Birch Wood Planks"
class OakWoodPlankBlock(WoodBlock):
texture_name = "wood",
icon_name = "wood"
hardness = 2
id = 5,1
burning_time = 15
name = "Oak Wood Planks"
class JungleWoodPlankBlock(WoodBlock):
texture_name = "wood_jungle",
icon_name = "wood_jungle"
hardness = 2
id = 5,3
burning_time = 15
name = "Jungle Wood Planks"
# FIXME: Can't find its specific id on minecraftwiki.
# from ronmurphy: This is just the snowy side grass from the above texture pack. MC has one like this also.
class SnowGrassBlock(Block):
texture_name = "snow","dirt","snow_side"
icon_name = "snow_side"
hardness = 0.6
id = 80
break_sound = sounds.dirt_break
def __init__(self):
super(SnowGrassBlock, self).__init__()
self.drop_id = BlockID(DirtBlock.id)
class OakWoodBlock(WoodBlock):
texture_name = "tree_top","tree_top","tree_side"
icon_name = "tree_side"
hardness = 2
id = 17,0
name = "Oak wood"
burning_time = 15
class OakBranchBlock(WoodBlock):
top_texture = 7, 0
bottom_texture = 7, 0
side_texture = 7, 0
hardness = 2
id = 17,1
name = "Oak wood"
def __init__(self):
super(OakBranchBlock, self).__init__()
self.drop_id = BlockID(OakWoodBlock.id)
class JungleWoodBlock(WoodBlock):
texture_name = "tree_top","tree_top","tree_jungle"
icon_name = "tree_jungle"
hardness = 2
id = 17,1
name = "Jungle wood"
burning_time = 15
class BirchWoodBlock(WoodBlock):
texture_name = "tree_top","tree_top","tree_birch"
icon_name = "tree_birch"
hardness = 2
id = 17,2
amount_label_color = 0, 0, 0, 255
name = "Birch wood"
burning_time = 15
class CactusBlock(Block):
width = 0.8
transparent = True
texture_name = "cactus_top","cactus_bottom","cactus_side"
icon_name = "cactus_side"
hardness = 2
player_damage = 1
id = 81,0
name = "Cactus"
class TallCactusBlock(Block):
width = 0.3
texture_name = "cactus_top","cactus_bottom","cactus_side"
icon_name = "cactus_side"
transparent = True
hardness = 1
player_damage = 1
id = 81,1 # not a real MC block, so the last possible # i think.
name = "Thin Cactus"
class LeafBlock(Block):
break_sound = sounds.leaves_break
colorizer = BlockColorizer('foliagecolor.png')
def __init__(self):
super(LeafBlock, self).__init__()
self.drop_id = None
def get_color(self, temperature, humidity):
ret = []
ret.extend(list(self.colorizer.get_color(temperature, humidity)) * 24)
return ret
class OakLeafBlock(LeafBlock):
texture_name = "leaves",
icon_name = "leaves"
hardness = 0.3
id = 18,0
name = "Oak Leaves"
class JungleLeafBlock(LeafBlock):
texture_name = "leaves_jungle",
icon_name = "leaves_jungle"
hardness = 0.3
id = 18,1
name = "Jungle Leaves"
class BirchLeafBlock(LeafBlock):
texture_name = "leaves",
icon_name = "leaves"
hardness = 0.3
id = 18,2
name = "Birch Leaves"
def __init__(self):
super(BirchLeafBlock, self).__init__()
self.drop_id = None
class MelonBlock(Block):
width = 0.8
height = 0.8
texture_name = "melon_top","melon_top","melon_side"
icon_name = "melon_side"
transparent = True
hardness = 1
id = 103
name = "Melon"
regenerated_health = 3
break_sound = sounds.melon_break
class PumpkinBlock(Block):
width = 0.8
height = 0.8
texture_name = "pumpkin_top","pumpkin_top","pumpkin_side"
icon_name = "pumpkin_side"
transparent = True
hardness = 1
id = 86
name = "Pumpkin"
regenerated_health = 3 # pumpkin pie
break_sound = sounds.melon_break
class TorchBlock(WoodBlock):
width = 0.1
height = 0.55
texture_name = "torch",
icon_name = "torch"
hardness = 1
transparent = True
id = 50
name = "Torch"
def on_neighbor_change(self, world, neighbor_pos, self_pos):
# the block under this torch has been removed, so remove the torch too
if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world:
world.remove_block(None, self_pos)
class YFlowersBlock(Block):
vertex_mode = G.VERTEX_CROSS
hardness = 0.0
# prevent generating vertices for top and bottom
side_texture = 0, 0
transparent = True
density = 0.3
id = 37
texture_name = "flower", "flower", "flower"
icon_name = "flower"
name = "Dandelion"
break_sound = sounds.leaves_break
def __init__(self):
super(YFlowersBlock, self).__init__()
self.texture_data = self.texture_data[0:2 * 4 * 2]
def on_neighbor_change(self, world, neighbor_pos, self_pos):
if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world:
world.remove_block(None,self_pos)
class StoneSlabBlock(HardBlock):
texture_name = "stoneslab_top","stoneslab_top","stoneslab_side",
icon_name = "stoneslab_side"
hardness = 2
id = 43
name = "Full Stone Slab"
class ClayBlock(HardBlock):
texture_name = "clay",
icon_name = "clay"
hardness = 0.6
id = 82
name = "Clay Block"
class CobbleBlock(HardBlock):
texture_name = "stonebrick",
icon_name = "stonebrick"
hardness = 2
id = 4,0
name = "Cobblestone"
class CobbleFenceBlock(HardBlock):
width = 0.6
texture_name = "stonebrick",
icon_name = "stonebrick"
transparent = True
hardness = 2
id = 4,1
name = "Cobblestone Fence Post"
class BookshelfBlock(WoodBlock):
texture_name = "wood","wood","bookshelf"
icon_name = "bookshelf"
hardness = 1.5
id = 47
name = "Bookshelf"
burning_time = 15
class FurnaceBlock(HardBlock):
texture_name = "furnace_top","stonebrick","furnace_front","furnace_side"
icon_name = "furnace_front"
hardness = 3.5
id = 61
name = "Furnace"
entity_type = FurnaceEntity
entity = None
slot_count = 2
def __del__(self):
if self.entity is not None:
del self.entity
# compatible with inventory
def set_slot(self, index, value):
i = int(index)
if i < 0 or i >= 2:
return None
if i == 0:
self.set_smelting_item(value)
else:
self.set_fuel(value)
def at(self, index):
i = int(index)
if i < 0 or i >= 2:
return None
return self.entity.fuel if i == 1 else self.entity.smelt_stack
def remove_all_by_index(self, index):
i = int(index)
if i < 0 or i >= 2:
return None
if i == 0:
self.entity.smelt_stack = None
else:
self.entity.fuel = None
def get_items(self):
return [self.entity.smelt_stack, self.entity.fuel]