Minecraft-like Roblox block game rblx.games/135624152691584
roblox roblox-game rojo

placement: fix selection box

+39 -10
+39 -10
src/ReplicatedStorage/Shared/PlacementManager.lua
··· 26 26 raycastParams.FilterType = Enum.RaycastFilterType.Include 27 27 raycastParams.IgnoreWater = true 28 28 29 + local Mouse: Mouse = nil 30 + local lastNormalId: Enum.NormalId? = nil 31 + local lastRaycastFailure: string? = nil 32 + local lastSelectedChunkKey: string? = nil 33 + local lastSelectedBlockKey: string? = nil 34 + local BREAK_ROLLBACK_TIMEOUT = 0.6 35 + local pendingBreaks = {} 36 + local clearSelection 37 + 29 38 if _G.__BLOCKSCRAFT_PLACEMENT_MANAGER then 30 39 return _G.__BLOCKSCRAFT_PLACEMENT_MANAGER 31 40 end ··· 35 44 PlacementManager.SelectionBox.Name = "$SelectionBox"..(game:GetService("RunService"):IsServer() and "_SERVER" or "") 36 45 PlacementManager.SelectionBox.Parent = game:GetService("Workspace"):FindFirstChildOfClass("Terrain") 37 46 PlacementManager.SelectionBox.Adornee = nil 47 + PlacementManager.SelectionBox:GetPropertyChangedSignal("Adornee"):Connect(function() 48 + local adornee = PlacementManager.SelectionBox.Adornee 49 + if not adornee then 50 + return 51 + end 52 + adornee.AncestryChanged:Connect(function(_, parent) 53 + if not parent then 54 + clearSelection("adornee destroyed") 55 + end 56 + end) 57 + end) 38 58 39 59 -- Trash method TODO: Fix this 40 60 local function findChunkFolderFromDescendant(inst: Instance): Instance? ··· 71 91 return chunkInst:FindFirstChild(blockName) 72 92 end 73 93 74 - local function clearSelection(reason: string?) 94 + clearSelection = function(reason: string?) 75 95 PlacementManager.SelectionBox.Adornee = nil 76 96 PlacementManager.SelectionBox.Parent = nil 77 97 lastNormalId = nil 98 + lastSelectedChunkKey = nil 99 + lastSelectedBlockKey = nil 78 100 if reason then 79 101 lastRaycastFailure = reason 80 102 end ··· 105 127 return nil, nil 106 128 end 107 129 108 - local Mouse: Mouse = nil 109 - local lastNormalId: Enum.NormalId? = nil 110 - local BREAK_ROLLBACK_TIMEOUT = 0.6 111 - local pendingBreaks = {} 112 - local lastRaycastFailure: string? = nil 113 130 local function vectorToNormalId(normal: Vector3): Enum.NormalId 114 131 local ax, ay, az = math.abs(normal.X), math.abs(normal.Y), math.abs(normal.Z) 115 132 if ax >= ay and ax >= az then ··· 324 341 script.RaycastResult.Value = nil 325 342 return 326 343 end 344 + local chunkKey = makeChunkKey(chunkCoords.X, chunkCoords.Y, chunkCoords.Z) 345 + local blockKey = makeBlockKey(blockCoords.X, blockCoords.Y, blockCoords.Z) 346 + 347 + -- block is being optimistically broken, do not highlight it 348 + if getPendingBreak(chunkKey, blockKey) then 349 + clearSelection("block pending break") 350 + script.RaycastResult.Value = nil 351 + return 352 + end 327 353 328 354 -- hide selection if block no longer exists (air/removed) 329 355 local chunk = ChunkManager:GetChunk(chunkCoords.X, chunkCoords.Y, chunkCoords.Z) ··· 341 367 end 342 368 343 369 lastRaycastFailure = nil 344 - setSelection(blockInstance, PlacementManager.ChunkFolder) 370 + if lastSelectedChunkKey ~= chunkKey or lastSelectedBlockKey ~= blockKey then 371 + setSelection(blockInstance, PlacementManager.ChunkFolder) 372 + lastSelectedChunkKey = chunkKey 373 + lastSelectedBlockKey = blockKey 374 + end 345 375 script.RaycastResult.Value = objLookingAt 346 376 lastNormalId = vectorToNormalId(result.Normal) 347 377 debugPlacementLog( ··· 520 550 local selectedPart = PlacementManager:RaycastGetResult() 521 551 --print(selectedPart and selectedPart:GetFullName() or nil) 522 552 if selectedPart == nil then 523 - PlacementManager.SelectionBox.Adornee = nil 553 + clearSelection() 524 554 script.RaycastResult.Value = nil 525 - lastNormalId = nil 526 555 debugPlacementLog("[PLACE][CLIENT][TARGET]", "no selectedPart after raycast", lastRaycastFailure) 527 556 return nil 528 557 end ··· 624 653 PlacementManager:Raycast() 625 654 end) 626 655 if not a then 627 - PlacementManager.SelectionBox.Adornee = nil 656 + clearSelection("raycast error") 628 657 script.RaycastResult.Value = nil 629 658 end 630 659 end)