forked from cuberite/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummon.lua
More file actions
197 lines (179 loc) · 5.61 KB
/
summon.lua
File metadata and controls
197 lines (179 loc) · 5.61 KB
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
local Minecarts =
{
["minecart"] = E_ITEM_MINECART,
["chest_minecart"] = E_ITEM_CHEST_MINECART,
["furnace_minecart"] = E_ITEM_FURNACE_MINECART,
["hopper_minecart"] = E_ITEM_MINECART_WITH_HOPPER,
["tnt_minecart"] = E_ITEM_MINECART_WITH_TNT,
-- 1.10 and below
["MinecartChest"] = E_ITEM_CHEST_MINECART,
["MinecartFurnace"] = E_ITEM_FURNACE_MINECART,
["MinecartHopper"] = E_ITEM_MINECART_WITH_HOPPER,
["MinecartRideable"] = E_ITEM_MINECART,
["MinecartTNT"] = E_ITEM_MINECART_WITH_TNT
}
local Mobs =
{
["bat"] = mtBat,
["blaze"] = mtBlaze,
["cave_spider"] = mtCaveSpider,
["chicken"] = mtChicken,
["cow"] = mtCow,
["creeper"] = mtCreeper,
["ender_dragon"] = mtEnderDragon,
["enderman"] = mtEnderman,
["ghast"] = mtGhast,
["giant"] = mtGiant,
["guardian"] = mtGuardian,
["horse"] = mtHorse,
["iron_golem"] = mtIronGolem,
["magma_cube"] = mtMagmaCube,
["mooshroom"] = mtMooshroom,
["ocelot"] = mtOcelot,
["pig"] = mtPig,
["rabbit"] = mtRabbit,
["sheep"] = mtSheep,
["silverfish"] = mtSilverfish,
["skeleton"] = mtSkeleton,
["slime"] = mtSlime,
["snowman"] = mtSnowGolem,
["spider"] = mtSpider,
["squid"] = mtSquid,
["villager"] = mtVillager,
["witch"] = mtWitch,
["wither"] = mtWither,
["wolf"] = mtWolf,
["zombie"] = mtZombie,
["zombie_pigman"] = mtZombiePigman,
-- 1.10 and below
["Bat"] = mtBat,
["Blaze"] = mtBlaze,
["CaveSpider"] = mtCaveSpider,
["Chicken"] = mtChicken,
["Cow"] = mtCow,
["Creeper"] = mtCreeper,
["EnderDragon"] = mtEnderDragon,
["Enderman"] = mtEnderman,
["Ghast"] = mtGhast,
["Giant"] = mtGiant,
["Guardian"] = mtGuardian,
["Horse"] = mtHorse,
["LavaSlime"] = mtMagmaCube,
["MushroomCow"] = mtMooshroom,
["Ozelot"] = mtOcelot,
["Pig"] = mtPig,
["Rabbit"] = mtRabbit,
["Sheep"] = mtSheep,
["Silverfish"] = mtSilverfish,
["Skeleton"] = mtSkeleton,
["Slime"] = mtSlime,
["SnowMan"] = mtSnowGolem,
["Spider"] = mtSpider,
["Squid"] = mtSquid,
["Villager"] = mtVillager,
["VillagerGolem"] = mtIronGolem,
["Witch"] = mtWitch,
["Wither"] = mtWither,
["Wolf"] = mtWolf,
["Zombie"] = mtZombie,
["PigZombie"] = mtZombiePigman
}
local Projectiles =
{
["arrow"] = cProjectileEntity.pkArrow,
["egg"] = cProjectileEntity.pkEgg,
["ender_pearl"] = cProjectileEntity.pkEnderPearl,
["fireworks_rocket"] = cProjectileEntity.pkFirework,
["fishing_float"] = cProjectileEntity.pkFishingFloat,
["fireball"] = cProjectileEntity.pkGhastFireball,
["potion"] = cProjectileEntity.pkSplashPotion,
["small_fireball"] = cProjectileEntity.pkFireCharge,
["snowball"] = cProjectileEntity.pkSnowball,
["wither_skull"] = cProjectileEntity.pkWitherSkull,
["xp_bottle"] = cProjectileEntity.pkExpBottle,
-- 1.10 and below
["Arrow"] = cProjectileEntity.pkArrow,
["Fireball"] = cProjectileEntity.pkGhastFireball,
["FireworksRocketEntity"] = cProjectileEntity.pkFirework,
["FishingFloat"] = cProjectileEntity.pkFishingFloat,
["SmallFireball"] = cProjectileEntity.pkFireCharge,
["Snowball"] = cProjectileEntity.pkSnowball,
["ThrownEgg"] = cProjectileEntity.pkEgg,
["ThrownEnderpearl"] = cProjectileEntity.pkEnderPearl,
["ThrownExpBottle"] = cProjectileEntity.pkExpBottle,
["ThrownPotion"] = cProjectileEntity.pkSplashPotion,
["WitherSkull"] = cProjectileEntity.pkWitherSkull
}
local function RelativeCommandCoord(a_Split, a_Relative)
if string.sub(a_Split, 1, 1) == "~" then
local rel = tonumber(string.sub(a_Split, 2, -1))
if rel then
return a_Relative + rel
end
return a_Relative
end
return tonumber(a_Split)
end
local function SpawnEntity(EntityName, World, X, Y, Z)
if EntityName == "boat" or EntityName == "Boat" then
local Material = cBoat.bmOak
World:SpawnBoat(Vector3d(X, Y, Z), Material)
elseif EntityName == "falling_block" or EntityName == "FallingSand" then
local BlockType = E_BLOCK_SAND
local BlockMeta = 0
World:SpawnFallingBlock(Vector3i(X, Y, Z), BlockType, BlockMeta)
elseif EntityName == "lightning_bolt" or EntityName == "LightningBolt" then
World:CastThunderbolt(Vector3i(X, Y, Z))
elseif Minecarts[EntityName] then
World:SpawnMinecart(Vector3d(X, Y, Z), Minecarts[EntityName])
elseif Mobs[EntityName] then
World:SpawnMob(X, Y, Z, Mobs[EntityName])
elseif Projectiles[EntityName] then
World:CreateProjectile(Vector3d(X, Y, Z), Projectiles[EntityName], Player, Player:GetEquippedItem(), Player:GetLookVector() * 20)
elseif EntityName == "tnt" or EntityName == "PrimedTnt" then
World:SpawnPrimedTNT(Vector3d(X, Y, Z))
elseif EntityName == "xp_orb" or EntityName == "XPOrb" then
local Reward = 1
World:SpawnExperienceOrb(Vector3d(X, Y, Z), Reward)
else
return false
end
return true
end
function HandleSummonCommand(Split, Player)
if not Split[2] then
Player:SendMessageInfo("Usage: " .. Split[1] .. " <entityname> [x] [y] [z]")
else
local X = Player:GetPosX()
local Y = Player:GetPosY()
local Z = Player:GetPosZ()
local World = Player:GetWorld()
if Split[3] then
X = RelativeCommandCoord(Split[3], X)
end
if Split[4] then
Y = RelativeCommandCoord(Split[4], Y)
end
if Split[5] then
Z = RelativeCommandCoord(Split[5], Z)
end
if not X then
Player:SendMessageFailure("'" .. Split[3] .. "' is not a valid number")
return true
end
if not Y then
Player:SendMessageFailure("'" .. Split[4] .. "' is not a valid number")
return true
end
if not Z then
Player:SendMessageFailure("'" .. Split[5] .. "' is not a valid number")
return true
end
if SpawnEntity(Split[2], World, X, Y, Z) then
Player:SendMessageSuccess("Successfully summoned entity at [X:" .. math.floor(X) .. " Y:" .. math.floor(Y) .. " Z:" .. math.floor(Z) .. "]")
else
Player:SendMessageFailure("Unknown entity '" .. Split[2] .. "'")
end
end
return true
end