core: broken

This commit is contained in:
2026-01-07 22:51:11 +02:00
parent a9da63e90e
commit 165913ca51
13 changed files with 582 additions and 217 deletions

View File

@@ -1,8 +1,6 @@
--!native
--!optimize 2
task.synchronize()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
@@ -76,7 +74,7 @@ local function propogate(a, cx, cy, cz, x, y, z, bd)
task.desynchronize()
end
local MAX_REACH = 24
local MAX_REACH = 512
local blockIdMap = {}
local function rebuildBlockIdMap()
@@ -107,12 +105,8 @@ local function getPlayerPosition(player: Player): Vector3?
end
local function isWithinReach(player: Player, cx: number, cy: number, cz: number, x: number, y: number, z: number): boolean
local playerPos = getPlayerPosition(player)
if not playerPos then
return false
end
local blockPos = Util.ChunkPosToCFrame(Vector3.new(cx, cy, cz), Vector3.new(x, y, z)).Position
return (blockPos - playerPos).Magnitude <= MAX_REACH
-- Relaxed reach; always true unless you want to re-enable limits
return true
end
local function resolveBlockId(blockId: any): string | number | nil
@@ -126,6 +120,8 @@ local function getServerChunk(cx: number, cy: number, cz: number)
return chunk
end
-- local PLAYER_BOX_SIZE = Vector3.new(3, 6, 3)
local function isBlockInsidePlayer(blockPos: Vector3): boolean
for _, player in ipairs(Players:GetPlayers()) do
local character = player.Character
@@ -142,37 +138,53 @@ local function isBlockInsidePlayer(blockPos: Vector3): boolean
return false
end
local DEBUG_PLACEMENT = true
placeRemote.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z, blockId)
--print("place",player, cx, cy, cz, x, y, z, blockData)
local function reject(reason: string)
if DEBUG_PLACEMENT then
warn("[PLACE][REJECT]", player.Name, reason, "chunk", cx, cy, cz, "block", x, y, z, "id", blockId)
end
return
end
if typeof(cx) ~= "number" or typeof(cy) ~= "number" or typeof(cz) ~= "number" then
return
return reject("chunk types")
end
if typeof(x) ~= "number" or typeof(y) ~= "number" or typeof(z) ~= "number" then
return
return reject("block types")
end
if x < 1 or x > 8 or y < 1 or y > 8 or z < 1 or z > 8 then
return
return reject("block bounds")
end
if math.abs(cx) > MAX_CHUNK_DIST or math.abs(cy) > MAX_CHUNK_DIST or math.abs(cz) > MAX_CHUNK_DIST then
--return
return reject("chunk bounds")
end
if not isWithinReach(player, cx, cy, cz, x, y, z) then
return
return reject("out of reach")
end
local resolvedId = resolveBlockId(blockId)
if not resolvedId then
return
return reject("invalid id")
end
local blockPos = Util.ChunkPosToCFrame(Vector3.new(cx, cy, cz), Vector3.new(x, y, z)).Position
if isBlockInsidePlayer(blockPos) then
return
return reject("inside player")
end
local chunk = getServerChunk(cx, cy, cz)
if chunk:GetBlockAt(x, y, z) then
return
local existing = chunk:GetBlockAt(x, y, z)
if existing and existing.id and existing.id ~= 0 then
if existing.id == resolvedId then
-- same block already there; treat as success without changes
if DEBUG_PLACEMENT then
print("[PLACE][OK][NOOP]", player.Name, "chunk", cx, cy, cz, "block", x, y, z, "id", resolvedId)
end
return
end
-- allow replacement when different id: remove then place
chunk:RemoveBlock(x, y, z)
end
local data = {
id = resolvedId,
@@ -180,6 +192,9 @@ placeRemote.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z, blockId)
}
chunk:CreateBlock(x, y, z, data)
propogate("B_C", cx, cy, cz, x, y, z, data)
if DEBUG_PLACEMENT then
print("[PLACE][OK]", player.Name, "chunk", cx, cy, cz, "block", x, y, z, "id", resolvedId)
end
end)
breakRemote.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z)