core: impovements
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
--!native
|
||||
--!optimize 2
|
||||
|
||||
print("Hello world!")
|
||||
|
||||
task.synchronize()
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
@@ -13,6 +11,7 @@ local ModsFolder = ReplicatedStorage:WaitForChild("Mods")
|
||||
|
||||
local Util = require(Shared.Util)
|
||||
local TG = require("./ServerChunkManager/TerrainGen")
|
||||
local Players = game:GetService("Players")
|
||||
|
||||
do
|
||||
local workspaceModFolder = game:GetService("Workspace"):WaitForChild("mods")
|
||||
@@ -127,6 +126,22 @@ local function getServerChunk(cx: number, cy: number, cz: number)
|
||||
return chunk
|
||||
end
|
||||
|
||||
local function isBlockInsidePlayer(blockPos: Vector3): boolean
|
||||
for _, player in ipairs(Players:GetPlayers()) do
|
||||
local character = player.Character
|
||||
if character then
|
||||
local cf, size = character:GetBoundingBox()
|
||||
local localPos = cf:PointToObjectSpace(blockPos)
|
||||
if math.abs(localPos.X) <= size.X * 0.5
|
||||
and math.abs(localPos.Y) <= size.Y * 0.5
|
||||
and math.abs(localPos.Z) <= size.Z * 0.5 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
placeRemote.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z, blockId)
|
||||
--print("place",player, cx, cy, cz, x, y, z, blockData)
|
||||
|
||||
@@ -150,6 +165,11 @@ placeRemote.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z, blockId)
|
||||
return
|
||||
end
|
||||
|
||||
local blockPos = Util.ChunkPosToCFrame(Vector3.new(cx, cy, cz), Vector3.new(x, y, z)).Position
|
||||
if isBlockInsidePlayer(blockPos) then
|
||||
return
|
||||
end
|
||||
|
||||
local chunk = getServerChunk(cx, cy, cz)
|
||||
if chunk:GetBlockAt(x, y, z) then
|
||||
return
|
||||
@@ -163,41 +183,31 @@ placeRemote.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z, blockId)
|
||||
end)
|
||||
|
||||
breakRemote.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z)
|
||||
print("[DEBUG] Server breakRemote received - Player:", player.Name, "Chunk:", cx, cy, cz, "Block:", x, y, z)
|
||||
|
||||
if typeof(cx) ~= "number" or typeof(cy) ~= "number" or typeof(cz) ~= "number" then
|
||||
print("[DEBUG] Invalid chunk coordinate types")
|
||||
return
|
||||
end
|
||||
if typeof(x) ~= "number" or typeof(y) ~= "number" or typeof(z) ~= "number" then
|
||||
print("[DEBUG] Invalid block coordinate types")
|
||||
return
|
||||
end
|
||||
if x < 1 or x > 8 or y < 1 or y > 8 or z < 1 or z > 8 then
|
||||
print("[DEBUG] Block coordinates out of range:", x, y, z)
|
||||
return
|
||||
end
|
||||
if math.abs(cx) > MAX_CHUNK_DIST or math.abs(cy) > MAX_CHUNK_DIST or math.abs(cz) > MAX_CHUNK_DIST then
|
||||
print("[DEBUG] Chunk coordinates out of range:", cx, cy, cz)
|
||||
return
|
||||
end
|
||||
if not isWithinReach(player, cx, cy, cz, x, y, z) then
|
||||
print("[DEBUG] Block not within player reach")
|
||||
return
|
||||
end
|
||||
|
||||
local chunk = getServerChunk(cx, cy, cz)
|
||||
if not chunk:GetBlockAt(x, y, z) then
|
||||
print("[DEBUG] No block found at specified location")
|
||||
task.synchronize()
|
||||
tickRemote:FireClient(player, "C_R", cx, cy, cz, 0, 0, 0, 0)
|
||||
task.desynchronize()
|
||||
return
|
||||
end
|
||||
print("[DEBUG] All validations passed, removing block")
|
||||
chunk:RemoveBlock(x, y, z)
|
||||
propogate("B_D", cx, cy, cz, x, y, z, 0)
|
||||
print("[DEBUG] Block removal propagated to clients")
|
||||
end)
|
||||
|
||||
task.desynchronize()
|
||||
|
||||
Reference in New Issue
Block a user