Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 113 additions & 126 deletions skygrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@

displayName = "SethBling's Sky Grid"
inputs = (
("Grid Length", (4, 1, 100)),
("World Type", ("Overworld",
"Nether",
)),
(
"Grid Length",
(4, 1, 100)
),
(
"World Type",
(
"Overworld",
"Nether",
)
),
)

def perform(level, box, options):
Expand All @@ -24,10 +31,8 @@ def perform(level, box, options):
total = 0
cump = {}

if worldtype == "Overworld":
p = normalp()
elif worldtype == "Nether":
p = netherp()
if worldtype == "Overworld": p = normalp()
elif worldtype == "Nether": p = netherp()

# generate the cumulative distribution
for key, value in p.iteritems():
Expand All @@ -39,23 +44,22 @@ def perform(level, box, options):
for z in xrange(box.minz, box.maxz, gridlength):
blockid = pickblock(cump, total)

if(blockid == 6 or blockid == 31 or blockid == 32 or blockid == 37 or
blockid == 38 or blockid == 39 or blockid == 40 or blockid == 83):
level.setBlockAt(x, y, z, 3) #dirt
if(blockid in (6, 31, 32, 37, 38, 39, 40, 83):
level.setBlockAt(x, y, z, 3) # dirt
if(y < box.maxy):
level.setBlockAt(x, y+1, z, blockid)
if(blockid == 83): #reeds
level.setBlockAt(x+1, y, z, 9) #still water
elif(blockid == 81): #cactus
level.setBlockAt(x, y, z, 12) #sand
if(blockid == 83): # reeds
level.setBlockAt(x+1, y, z, 9) # still water
elif(blockid == 81): # cactus
level.setBlockAt(x, y, z, 12) # sand
if(y < box.maxy):
level.setBlockAt(x, y+1, z, blockid)
if(y > box.miny):
level.setBlockAt(x, y-1, z, 106) # vines
elif(blockid == 115): #netherwart
level.setBlockAt(x, y, z, 112)
level.setBlockAt(x, y-1, z, 106) # vines
elif(blockid == 115): # netherwart
level.setBlockAt(x, y, z, 112)
if(y < box.maxy):
level.setBlockAt(x, y+1, z, blockid)
level.setBlockAt(x, y+1, z, blockid)
else:
level.setBlockAt(x, y, z, blockid)

Expand All @@ -66,7 +70,7 @@ def perform(level, box, options):
setSpawnerAt(level, worldtype, x, y, z)

if worldtype == "Overworld":
#generate end portal
# generate end portal
dx = box.maxx - box.minx
dz = box.maxz - box.minz

Expand Down Expand Up @@ -113,71 +117,67 @@ def perform(level, box, options):

level.markDirtyBox(box)

# returns an unnormalized probability distribution for blocks in the
# overworld
# returns an unnormalized probability distribution for blocks in the overworld
def normalp():
p = {}
p[1] = 120 #stone
p[2] = 80 #grass
p[3] = 20 #dirt
p[9] = 10 #still water
p[11] = 5 #still lava
p[12] = 20 #sand
p[13] = 10 #gravel
p[14] = 10 #gold ore
p[15] = 20 #iron ore
p[16] = 40 #coal ore
p[17] = 100 #log
p[18] = 40 #leaves
p[20] = 1 #glass
p[21] = 5 #lapis ore
p[24] = 10 #sandstone
p[29] = 1 #sticky piston
p[30] = 10 #web
p[31] = 3 #shrub
p[32] = 3 #shrub
p[33] = 1 #piston
p[35] = 25 #wool
p[37] = 2 #yellow flower
p[38] = 2 #red flower
p[39] = 2 #brown mushroom
p[40] = 2 #red mushroom
p[46] = 2 #TNT
p[47] = 3 #bookshelves
p[48] = 5 #mossy cobblestone
p[49] = 5 #obsidian
p[52] = 1 #spawner
p[54] = 1 #chest
p[56] = 1 #diamond ore
p[73] = 8 #redstone ore
p[79] = 4 #ice
p[80] = 8 #snow
p[81] = 1 #cactus
p[82] = 20 #clay
p[83] = 15 #reeds
p[86] = 5 #pumpkin
p[103] = 5 #melon
p[110] = 15 #mycelium

return p

# returns an unnormalized probability distribution for blocks in the
# nether
return {
1 : 120, # stone
2 : 80, # grass
3 : 20, # dirt
9 : 10, # still water
11 : 5, # still lava
12 : 20, # sand
13 : 10, # gravel
14 : 10, # gold ore
15 : 20, # iron ore
16 : 40, # coal ore
17 : 100, # log
18 : 40, # leaves
20 : 1, # glass
21 : 5, # lapis ore
24 : 10, # sandstone
29 : 1, # sticky piston
30 : 10, # web
31 : 3, # shrub
32 : 3, # shrub
33 : 1, # piston
35 : 25, # wool
37 : 2, # yellow flower
38 : 2, # red flower
39 : 2, # brown mushroom
40 : 2, # red mushroom
46 : 2, # TNT
47 : 3, # bookshelves
48 : 5, # mossy cobblestone
49 : 5, # obsidian
52 : 1, # spawner
54 : 1, # chest
56 : 1, # diamond ore
73 : 8, # redstone ore
79 : 4, # ice
80 : 8, # snow
81 : 1, # cactus
82 : 20, # clay
83 : 15, # reeds
86 : 5, # pumpkin
103 : 5, # melon
110 : 15 # mycelium
}

# returns an unnormalized probability distribution for blocks in the nether
def netherp():
p = {}
p[11] = 50 #still lava
p[13] = 30 #gravel
p[52] = 2 #mob spawner
p[54] = 1 #chest
p[87] = 300 #netherack
p[88] = 100 #soulsand
p[89] = 50 #glowstone
p[112] = 30 #netherbrick
p[113] = 10 #nether fence
p[114] = 15 #nether stairs
p[115] = 30 #netherwart

return p
return {
11 : 50, # still lava
13 : 30, # gravel
52 : 2, # mob spawner
54 : 1, # chest
87 : 300, # netherack
88 : 100, # soulsand
89 : 50, # glowstone
112 : 30, # netherbrick
113 : 10, # nether fence
114 : 15, # nether stairs
115 : 30 # netherwart
}

# picks a random block from a cumulative distribution
def pickblock(cump, size):
Expand Down Expand Up @@ -207,28 +207,30 @@ def setSpawnerAt(level, worldtype, x, y, z):
chunk.TileEntities.append(spawner)

def overworldSpawns():
return ["Creeper",
"Skeleton",
"Spider",
"CaveSpider",
"Zombie",
"Slime",
"Pig",
"Sheep",
"Cow",
"Chicken",
"Squid",
"Wolf",
"Enderman",
"Silverfish",
"Villager",
]
return [
"Creeper",
"Skeleton",
"Spider",
"CaveSpider",
"Zombie",
"Slime",
"Pig",
"Sheep",
"Cow",
"Chicken",
"Squid",
"Wolf",
"Enderman",
"Silverfish",
"Villager",
]

def netherSpawns():
return ["PigZombie",
"Blaze",
"LavaSlime",
]
return [
"PigZombie",
"Blaze",
"LavaSlime",
]

# fills a chest with random goodies
def fillChestAt(level, x, y, z):
Expand All @@ -237,29 +239,14 @@ def fillChestAt(level, x, y, z):
chest = TileEntity.Create("Chest")
TileEntity.setpos(chest, (x, y, z))

if(random.random() < 0.7):
chest["Items"].append(createItemInRange(256, 294)) #various weapons/random

if(random.random() < 0.7):
chest["Items"].append(createItemInRange(298, 317)) #various armor

if(random.random() < 0.7):
chest["Items"].append(createItemInRange(318, 350)) #various food/tools

if(random.random() < 0.3):
chest["Items"].append(createItemWithRandomDamage(383, 50, 52)) # various spawn eggs

if(random.random() < 0.9):
chest["Items"].append(createItemWithRandomDamage(383, 54, 62)) #various spawn eggs

if(random.random() < 0.4):
chest["Items"].append(createItemWithRandomDamage(383, 90, 96)) #various spawn eggs

if(random.random() < 0.1):
chest["Items"].append(createItemWithRandomDamage(383, 98, 98)) #ocelot spawn egg

if(random.random() < 0.1):
chest["Items"].append(createItemWithRandomDamage(383, 120, 120)) #villager spawn egg
if(random.random() < 0.7): chest["Items"].append(createItemInRange(256, 294)) #various weapons/random
if(random.random() < 0.7): chest["Items"].append(createItemInRange(298, 317)) #various armor
if(random.random() < 0.7): chest["Items"].append(createItemInRange(318, 350)) #various food/tools
if(random.random() < 0.3): chest["Items"].append(createItemWithRandomDamage(383, 50, 52)) # various spawn eggs
if(random.random() < 0.9): chest["Items"].append(createItemWithRandomDamage(383, 54, 62)) #various spawn eggs
if(random.random() < 0.4): chest["Items"].append(createItemWithRandomDamage(383, 90, 96)) #various spawn eggs
if(random.random() < 0.1): chest["Items"].append(createItemWithRandomDamage(383, 98, 98)) #ocelot spawn egg
if(random.random() < 0.1): chest["Items"].append(createItemWithRandomDamage(383, 120, 120)) #villager spawn egg

if(random.random() < 0.7):
itemid = randomInRange(1, 5)
Expand Down