forked from mcedit/pymclevel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.py
184 lines (157 loc) · 4.41 KB
/
entity.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
'''
Created on Jul 23, 2011
@author: Rio
'''
import nbt
from copy import deepcopy
__all__ = "Entity, TileEntity".split(", ")
id = "id"
Motion = "Motion"
Pos = "Pos"
Rotation = "Rotation"
class TileEntity(object):
baseStructures = {
"Furnace": (
("BurnTime", nbt.TAG_Short),
("CookTime", nbt.TAG_Short),
("Items", nbt.TAG_List),
),
"Sign": (
("Items", nbt.TAG_List),
),
"MobSpawner": (
("Items", nbt.TAG_List),
),
"Chest": (
("Items", nbt.TAG_List),
),
"Music": (
("note", nbt.TAG_Byte),
),
"Trap": (
("Items", nbt.TAG_List),
),
"RecordPlayer": (
("Record", nbt.TAG_Int),
),
"Piston": (
("blockId", nbt.TAG_Int),
("blockData", nbt.TAG_Int),
("facing", nbt.TAG_Int),
("progress", nbt.TAG_Float),
("extending", nbt.TAG_Byte),
),
"Cauldron": (
("Items", nbt.TAG_List),
("BrewTime", nbt.TAG_Int),
),
}
knownIDs = baseStructures.keys()
maxItems = {
"Furnace": 3,
"Chest": 27,
"Trap": 9,
"Cauldron": 4,
}
slotNames = {
"Furnace": {
0: "Raw",
1: "Fuel",
2: "Product"
},
"Cauldron": {
0: "Potion",
1: "Potion",
2: "Potion",
3: "Reagent",
}
}
@classmethod
def Create(cls, tileEntityID, **kw):
tileEntityTag = nbt.TAG_Compound()
tileEntityTag[id] = nbt.TAG_String(tileEntityID)
base = cls.baseStructures.get(tileEntityID, None)
if base:
for (name, tag) in base:
tileEntityTag[name] = tag()
cls.setpos(tileEntityTag, (0, 0, 0))
return tileEntityTag
@classmethod
def pos(cls, tag):
return [tag[a].value for a in 'xyz']
@classmethod
def setpos(cls, tag, pos):
for a, p in zip('xyz', pos):
tag[a] = nbt.TAG_Int(p)
@classmethod
def copyWithOffset(cls, tileEntity, copyOffset):
eTag = deepcopy(tileEntity)
eTag['x'] = nbt.TAG_Int(tileEntity['x'].value + copyOffset[0])
eTag['y'] = nbt.TAG_Int(tileEntity['y'].value + copyOffset[1])
eTag['z'] = nbt.TAG_Int(tileEntity['z'].value + copyOffset[2])
return eTag
class Entity(object):
monsters = ["Creeper",
"Skeleton",
"Spider",
"CaveSpider",
"Giant",
"Zombie",
"Slime",
"PigZombie",
"Ghast",
"Pig",
"Sheep",
"Cow",
"Chicken",
"Squid",
"Wolf",
"Monster",
"Enderman",
"Silverfish",
"Blaze",
"Villager",
"LavaSlime",
]
projectiles = ["Arrow",
"Snowball",
"Egg",
"Fireball",
"SmallFireball",
"ThrownEnderpearl",
]
items = ["Item",
"XPOrb",
"Painting",
"EnderCrystal",
]
vehicles = ["Minecart", "Boat"]
tiles = ["PrimedTnt", "FallingSand"]
@classmethod
def Create(cls, entityID, **kw):
entityTag = nbt.TAG_Compound()
entityTag[id] = nbt.TAG_String(entityID)
Entity.setpos(entityTag, (0, 0, 0))
return entityTag
@classmethod
def pos(cls, tag):
if Pos not in tag:
raise InvalidEntity(tag)
return [a.value for a in tag[Pos]]
@classmethod
def setpos(cls, tag, pos):
tag["Pos"] = nbt.TAG_List([nbt.TAG_Double(p) for p in pos])
@classmethod
def copyWithOffset(cls, entity, copyOffset):
eTag = deepcopy(entity)
positionTags = map(lambda p, co: nbt.TAG_Double(p.value + co), eTag["Pos"], copyOffset)
eTag["Pos"] = nbt.TAG_List(positionTags)
if eTag["id"].value == "Painting":
eTag["TileX"].value += copyOffset[0]
eTag["TileY"].value += copyOffset[1]
eTag["TileZ"].value += copyOffset[2]
return eTag
class InvalidEntity(ValueError):
pass
class InvalidTileEntity(ValueError):
pass