Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- at the time of writing these comments the game is availible to copy, if you use it please credit me
- -- i might make this unavailible at anytime so...
- local x = 0 -- counter for how many blocks generated
- local z = 0 -- z position of currently generating blocks - gets overwritten
- local block = nil -- currently generating block - gets overwritten
- local seed = 1 -- generation seed - gets overwritten by player
- local y = 0 -- y position of currently generating blocks - gets overwritten
- local chunksize = 16 -- size of chunks that are generated - im not sure how changing this affects generation
- local size = 69 -- smoothness of terrain - idk why i called it size
- local xpos = 0 -- x position of currently generating blocks - gets overwritten
- local lcount = 0 -- amount of rows of blocks generated - gets overwritten
- local amplifier = 5 -- amplifier for terrain - high amiplifier + high smoothness = giant hills - low amplifier + low smoothness = tiny spiky mountains - gets overwritten by player
- local chunkmodel = nil -- the currently generating chunk's model - gets overwritten
- local genxpos = 0 -- i think this went unused
- local genzpos = 0 -- i think this went unused
- local isfirstblock = true -- meant to set the chunks "position" so i could use render distance but it made it laggier than without render distance so i might add fog like minecraft 0.0.23a_01
- local chunkrowx = 0 -- i think this went unused
- local chunkrowz = 0 -- i think this went unused
- local mapsizechunk = 4 -- the dimensions of the map in chunks - gets overwritten by player
- local rowchunkcount = 0 -- the amount of chunks that have been generated in a row of chunks - gets overwritten
- local chunkrowcount = 0 -- the amount of rows of chunks that have been generated
- local topwoodblock = Vector3.new(0, 0, 0) -- the position highest block of wood of wood generated used to reference where to generate leaves - gets overwritten
- local treeblockamount = 0 -- the amount of leaves or logs generated - used for determining if dirt is finished generating
- local texture = nil -- the texture being added the the currently generating block
- function leaves(wood, model, x, y, z)
- local leaves = Instance.new("Part", model)
- leaves.Name = "Leaves"
- leaves.Size = Vector3.new(2.5, 2.5, 2.5)
- leaves.Anchored = true
- leaves.Transparency = 1
- texture = Instance.new("Decal", leaves)
- texture.Texture = "http://www.roblox.com/asset/?id=5633520791"
- texture.Face = "Left"
- texture = Instance.new("Decal", leaves)
- texture.Texture = "http://www.roblox.com/asset/?id=5633520791"
- texture.Face = "Right"
- texture = Instance.new("Decal", leaves)
- texture.Texture = "http://www.roblox.com/asset/?id=5633520791"
- texture.Face = "Front"
- texture = Instance.new("Decal", leaves)
- texture.Texture = "http://www.roblox.com/asset/?id=5633520791"
- texture.Face = "Back"
- texture = Instance.new("Decal", leaves)
- texture.Texture = "http://www.roblox.com/asset/?id=5633520791"
- texture.Face = "Bottom"
- texture = Instance.new("Decal", leaves)
- texture.Texture = "http://www.roblox.com/asset/?id=5633520791"
- texture.Face = "Top"
- leaves.Position = wood + Vector3.new(x, y, z)
- end
- function genlayer(cmodel)
- while x < chunksize do
- -- create the block
- block = Instance.new("Part")
- block.Size = Vector3.new(2.5, 2.5, 2.5)
- block.Anchored = true
- texture = Instance.new("Decal", block)
- texture.Texture = "rbxgameasset://Images/grass_dirt"
- texture.Face = "Left"
- texture = Instance.new("Decal", block)
- texture.Texture = "rbxgameasset://Images/grass_dirt"
- texture.Face = "Right"
- texture = Instance.new("Decal", block)
- texture.Texture = "rbxgameasset://Images/grass_dirt"
- texture.Face = "Front"
- texture = Instance.new("Decal", block)
- texture.Texture = "rbxgameasset://Images/grass_dirt"
- texture.Face = "Back"
- texture = Instance.new("Decal", block)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Bottom"
- texture = Instance.new("Decal", block)
- texture.Texture = "rbxgameasset://Images/grass"
- texture.Face = "Top"
- -- if its the first block, then name it chunk position
- if isfirstblock == true then
- block.Name = "ChunkPos"
- isfirstblock = false
- end
- -- find the y value of the block using math.noise
- y = math.floor(math.noise(xpos / size, z / size, seed) * amplifier)
- y = 2.5 * y
- y = 80 + y
- --print(y)
- block.Position = Vector3.new(xpos, y, z)
- z = z + 2.5
- block.Parent = cmodel
- x = x + 1
- end
- end
- function genchunk(chunkzpos)
- chunkmodel = Instance.new("Model")
- --chunkmodel.Parent = game.ServerStorage.Folder
- chunkmodel.Parent = workspace.GeneratedTerrain
- local chunkseed = Instance.new("IntValue", chunkmodel)
- chunkseed.Value = seed * ((rowchunkcount + chunkrowcount) + (rowchunkcount * chunkrowcount))
- print(chunkseed.Value)
- while lcount < chunksize do
- z = chunkzpos
- x = 0
- genlayer(chunkmodel)
- lcount = lcount + 1
- xpos = xpos + 2.5
- end
- isfirstblock = true
- wait()
- end
- function genchunkrow(rowx)
- while rowchunkcount < mapsizechunk do
- xpos = rowx
- lcount = 0
- genchunk(z)
- rowchunkcount = rowchunkcount + 1
- end
- end
- function coalthingy(coal)
- for i,x in pairs(coal:GetTouchingParts()) do
- if math.random(1,3) == 2 and x.Name == "Stone" then
- for i,v in pairs(x:GetChilden()) do
- if not v:IsA("TouchTransmitter") then
- v.Texture = "rbxgameasset://Images/rock_coal"
- end
- end
- if math.random(1,3) == 3 then
- coalthingy(x)
- end
- end
- end
- end
- function generate()
- local hint = Instance.new("Hint", workspace)
- hint.Text = "Generating grass and trees"
- -- set values
- workspace.AllowRenderDistance.Value = false
- amplifier = workspace.Amplifier.Value
- size = workspace.Size.Value
- seed = workspace.Seed.Value
- math.randomseed(seed)
- mapsizechunk = workspace.MapSize.Value
- workspace.RandomSeed.Value = seed
- treeblockamount = 0
- --wait(2)
- -- clear terrain
- for i,v in pairs(workspace.GeneratedTerrain:GetChildren()) do
- v:Destroy()
- wait(0.1)
- end
- -- generate
- while chunkrowcount < mapsizechunk do
- z = 0
- genchunkrow(xpos)
- chunkrowcount = chunkrowcount + 1
- rowchunkcount = 0
- end
- --repeat wait() until #game.ServerStorage.Folder:GetChildren() == mapsizechunk * mapsizechunk
- --for i,v in pairs(game.ServerStorage.Folder:GetChildren()) do
- -- v.Parent = workspace.GeneratedTerrain
- --end
- repeat wait() until #workspace.GeneratedTerrain:GetChildren() == mapsizechunk * mapsizechunk
- hint.Text = "Generating dirt and stone"
- wait(5)
- for i,v in pairs(workspace.GeneratedTerrain:GetDescendants()) do
- if v.Name == "Part" or v.Name == "ChunkPos" then
- local dirt = Instance.new("Part", v.Parent)
- dirt.Size = Vector3.new(2.5, 2.5, 2.5)
- dirt.Anchored = true
- dirt.Name = "Dirt"
- dirt.Position = v.Position - Vector3.new(0, 2.5, 0)
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Left"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Right"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Front"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Back"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Bottom"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Top"
- dirt = Instance.new("Part", v.Parent)
- dirt.Name = "Dirt"
- dirt.Size = Vector3.new(2.5, 2.5, 2.5)
- dirt.Anchored = true
- dirt.Position = v.Position - Vector3.new(0, 5, 0)
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Left"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Right"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Front"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Back"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Bottom"
- texture = Instance.new("Decal", dirt)
- texture.Texture = "rbxgameasset://Images/dirt (1)"
- texture.Face = "Top"
- spawn(function()
- local generated = false
- local stone = nil
- local pos = dirt.Position.Y
- generated = false
- while pos > (workspace.Stone.Value * 2.5) + 2.5 do
- generated = true
- pos = pos - 2.5
- stone = Instance.new("Part", v.Parent)
- stone.Size = Vector3.new(2.5, 2.5, 2.5)
- stone.Anchored = true
- stone.Name = "Stone"
- texture = Instance.new("Decal", stone)
- texture.Texture = "rbxgameasset://Images/stone (1)"
- texture.Face = "Left"
- texture = Instance.new("Decal", stone)
- texture.Texture = "rbxgameasset://Images/stone (1)"
- texture.Face = "Right"
- texture = Instance.new("Decal", stone)
- texture.Texture = "rbxgameasset://Images/stone (1)"
- texture.Face = "Front"
- texture = Instance.new("Decal", stone)
- texture.Texture = "rbxgameasset://Images/stone (1)"
- texture.Face = "Back"
- texture = Instance.new("Decal", stone)
- texture.Texture = "rbxgameasset://Images/stone (1)"
- texture.Face = "Bottom"
- texture = Instance.new("Decal", stone)
- texture.Texture = "rbxgameasset://Images/stone (1)"
- texture.Face = "Top"
- stone.Position = Vector3.new(dirt.Position.X, pos, dirt.Position.Z)
- local touched = stone.Touched:Connect(function() end)
- touched:Disconnect()
- end
- if generated == true then
- stone.Name = "Bedrock"
- for i,x in pairs(stone:GetChildren()) do
- if x:IsA("Decal") then
- x.Texture = "http://www.roblox.com/asset/?id=5634415312"
- end
- end
- end
- end)
- end
- end
- --repeat wait() until (#workspace.GeneratedTerrain:GetDescendants() - (mapsizechunk * mapsizechunk) - treeblockamount) == (((mapsizechunk * 16) * (mapsizechunk * 16)) * 3)
- wait(5)
- hint.Text = "Generating trees"
- for i,v in pairs(workspace.GeneratedTerrain:GetDescendants()) do
- if v.Name == "Part" then
- if seed ~= v.Parent.Value.Value then
- seed = v.Parent.Value.Value
- print(v.Parent.Value.Value)
- math.randomseed(seed)
- end
- if math.random(1, 256) == 69 then -- 1 in 256 chance of generating a tree, considering a chunk is 16x16 blocks and 16x16 = 256 theres is on average 1 tree per chunk
- local log = game.ServerStorage.Log:Clone()
- log.Position = v.Position + Vector3.new(0, 2.5, 0)
- log.Parent = v.Parent
- log = game.ServerStorage.Log:Clone()
- log.Position = v.Position + Vector3.new(0, 5, 0)
- log.Parent = v.Parent
- log = game.ServerStorage.Log:Clone()
- log.Position = v.Position + Vector3.new(0, 7.5, 0)
- log.Parent = v.Parent
- log = game.ServerStorage.Log:Clone()
- log.Position = v.Position + Vector3.new(0, 10, 0)
- log.Parent = v.Parent
- treeblockamount = treeblockamount + 4
- if math.random(1,3) == 1 then -- 1 in 3 chance of the tree being five blocks tall
- topwoodblock = v.Position + Vector3.new(0, 12.5, 0)
- log = game.ServerStorage.Log:Clone()
- log.Position = v.Position + Vector3.new(0, 12.5, 0)
- log.Parent = v.Parent
- treeblockamount = treeblockamount + 1
- if math.random(1,2) == 2 then -- if is a five block tall, 50/50 chance of being 6 blocks tall
- log = game.ServerStorage.Log:Clone()
- log.Position = v.Position + Vector3.new(0, 15, 0)
- log.Parent = v.Parent
- topwoodblock = v.Position + Vector3.new(0, 15, 0)
- treeblockamount = treeblockamount + 1
- end
- else
- topwoodblock = v.Position + Vector3.new(0, 10, 0)
- end
- wait(0.1)
- leaves(topwoodblock, v.Parent, 0, 2.5, 0)
- leaves(topwoodblock, v.Parent, 2.5, 2.5, 0)
- leaves(topwoodblock, v.Parent, 0, 2.5, 2.5)
- leaves(topwoodblock, v.Parent, -2.5, 2.5, 0)
- leaves(topwoodblock, v.Parent, 0, 2.5, -2.5)
- leaves(topwoodblock, v.Parent, 2.5, 0, 0)
- leaves(topwoodblock, v.Parent, 0, 0, 2.5)
- leaves(topwoodblock, v.Parent, -2.5, 0, 0)
- leaves(topwoodblock, v.Parent, 0, 0, -2.5)
- treeblockamount = treeblockamount + 9
- if math.random(1,4) == 1 then
- leaves(topwoodblock, v.Parent, 2.5, 0, -2.5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,4) == 2 then
- leaves(topwoodblock, v.Parent, -2.5, 0, 2.5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,4) == 3 then
- leaves(topwoodblock, v.Parent, -2.5, 0, -2.5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,4) == 4 then
- leaves(topwoodblock, v.Parent, 2.5, 0, 2.5)
- treeblockamount = treeblockamount + 1
- end
- --upper ring
- leaves(topwoodblock, v.Parent, -2.5, -2.5, 2.5)
- leaves(topwoodblock, v.Parent, 2.5, -2.5, -2.5)
- leaves(topwoodblock, v.Parent, 2.5, -2.5, 2.5)
- leaves(topwoodblock, v.Parent, -2.5, -2.5, -2.5)
- leaves(topwoodblock, v.Parent, 0, -2.5, 2.5)
- leaves(topwoodblock, v.Parent, 2.5, -2.5, 0)
- leaves(topwoodblock, v.Parent, 0, -2.5, -2.5)
- leaves(topwoodblock, v.Parent, -2.5, -2.5, 0)
- -- lower ring
- leaves(topwoodblock, v.Parent, -2.5, -5, 2.5)
- leaves(topwoodblock, v.Parent, 2.5, -5, -2.5)
- leaves(topwoodblock, v.Parent, 2.5, -5, 2.5)
- leaves(topwoodblock, v.Parent, -2.5, -5, -2.5)
- leaves(topwoodblock, v.Parent, 0, -5, 2.5)
- leaves(topwoodblock, v.Parent, 2.5, -5, 0)
- leaves(topwoodblock, v.Parent, 0, -5, -2.5)
- leaves(topwoodblock, v.Parent, -2.5, -5, 0)
- -- upper outer ring
- leaves(topwoodblock, v.Parent, 5, -2.5, 2.5)
- leaves(topwoodblock, v.Parent, 5, -2.5, -2.5)
- leaves(topwoodblock, v.Parent, -5, -2.5, 2.5)
- leaves(topwoodblock, v.Parent, -5, -2.5, -2.5)
- leaves(topwoodblock, v.Parent, 2.5, -2.5, 5)
- leaves(topwoodblock, v.Parent, -2.5, -2.5, 5)
- leaves(topwoodblock, v.Parent, 2.5, -2.5, -5)
- leaves(topwoodblock, v.Parent, -2.5, -2.5, -5)
- leaves(topwoodblock, v.Parent, 0, -2.5, 5)
- leaves(topwoodblock, v.Parent, 5, -2.5, 0)
- leaves(topwoodblock, v.Parent, 0, -2.5, -5)
- leaves(topwoodblock, v.Parent, -5, -2.5, 0)
- -- lower outer ring
- leaves(topwoodblock, v.Parent, 5, -5, 2.5)
- leaves(topwoodblock, v.Parent, 5, -5, -2.5)
- leaves(topwoodblock, v.Parent, -5, -5, 2.5)
- leaves(topwoodblock, v.Parent, -5, -5, -2.5)
- leaves(topwoodblock, v.Parent, 2.5, -5, 5)
- leaves(topwoodblock, v.Parent, -2.5, -5, 5)
- leaves(topwoodblock, v.Parent, 2.5, -5, -5)
- leaves(topwoodblock, v.Parent, -2.5, -5, -5)
- leaves(topwoodblock, v.Parent, 0, -5, 5)
- leaves(topwoodblock, v.Parent, 5, -5, 0)
- leaves(topwoodblock, v.Parent, 0, -5, -5)
- leaves(topwoodblock, v.Parent, -5, -5, 0)
- treeblockamount = treeblockamount + 40
- -- corners
- if math.random(1,3) == 1 then
- leaves(topwoodblock, v.Parent, -5, -2.5, 5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,3) == 2 then
- leaves(topwoodblock, v.Parent, 5, -2.5, -5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,3) == 3 then
- leaves(topwoodblock, v.Parent, -5, -2.5, -5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,3) == 1 then
- leaves(topwoodblock, v.Parent, 5, -2.5, 5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,3) == 1 then
- leaves(topwoodblock, v.Parent, -5, -5, 5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,3) == 2 then
- leaves(topwoodblock, v.Parent, 5, -5, -5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,3) == 3 then
- leaves(topwoodblock, v.Parent, -5, -5, -5)
- treeblockamount = treeblockamount + 1
- end
- if math.random(1,3) == 1 then
- leaves(topwoodblock, v.Parent, 5, -5, 5)
- treeblockamount = treeblockamount + 1
- end
- end
- end
- end
- hint.Text = "Generating coal."
- print("ok")
- wait(1)
- for i,v in pairs(workspace.GeneratedTerrain:GetDescendants()) do
- if v.Name == "Stone" then
- if seed ~= v.Parent.Value.Value then
- seed = v.Parent.Value.Value
- print(v.Parent.Value.Value)
- math.randomseed(seed)
- end
- if math.random(1, 512) == 1 then
- v.Name = "RockCoal"
- for i,x in pairs(v:GetChildren()) do
- if not v:IsA("TouchTransmitter") then
- x.Texture = "rbxgameasset://Images/rock_coal"
- end
- end
- coalthingy(v)
- end
- end
- end
- hint.Text = "Generating iron."
- hint.Text = "Generating gold."
- hint.Text = "Done."
- -- reset values
- chunkrowcount = 0
- z = 0
- x = 0
- xpos = 0
- lcount = 0
- wait(5)
- hint:Destroy()
- end
- workspace.Generate.Head.ClickDetector.MouseClick:Connect(generate)
Add Comment
Please, Sign In to add comment