So, I’ve made a (probably very inefficient) grid block generation test which is on the client (I will change that later but that’s not my problem at the moment.)
I’m trying to lessen lag for later, and working on a system to hide blocks that aren’t able to be seen (obstructed by blocks from every side)
But my problem is that I cant seem to find a good way of doing this.
My script (The part I’m talking about is at around line 25):
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local Client_PlotData = {}
local function getServerPlotData()
local Remote = ReplicatedStorage.Remotes["GetServerBuilds"]
return Remote:InvokeServer()
end
local function updateToServer(ItemTable)
local Remote = ReplicatedStorage.Remotes["UpdateServerBuilds"]
Remote:FireServer(ItemTable)
end
local function getItemData(Item)
local List = ReplicatedStorage.Items[Item]
local Data = List["Data - "..Item]
return require(Data)
end
--everything below is what i was using while trying to figure it out myself
local function getBlockAt(Coords)
local Xcoord, Ycoord, Zcoord = Coords[1], Coords[2], Coords[3]
for index, object in pairs(Client_PlotData) do
if object.Coordinates[1] == Xcoord and object.Coordinates[2] == Ycoord and object.Coordinates[3] == Zcoord then
return object
end
end
return nil
end
local BlockSides = {["front"]={0,0,1},["back"]={0,0,-1},["left"]={-1,0,0},["right"]={1,0,0},["top"]={0,1,0},["bottom"]={0,-1,0}}
local function getside(Coords)
for i,v in pairs(BlockSides) do
for a,b in pairs(Coords) do
if v[a] == b then
return i
end
end
end
return nil
end
local function AirCheck(Item)
local sidesBlocked = {["front"]=false,["back"]=false,["left"]=false,["right"]=false,["top"]=false,["bottom"]=false}
local function Check(dim, index)
if index == 2 then return end
local coordtable = {[1]=Item.Coordinates[1],[2]=Item.Coordinates[2],[3]=Item.Coordinates[3]}
coordtable[dim] = coordtable[dim] + index
if getBlockAt(coordtable) ~= nil then
if getside(coordtable) then
sidesBlocked[getside(coordtable)] = true
end
end
end
for XBlock = -1,1 do
Check(1, XBlock)
end
for YBlock = -1,1 do
Check(2, YBlock)
end
for ZBlock = -1,1 do
Check(3, ZBlock)
end
return sidesBlocked
end
local function CheckIfHide(BlockedSides)
--print(BlockedSides)
local trues = 0
for i,v in pairs(BlockedSides) do
if v == true then
trues += 1
end
end
print(BlockedSides, trues)
return trues > 6 --All sides
end
--until here
local function addItem(Coords, Item)
local Xcoord, Ycoord, Zcoord = Coords.x, Coords.y, Coords.z
local NewObject = getItemData(Item)["Model"]:Clone()
NewObject:PivotTo(CFrame.new(Vector3.new(2*Xcoord,2*Ycoord,2*Zcoord)))
local NewData = {itemName = Item, Model = NewObject, Coordinates = {Xcoord, Ycoord, Zcoord}}
table.insert(Client_PlotData,NewData)
NewObject.Parent = workspace.Items
local AirCheckTest = AirCheck(NewData)
if CheckIfHide(AirCheckTest) == true then
for i,v in pairs(NewData.Model:GetDescendants()) do
if v.Name ~= "BoundingBox" then
if v:IsA("Part") then
v.Transparency = 0
end
end
end
else
for i,v in pairs(NewData.Model:GetDescendants()) do
if v.Name ~= "BoundingBox" then
if v:IsA("Part") then
v.Transparency = 1
end
end
end
end
return NewData
end
--basic generation
for X = 1,10 do
for Z = 1,10 do
for Y = 1,10 do
addItem({x=X,y=Y,z=Z}, (Y>9) and "Grass" or "Dirt")
end
end
end
Any help is appreciated!