Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function round(x)
- if x%2 ~= 0.5 then
- return math.floor(x+0.5)
- end
- return x-0.5
- end
- function grid(n, grid)
- return math.floor(n/grid + 0.5)*grid
- end
- function putTexture(part, frontF, backF, topF, bottomF, leftF, rightF, className)
- local faces = {"Front", "Back", "Top", "Bottom", "Left", "Right"}
- for i,f in pairs(faces) do
- local decal = Instance.new(className)
- decal.StudsPerTileU = 2.6
- decal.StudsPerTileV = 2.6
- if i == 1 then decal.Texture = frontF decal.Name = f end
- if i == 2 then decal.Texture = backF or frontF decal.Name = f end
- if i == 3 then decal.Texture = topF or frontF decal.Name = f end
- if i == 4 then decal.Texture = bottomF or frontF decal.Name = f end
- if i == 5 then decal.Texture = leftF or frontF decal.Name = f end
- if i == 6 then decal.Texture = rightF or frontF decal.Name = f end
- decal.Face = f
- decal.Parent = part
- end
- return part
- end
- function QuickCreateInstance(className, properties)
- local inst = Instance.new(className)
- for propertyName,propertyValue in pairs(properties or {}) do
- inst[propertyName] = propertyValue
- end
- return inst
- end
- local collectionService = game:GetService("CollectionService")
- local posToGen = Vector3.new(10000, 10000, 10000)
- posToGen = Vector3.new(grid(posToGen.X, 2.6), grid(posToGen.Y, 2.6), grid(posToGen.Z, 2.6))
- local x1 = 500
- local y1 = 1
- local z1 = 500
- local seed = math.random()*100
- local terrainBlocks = workspace:FindFirstChild("TerrainBlocks") or Instance.new("Model", workspace)
- terrainBlocks.Name = "TerrainBlocks"
- local oldBlockBehind = nil
- for x = 1, z1 do
- local line = Instance.new("Model", terrainBlocks)
- line.Name = "Line " .. x
- for z = 1, x1 do
- for y = 1, y1 do
- local blockType = "grass"--math.noise(x/150, seed*16, z/150) > 0.4 and "stone" or "grass"
- local height = math.sqrt(13 + (math.noise(x/160, seed, z/160)*10 + math.noise(x/500, seed*5, z/500)*7))*3
- local pos = Vector3.new(x * 2.6, (round((height*26) / 2.6) * 2.6) - (y * 2.6), z * 2.6) + posToGen - Vector3.new(x1*2.6/2, 0, z1*2.6/2)
- local blockBehind = line:FindFirstChild("B " .. grid(pos.X, 2.6)/2.6 .. "," .. grid(pos.Y, 2.6)/2.6 .. "," .. grid(pos.Z - 2.6, 2.6)/2.6)
- if not blockBehind or (blockBehind and collectionService:HasTag(blockBehind, blockType) == false) then
- if oldBlockBehind then
- local oldLine = terrainBlocks:FindFirstChild("Line " .. x - 1)
- if oldLine then
- local sideBlock = oldLine:FindFirstChild("B " .. grid(oldBlockBehind.CFrame.p.X - 2.6, 2.6)/2.6 .. "," .. grid(oldBlockBehind.CFrame.p.Y, 2.6)/2.6 .. "," .. grid(oldBlockBehind.CFrame.p.Z + oldBlockBehind.Size.Z/2 - 0.5, 2.6)/2.6)
- if sideBlock and sideBlock.Size.Z == oldBlockBehind.Size.Z then
- sideBlock:Destroy()
- oldBlockBehind.Size = sideBlock.Size + Vector3.new(2.6, 0, 0)
- oldBlockBehind.CFrame = CFrame.new(sideBlock.CFrame.p.X + 1.3, oldBlockBehind.CFrame.p.Y, oldBlockBehind.CFrame.p.Z)
- -- debug
- --for _,c in pairs(oldBlockBehind:GetChildren()) do
- -- if c:IsA("Texture") then c.Color3 = Color3.new(0, 0, 1) end
- --end
- end
- end
- end
- --local chunkPos = Vector3.new(grid(pos.X/2.6, 16), grid(pos.Y/2.6, 16), grid(pos.Z/2.6, 16))
- --local chunk = chunks:FindFirstChild(chunkPos.X .. "," .. chunkPos.Y .. "," .. chunkPos.Z) or Instance.new("Model", chunks)
- --chunk.Name = chunkPos.X .. "," .. chunkPos.Y .. "," .. chunkPos.Z
- local block = Instance.new("Part")
- block.Material = "Fabric"
- block.Anchored = true
- block.Size = Vector3.new(2.6, 2.6, 2.6)
- block.CFrame = CFrame.new(grid(pos.X, 2.6), grid(pos.Y, 2.6), grid(pos.Z, 2.6))
- block.Name = "B " .. grid(pos.X, 2.6)/2.6 .. "," .. grid(pos.Y, 2.6)/2.6 .. "," .. grid(pos.Z, 2.6)/2.6
- --if y == 1 then
- if blockType == "grass" then
- -- if y == 1 then
- putTexture(block, "rbxassetid://3132023393", "rbxassetid://3132023393",
- "rbxassetid://3131912045", "rbxassetid://3103457697",
- "rbxassetid://3132023393", "rbxassetid://3132023393", "Texture")
- -- elseif y >= 2 then
- -- putTexture(block, "rbxassetid://3103457697", "rbxassetid://3103457697",
- -- "rbxassetid://3103457697", "rbxassetid://3103457697",
- -- "rbxassetid://3103457697", "rbxassetid://3103457697", "Texture")
- -- end
- --elseif y == 2 then
- else
- putTexture(block, "rbxassetid://3131912893", "rbxassetid://3131912893",
- "rbxassetid://3131912893", "rbxassetid://3131912893",
- "rbxassetid://3131912893", "rbxassetid://3131912893", "Texture")
- end
- -- elseif y >= 3 then
- -- putTexture(block, "rbxassetid://75880927", "rbxassetid://75880927",
- -- "rbxassetid://75880927", "rbxassetid://75880927",
- -- "rbxassetid://75880927", "rbxassetid://75880927", "Texture")
- --end
- block.Parent = line
- collectionService:AddTag(block, blockType)
- else
- if blockBehind:IsA("ObjectValue") then blockBehind = blockBehind.Value end
- if collectionService:HasTag(blockBehind, blockType) then
- blockBehind.Size = blockBehind.Size + Vector3.new(0, 0, 2.6)
- blockBehind.CFrame = CFrame.new(blockBehind.CFrame.p + Vector3.new(0, 0, 2.6/2))
- blockBehind.Name = "B " .. grid(pos.X, 2.6)/2.6 .. "," .. grid(pos.Y, 2.6)/2.6 .. "," .. grid(pos.Z, 2.6)/2.6
- --QuickCreateInstance("ObjectValue", {Name = "B " .. grid(pos.X, 2.6)/2.6 .. "," .. grid(pos.Y, 2.6)/2.6 .. "," .. grid(pos.Z - 2.6, 2.6)/2.6, Value = blockBehind, Parent = blockBehind})
- oldBlockBehind = blockBehind
- end
- end
- end
- end
- wait()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement