forked from fogleman/Minecraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocks.py
1724 lines (1470 loc) · 42.1 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 __future__ import unicode_literals
# Python packages
# Nothing for now...
# Third-party packages
import pyglet
from pyglet.gl import *
from pyglet.image.atlas import TextureAtlas
from utils import load_image
# Modules from this project
import globals as G
from random import randint
import sounds
from entity import WheatCropEntity, FurnaceEntity
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):
super(TextureGroupIndividual, self).__init__()
atlas = TextureAtlas(64*len(names), 64)
self.texture = atlas.texture
self.texture_data = []
i=0
for name in names:
if not name in BLOCK_TEXTURE_DIR:
if G.TEXTURE_PACK != 'default':
BLOCK_TEXTURE_DIR[name] = load_image('resources', 'texturepacks', G.TEXTURE_PACK, 'textures', 'blocks', name + '.png')
else:
BLOCK_TEXTURE_DIR[name] = load_image('resources', 'texturepacks', 'textures', 'blocks', name + '.png')
if not BLOCK_TEXTURE_DIR[name]:
return None
subtex = atlas.add(BLOCK_TEXTURE_DIR[name].get_region(0,0,64,64))
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
#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))
def set_state(self):
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):
glDisable(self.texture.target)
class BlockID(object):
"""
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, etc
def __init__(self, main, sub=0):
if isinstance(main, tuple):
self.main, self.sub = main
elif isinstance(main, basestring):
# 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)
def __repr__(self):
return '%d.%d' % (self.main, self.sub)
def __hash__(self):
return hash((self.main, self.sub))
def __cmp__(self, other):
if isinstance(other, tuple):
return cmp((self.main, self.sub), other)
if isinstance(other, float):
return cmp(float(repr(self.main)), other)
if isinstance(other, int):
return cmp(self.main, other)
if isinstance(other, BlockID):
return cmp(self.main, other.main) or cmp(self.sub, other.sub)
def __nonzero__(self):
"""Checks whether it is an AirBlock."""
return self.main != 0
def is_item(self):
return self.main > 255
def filename(self):
if self.sub == 0: return str(self.main)
return '%d.%d' % (self.main, self.sub)
class Block(object):
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
@property
def drop_id(self):
return self._drop_id
@drop_id.setter
def drop_id(self, value):
self._drop_id = 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 = ()
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
# 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
player_damage = 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
def __init__(self, width=None, height=None):
self.id = BlockID(self.id or 0)
self.drop_id = self.id
if width is not None:
self.width = width
if height is not None:
self.height = height
if self.texture_name and G.TEXTURE_PACK != 'default':
self.group = TextureGroupIndividual(self.texture_name)
if self.group:
self.texture_data = self.group.texture_data
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'):
v = getattr(self, k)
if v:
setattr(self, k, get_texture_coordinates(*v))
self.texture_data = self.get_texture_data()
G.BLOCKS_DIR[self.id] = self
def __str__(self):
return self.name
def get_texture_data(self):
textures = self.top_texture + self.bottom_texture \
+ self.side_texture * 2
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 play_break_sound(self, player=None, position=None):
if self.break_sound is not None:
sounds.play_sound(self.break_sound, player=player, position=position)
class AirBlock(Block):
top_texture = -1, -1
bottom_texture = -1, -1
side_texture = -1, -1
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):
top_texture = 2, 1
bottom_texture = 2, 1
side_texture = 2, 1
texture_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)
class GrassBlock(Block):
top_texture = 1, 0
bottom_texture = 0, 1
side_texture = 0, 0
texture_name = "grass_top", "dirt", "grass_side"
hardness = 0.6
id = 2
break_sound = sounds.dirt_break
name = 'Grass'
digging_tool = G.SHOVEL
def __init__(self):
super(GrassBlock, self).__init__()
self.drop_id = BlockID(DirtBlock.id)
class DirtBlock(Block):
top_texture = 0, 1
bottom_texture = 0, 1
side_texture = 0, 1
texture_name = "dirt",
hardness = 0.5
id = 3
name = "Dirt"
digging_tool = G.SHOVEL
break_sound = sounds.dirt_break
class SnowBlock(Block):
top_texture = 4, 1
bottom_texture = 4, 1
side_texture = 4, 1
texture_name = "snow",
hardness = 0.5
id = 80
name = "Snow"
amount_label_color = 0, 0, 0, 255
break_sound = sounds.dirt_break
class SandBlock(Block):
top_texture = 1, 1
bottom_texture = 1, 1
side_texture = 1, 1
texture_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
class GoldOreBlock(HardBlock):
top_texture = 3, 4
bottom_texture = 3, 4
side_texture = 3, 4
texture_name = "oreGold",
hardness = 3
id = 14
digging_tool = G.PICKAXE
name = "Gold Ore"
class IronOreBlock(HardBlock):
top_texture = 1, 4
bottom_texture = 1, 4
side_texture = 1, 4
texture_name = "oreIron",
hardness = 3
id = 15
digging_tool = G.PICKAXE
name = "Iron Ore"
smelting_time = 10
class DiamondOreBlock(HardBlock):
top_texture = 2, 4
bottom_texture = 2, 4
side_texture = 2, 4
texture_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):
top_texture = 0, 4
bottom_texture = 0, 4
side_texture = 0, 4
texture_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):
top_texture = 2, 0
bottom_texture = 2, 0
side_texture = 2, 0
texture_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):
top_texture = 0, 5
bottom_texture = 0, 5
side_texture = 0, 5
texture_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):
top_texture = 1, 5
bottom_texture = 1, 5
side_texture = 1, 5
texture_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):
top_texture = 3, 0
bottom_texture = 3, 0
side_texture = 3, 0
texture_name = "bedrock",
hardness = -1 # Unbreakable
id = 7
name = "Bedrock"
class WaterBlock(Block):
height = 0.8
top_texture = 0, 2
bottom_texture = 0, 6 # transparent
side_texture = 0, 6 # transparent
texture_name = "water",
transparent = True
hardness = -1 # Unobtainable
density = 0.5
id = 8
name = "Water"
break_sound = sounds.water_break
class CraftTableBlock(WoodBlock):
top_texture = 8, 1
bottom_texture = 1, 1
side_texture = 8, 0
texture_name = "workbench_top","wood","workbench_front","workbench_side",
hardness = 2.5
id = 58
name = "Crafting Table"
burning_time = 15
class MetaBlock(WoodBlock): # this is a experimental block.
top_texture = 9, 0
bottom_texture = 9, 0
side_texture = 9, 0
hardness = 2.5
id = 0.1
name = "Action"
class SandstoneBlock(HardBlock):
top_texture = 2, 2
bottom_texture = 2, 2
side_texture = 2, 2
texture_name = "sandstone_top","sandstone_bottom","sandstone_side"
amount_label_color = 0, 0, 0, 255
hardness = 0.8
id = 24
name = "Sandstone"
class EmeraldOreBlock(HardBlock):
top_texture = 8, 5
bottom_texture = 8, 5
side_texture = 8, 5
texture_name = "oreEmerald",
hardness = 2
id = 129,0
name = "Emerald Ore"
class LapisOreBlock(HardBlock):
top_texture = 8, 6
bottom_texture = 8, 6
side_texture = 8, 6
texture_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):
top_texture = 3, 2
bottom_texture = 9, 4
side_texture = 3, 2
texture_name = "quartzblock_top","quartzblock_bottom","quartzblock_side"
id = 155,0
hardness = 2
name = "Quartz"
amount_label_color = 0, 0, 0, 255
digging_tool = G.PICKAXE
class ChiseledQuartzBlock(HardBlock):
top_texture = 3, 2
bottom_texture = 9, 4
side_texture = 9, 6
texture_name = "quartzblock_chiseled_top","quartzblock_chiseled_top","quartzblock_chiseled"
id = 155,1
hardness = 2
name = "Chiseled Quartz"
amount_label_color = 0, 0, 0, 255
digging_tool = G.PICKAXE
class ColumnQuartzBlock(HardBlock):
top_texture = 3, 2
bottom_texture = 9, 4
side_texture = 9, 5
texture_name = "quartzblock_lines_top","quartzblock_lines_top","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 = 13, 0
bottom_texture = 13, 0
side_texture = 13, 0
id = 155,3
hardness = 2
name = "Quartz Brick"
amount_label_color = 0, 0, 0, 255
digging_tool = G.PICKAXE
class BirchWoodPlankBlock(WoodBlock):
top_texture = 3, 3
bottom_texture = 3, 3
side_texture = 3, 3
texture_name = "wood_birch",
hardness = 2
id = 5,0
burning_time = 15
name = "Birch Wood Planks"
class OakWoodPlankBlock(WoodBlock):
top_texture = 1, 3
bottom_texture = 1, 3
side_texture = 1, 3
texture_name = "wood",
hardness = 2
id = 5,1
burning_time = 15
name = "Oak Wood Planks"
class JungleWoodPlankBlock(WoodBlock):
top_texture = 2, 3
bottom_texture = 2, 3
side_texture = 2, 3
texture_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):
top_texture = 4, 1
bottom_texture = 0, 1
side_texture = 4, 0
texture_name = "snow","dirt","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):
top_texture = 7, 1
bottom_texture = 7, 1
side_texture = 7, 0
texture_name = "tree_top","tree_top","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):
top_texture = 6, 1
bottom_texture = 6, 1
side_texture = 6, 0
texture_name = "tree_top","tree_top","tree_jungle"
hardness = 2
id = 17,1
name = "Jungle wood"
burning_time = 15
class BirchWoodBlock(WoodBlock):
top_texture = 5, 1
bottom_texture = 5, 1
side_texture = 5, 0
texture_name = "tree_top","tree_top","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
top_texture = 7, 5
bottom_texture = 7, 3
side_texture = 7, 4
transparent = True
texture_name = "cactus_top","cactus_bottom","cactus_side"
hardness = 2
player_damage = 1
id = 81,0
name = "Cactus"
class TallCactusBlock(Block):
width = 0.3
top_texture = 7, 5
bottom_texture = 7, 3
side_texture = 7, 4
texture_name = "cactus_top","cactus_bottom","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
def __init__(self):
super(LeafBlock, self).__init__()
self.drop_id = None
class OakLeafBlock(LeafBlock):
top_texture = 7, 2
bottom_texture = 7, 2
side_texture = 7, 2
texture_name = "leaves",
hardness = 0.3
id = 18,0
name = "Oak Leaves"
class JungleLeafBlock(LeafBlock):
top_texture = 6, 2
bottom_texture = 6, 2
side_texture = 6, 2
texture_name = "leaves_jungle",
hardness = 0.3
id = 18,1
name = "Jungle Leaves"
class BirchLeafBlock(LeafBlock):
top_texture = 5, 2
bottom_texture = 5, 2
side_texture = 5, 2
texture_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
top_texture = 4, 3
bottom_texture = 4, 3
side_texture = 4, 2
texture_name = "melon_top","melon_top","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
top_texture = 2, 5
bottom_texture = 2, 5
side_texture = 3, 5
texture_name = "pumpkin_top","pumpkin_top","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.5
top_texture = 5, 5
bottom_texture = 0, 1
side_texture = 4, 5
texture_name = "torch",
hardness = 1
transparent = True
player_damage = 1
id = 50
name = "Torch"
class YFlowersBlock(Block):
width = 0.5
height = 0.7
top_texture = 6, 6
bottom_texture = -1, -1
side_texture = 6, 5
vertex_mode = G.VERTEX_CROSS
hardness = 0.0
transparent = True
density = 0.3
id = 37
name = "Dandelion"
break_sound = sounds.leaves_break
class StoneSlabBlock(HardBlock):
top_texture = 4, 4
bottom_texture = 4, 4
side_texture = 4, 4
texture_name = "stoneslab_top","stoneslab_top","stoneslab_side",
hardness = 2
id = 43
name = "Full Stone Slab"
class ClayBlock(HardBlock):
top_texture = 6, 4
bottom_texture = 6, 4
side_texture = 6, 4
texture_name = "clay",
hardness = 0.6
id = 82
name = "Clay Block"
class CobbleBlock(HardBlock):
top_texture = 6, 3
bottom_texture = 6, 3
side_texture = 6, 3
texture_name = "stonebrick",
hardness = 2
id = 4,0
name = "Cobblestone"
class CobbleFenceBlock(HardBlock):
width = 0.6
top_texture = 6, 3
bottom_texture = 6, 3
side_texture = 6, 3
texture_name = "stonebrick",
transparent = True
hardness = 2
id = 4,1
name = "Cobblestone Fence Post"
class BookshelfBlock(WoodBlock):
top_texture = 1, 2
bottom_texture = 0, 2
side_texture = 5, 4
texture_name = "wood","wood","bookshelf"
hardness = 1.5
id = 47
name = "Bookshelf"
burning_time = 15
class FurnaceBlock(HardBlock):
top_texture = 7, 7
bottom_texture = 6, 3
side_texture = 7, 6
texture_name = "furnace_top","stonebrick","furnace_front","furnace_side"
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]
def remove_unnecessary_stacks(self):
if self.entity.fuel is not None:
if self.entity.fuel.amount == 0:
self.entity.fuel = None
if self.entity.smelt_stack is not None:
if self.entity.smelt_stack.amount == 0:
self.entity.smelt_stack = None
def set_smelting_item(self, item):
if item is None:
return
self.entity.smelt_stack = item
self.entity.outcome_item = G.smelting_recipes.smelt(self.entity.smelt_stack.get_object())
# no such recipe
if self.entity.outcome_item is None:
return
else:
self.entity.smelt()
def set_fuel(self, fuel):
if fuel is None:
return
self.entity.fuel = fuel
# invalid fuel
if self.entity.fuel.get_object().burning_time == -1:
return
else:
self.entity.smelt()
def set_outcome_callback(self, callback):
self.entity.outcome_callback = callback
def set_fuel_callback(self, callback):
self.entity.fuel_callback = callback
def get_smelt_outcome(self):
return self.entity.smelt_outcome
class FarmBlock(Block):
top_texture = 5, 3
bottom_texture = 0, 1
side_texture = 0, 1
hardness = 0.5
id = 60
name = "Farm Dirt"
break_sound = sounds.dirt_break
def __init__(self):
super(FarmBlock, self).__init__()
self.drop_id = BlockID(DirtBlock.id)
class ChestBlock(Block):
top_texture = 8, 4
bottom_texture = 8, 2
side_texture = 8, 3
hardness = 2
id = 54
name = "Chest"
burning_time = 15
# Wool blocks
class BlackWoolBlock(Block):
top_texture = 15, 0
bottom_texture = 15, 0
side_texture = 15, 0
texture_name = "cloth_15",
hardness = 1
id = 35,15
name = "Black Wool"
class RedWoolBlock(Block):