codex: stuff
This commit is contained in:
7
src/ReplicatedStorage/Remotes/BreakBlock.rbxmx
Normal file
7
src/ReplicatedStorage/Remotes/BreakBlock.rbxmx
Normal file
@@ -0,0 +1,7 @@
|
||||
<roblox version="4">
|
||||
<Item class="RemoteEvent" referent="RBX0D1D3E8A8F5C4B0B9F0B123E18E5D6A2">
|
||||
<Properties>
|
||||
<string name="Name">BreakBlock</string>
|
||||
</Properties>
|
||||
</Item>
|
||||
</roblox>
|
||||
7
src/ReplicatedStorage/Remotes/PlaceBlock.rbxmx
Normal file
7
src/ReplicatedStorage/Remotes/PlaceBlock.rbxmx
Normal file
@@ -0,0 +1,7 @@
|
||||
<roblox version="4">
|
||||
<Item class="RemoteEvent" referent="RBX3F7B7B3E7E5C4D8B9A9B3D8C76E8C0A1">
|
||||
<Properties>
|
||||
<string name="Name">PlaceBlock</string>
|
||||
</Properties>
|
||||
</Item>
|
||||
</roblox>
|
||||
4
src/ReplicatedStorage/Remotes/init.meta.json
Normal file
4
src/ReplicatedStorage/Remotes/init.meta.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"className": "Folder",
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
@@ -39,17 +39,20 @@ local function propogateNeighboringBlockChanges(cx, cy, cz, x, y, z)
|
||||
local d = c.data[`{x},{y},{z}`]
|
||||
if not d then return end
|
||||
|
||||
task.synchronize()
|
||||
|
||||
if c:IsBlockRenderable(x, y, z) then
|
||||
if c.instance:FindFirstChild(`{x},{y},{z}`) then return end
|
||||
task.synchronize()
|
||||
local block = BlockManager:GetBlockRotated(d.id, util.RotationStringToNormalId(d.state["r"] or "f"), d.state)
|
||||
block.Name = `{x},{y},{z}`
|
||||
block:PivotTo(util.ChunkPosToCFrame(c.pos, Vector3.new(x, y, z)))
|
||||
block.Parent = c.instance
|
||||
task.desynchronize()
|
||||
else
|
||||
if c.instance:FindFirstChild(`{x},{y},{z}`) then
|
||||
c.instance:FindFirstChild(`{x},{y},{z}`):Destroy()
|
||||
local existing = c.instance:FindFirstChild(`{x},{y},{z}`)
|
||||
if existing then
|
||||
task.synchronize()
|
||||
existing:Destroy()
|
||||
task.desynchronize()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,6 +28,55 @@ local function findParent(i: Instance): Instance
|
||||
end
|
||||
|
||||
local Mouse: Mouse = nil
|
||||
local lastNormalId: Enum.NormalId? = nil
|
||||
|
||||
local function normalIdToOffset(normal: Enum.NormalId): Vector3
|
||||
if normal == Enum.NormalId.Top then
|
||||
return Vector3.new(0, 1, 0)
|
||||
elseif normal == Enum.NormalId.Bottom then
|
||||
return Vector3.new(0, -1, 0)
|
||||
elseif normal == Enum.NormalId.Left then
|
||||
return Vector3.new(-1, 0, 0)
|
||||
elseif normal == Enum.NormalId.Right then
|
||||
return Vector3.new(1, 0, 0)
|
||||
elseif normal == Enum.NormalId.Back then
|
||||
return Vector3.new(0, 0, 1)
|
||||
elseif normal == Enum.NormalId.Front then
|
||||
return Vector3.new(0, 0, -1)
|
||||
end
|
||||
return Vector3.new(0, 0, 0)
|
||||
end
|
||||
|
||||
local function offsetChunkBlock(chunk: Vector3, block: Vector3, offset: Vector3)
|
||||
local cx, cy, cz = chunk.X, chunk.Y, chunk.Z
|
||||
local bx, by, bz = block.X + offset.X, block.Y + offset.Y, block.Z + offset.Z
|
||||
|
||||
if bx < 1 then
|
||||
bx = 8
|
||||
cx -= 1
|
||||
elseif bx > 8 then
|
||||
bx = 1
|
||||
cx += 1
|
||||
end
|
||||
|
||||
if by < 1 then
|
||||
by = 8
|
||||
cy -= 1
|
||||
elseif by > 8 then
|
||||
by = 1
|
||||
cy += 1
|
||||
end
|
||||
|
||||
if bz < 1 then
|
||||
bz = 8
|
||||
cz -= 1
|
||||
elseif bz > 8 then
|
||||
bz = 1
|
||||
cz += 1
|
||||
end
|
||||
|
||||
return Vector3.new(cx, cy, cz), Vector3.new(bx, by, bz)
|
||||
end
|
||||
|
||||
-- Gets the block and normalid of the block (and surface) the player is looking at
|
||||
function PlacementManager:Raycast()
|
||||
@@ -40,6 +89,7 @@ function PlacementManager:Raycast()
|
||||
if not objLookingAt then
|
||||
PlacementManager.SelectionBox.Adornee = nil
|
||||
script.RaycastResult.Value = nil
|
||||
lastNormalId = nil
|
||||
return
|
||||
end
|
||||
|
||||
@@ -48,10 +98,12 @@ function PlacementManager:Raycast()
|
||||
if parent:GetAttribute("ns") == true then
|
||||
PlacementManager.SelectionBox.Adornee = nil
|
||||
script.RaycastResult.Value = nil
|
||||
lastNormalId = nil
|
||||
return
|
||||
end
|
||||
PlacementManager.SelectionBox.Adornee = parent
|
||||
script.RaycastResult.Value = parent
|
||||
lastNormalId = dir
|
||||
return parent, dir
|
||||
end
|
||||
|
||||
@@ -59,16 +111,17 @@ function PlacementManager:RaycastGetResult()
|
||||
return script.RaycastResult.Value
|
||||
end
|
||||
|
||||
local placeRemote = game:GetService("ReplicatedStorage").PlaceBlock
|
||||
local breakRemote = game:GetService("ReplicatedStorage").BreakBlock
|
||||
local remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
|
||||
local placeRemote = remotes:WaitForChild("PlaceBlock")
|
||||
local breakRemote = remotes:WaitForChild("BreakBlock")
|
||||
local tickRemote = game:GetService("ReplicatedStorage").Tick
|
||||
|
||||
-- FIRES REMOTE
|
||||
function PlacementManager:PlaceBlock(cx, cy, cz, x, y, z, blockData)
|
||||
function PlacementManager:PlaceBlock(cx, cy, cz, x, y, z, blockId: string)
|
||||
--print("placeblock")
|
||||
--local chunk = ChunkManager:GetChunk(cx, cy, cz)
|
||||
--chunk:CreateBlock(x, y, z, blockData)
|
||||
placeRemote:FireServer(cx, cy, cz, x, y, z, blockData)
|
||||
placeRemote:FireServer(cx, cy, cz, x, y, z, blockId)
|
||||
end
|
||||
|
||||
-- FIRES REMOTE
|
||||
@@ -97,11 +150,13 @@ function PlacementManager:GetBlockAtMouse(): nil | {chunk:Vector3, block: Vector
|
||||
if selectedPart == nil then
|
||||
PlacementManager.SelectionBox.Adornee = nil
|
||||
script.RaycastResult.Value = nil
|
||||
lastNormalId = nil
|
||||
return nil
|
||||
end
|
||||
if not selectedPart.Parent then
|
||||
PlacementManager.SelectionBox.Adornee = nil
|
||||
script.RaycastResult.Value = nil
|
||||
lastNormalId = nil
|
||||
return nil
|
||||
end
|
||||
local chunkCoords = Util.BlockPosStringToCoords(selectedPart.Parent.Name)
|
||||
@@ -114,6 +169,32 @@ function PlacementManager:GetBlockAtMouse(): nil | {chunk:Vector3, block: Vector
|
||||
|
||||
end
|
||||
|
||||
function PlacementManager:GetTargetAtMouse(): nil | {chunk:Vector3, block: Vector3, normal: Enum.NormalId}
|
||||
local hit = PlacementManager:GetBlockAtMouse()
|
||||
if not hit or not lastNormalId then
|
||||
return nil
|
||||
end
|
||||
|
||||
return {
|
||||
chunk = hit.chunk,
|
||||
block = hit.block,
|
||||
normal = lastNormalId
|
||||
}
|
||||
end
|
||||
|
||||
function PlacementManager:GetPlacementAtMouse(): nil | {chunk:Vector3, block: Vector3}
|
||||
local hit = PlacementManager:GetTargetAtMouse()
|
||||
if not hit then
|
||||
return nil
|
||||
end
|
||||
local offset = normalIdToOffset(hit.normal)
|
||||
local placeChunk, placeBlock = offsetChunkBlock(hit.chunk, hit.block, offset)
|
||||
return {
|
||||
chunk = placeChunk,
|
||||
block = placeBlock
|
||||
}
|
||||
end
|
||||
|
||||
function PlacementManager:Init()
|
||||
game:GetService("RunService").Heartbeat:Connect(function()
|
||||
local a,b = pcall(function()
|
||||
|
||||
Reference in New Issue
Block a user