chore: init from rojo-to-rbxlx
This commit is contained in:
35
default.project.json
Normal file
35
default.project.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "project",
|
||||
"tree": {
|
||||
"$className": "DataModel",
|
||||
"ReplicatedStorage": {
|
||||
"$className": "ReplicatedStorage",
|
||||
"$ignoreUnknownInstances": true,
|
||||
"$path": "src/ReplicatedStorage"
|
||||
},
|
||||
"ServerScriptService": {
|
||||
"$className": "ServerScriptService",
|
||||
"$ignoreUnknownInstances": true,
|
||||
"$path": "src/ServerScriptService"
|
||||
},
|
||||
"StarterGui": {
|
||||
"$className": "StarterGui",
|
||||
"$ignoreUnknownInstances": true,
|
||||
"$path": "src/StarterGui"
|
||||
},
|
||||
"StarterPlayer": {
|
||||
"$className": "StarterPlayer",
|
||||
"StarterPlayerScripts": {
|
||||
"$className": "StarterPlayerScripts",
|
||||
"$ignoreUnknownInstances": true,
|
||||
"$path": "src/StarterPlayer/StarterPlayerScripts"
|
||||
},
|
||||
"$ignoreUnknownInstances": true
|
||||
},
|
||||
"Workspace": {
|
||||
"$className": "Workspace",
|
||||
"$ignoreUnknownInstances": true,
|
||||
"$path": "src/Workspace"
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
place.rbxl
Normal file
BIN
place.rbxl
Normal file
Binary file not shown.
5
place.rbxl.lock
Normal file
5
place.rbxl.lock
Normal file
@@ -0,0 +1,5 @@
|
||||
292
|
||||
RobloxStudioBeta
|
||||
CACHYOS
|
||||
3ad4fa05-1765-4ae8-a484-86d03d176c98
|
||||
|
||||
86
src/ReplicatedStorage/Shared/ChunkManager/BlockManager.lua
Normal file
86
src/ReplicatedStorage/Shared/ChunkManager/BlockManager.lua
Normal file
@@ -0,0 +1,86 @@
|
||||
local BlockManager = {}
|
||||
|
||||
BlockManager.BlockIdMappings = {} :: {BasePart}
|
||||
|
||||
for i,v in pairs(game:GetService("ReplicatedStorage"):WaitForChild("Blocks"):GetChildren()) do
|
||||
BlockManager.BlockIdMappings[v:GetAttribute("n")] = v
|
||||
end
|
||||
|
||||
BlockManager.UpdateIdMappings = {} :: {BasePart}
|
||||
|
||||
for i,v in pairs(game:GetService("ReplicatedStorage"):WaitForChild("BlockUpdateOperations"):GetChildren()) do
|
||||
local success, reason = pcall(function()
|
||||
BlockManager.UpdateIdMappings[v:GetAttribute("n")] = require(v)
|
||||
end)
|
||||
if not success then
|
||||
warn("[BLOCKMANAGER] Invalid update operation",v:GetAttribute("n"),":",reason)
|
||||
end
|
||||
end
|
||||
|
||||
local warnedBlockIds = {}
|
||||
|
||||
function BlockManager:GetBlock(blockId: number, attr: {[typeof("")]: any}?)
|
||||
|
||||
task.synchronize()
|
||||
|
||||
if not BlockManager.BlockIdMappings[blockId] then
|
||||
if not warnedBlockIds[blockId] then
|
||||
warnedBlockIds[blockId] = true
|
||||
warn("[BLOCKMANAGER] Invalid block id",blockId)
|
||||
end
|
||||
return script.invalid:Clone()
|
||||
end
|
||||
|
||||
local b = BlockManager.BlockIdMappings[blockId]:Clone()
|
||||
b.Size = Vector3.new(3.95,3.95,3.95)
|
||||
|
||||
for i,v in pairs(attr or {}) do
|
||||
b:SetAttribute(i,v)
|
||||
end
|
||||
|
||||
if BlockManager.UpdateIdMappings[blockId] then
|
||||
local success, reason = pcall(function()
|
||||
BlockManager.UpdateIdMappings[blockId](b)
|
||||
end)
|
||||
if not success then
|
||||
warn("[BLOCKMANAGER] Failed update operation",blockId,":",reason)
|
||||
end
|
||||
end
|
||||
|
||||
return b
|
||||
end
|
||||
|
||||
-- ChatGPT Generated Func!!!!
|
||||
function BlockManager:GetBlockRotated(blockId: number, face: Enum.NormalId, attr: {[typeof("")]: any}?)
|
||||
-- Returns block with id blockId, rotated so the given face (NormalId) points north (+X).
|
||||
local block = BlockManager:GetBlock(blockId, attr)
|
||||
local rot = CFrame.new()
|
||||
|
||||
task.synchronize()
|
||||
|
||||
if face == Enum.NormalId.Front then
|
||||
rot = CFrame.Angles(0, 0, 0) -- no rot
|
||||
elseif face == Enum.NormalId.Back then
|
||||
rot = CFrame.Angles(0, math.rad(180), 0)
|
||||
elseif face == Enum.NormalId.Left then
|
||||
rot = CFrame.Angles(0, math.rad(90), 0)
|
||||
elseif face == Enum.NormalId.Right then
|
||||
rot = CFrame.Angles(0, math.rad(-90), 0)
|
||||
elseif face == Enum.NormalId.Top then
|
||||
rot = CFrame.Angles(math.rad(-90), 0, 0) -- top +x
|
||||
elseif face == Enum.NormalId.Bottom then
|
||||
rot = CFrame.Angles(math.rad(90), 0, 0) -- bottom +x
|
||||
end
|
||||
|
||||
|
||||
-- ocbwoy3's fix
|
||||
block:PivotTo(rot)
|
||||
block.CFrame = CFrame.new(rot.Position)
|
||||
|
||||
return block
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
return BlockManager
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
180
src/ReplicatedStorage/Shared/ChunkManager/Chunk.lua
Normal file
180
src/ReplicatedStorage/Shared/ChunkManager/Chunk.lua
Normal file
@@ -0,0 +1,180 @@
|
||||
local Chunk = {}
|
||||
Chunk.__index = Chunk
|
||||
|
||||
Chunk.UpdateBlockBindable = Instance.new("BindableEvent") :: BindableEvent
|
||||
|
||||
Chunk.AllChunks = {} :: {[typeof("")]: typeof(Chunk.new(0,0,0))}
|
||||
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local function Swait(l)
|
||||
for i = 1,l do
|
||||
RunService.Stepped:Wait()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
export type BlockData = {
|
||||
id: number,
|
||||
state: {
|
||||
[typeof("")]: string | boolean | number
|
||||
}
|
||||
}
|
||||
|
||||
function Chunk.new(x,y,z)
|
||||
local self = setmetatable({}, Chunk)
|
||||
self.pos = Vector3.new(x,y,z)
|
||||
|
||||
-- Tick ONLY in a 5 chunk distance of LP's char
|
||||
self.inhabitedTime = tick()
|
||||
self.instance = Instance.new("Folder")
|
||||
self.unloadChunkHook = function() end
|
||||
self.UpdateBlockBindableL = Instance.new("BindableEvent") :: BindableEvent
|
||||
|
||||
self.loaded = false
|
||||
self.loading = false
|
||||
|
||||
self.data = {} :: {[typeof("")]: BlockData} -- "X,Y,Z": BlockData ("-1,-1,1": BlockData)
|
||||
return self
|
||||
end
|
||||
|
||||
function Chunk.from(x,y,z,data)
|
||||
local self = setmetatable({}, Chunk)
|
||||
self.pos = Vector3.new(x,y,z)
|
||||
|
||||
-- Tick ONLY in a 5 chunk distance of LP's char
|
||||
self.inhabitedTime = tick()
|
||||
self.instance = Instance.new("Folder")
|
||||
self.unloadChunkHook = function() end
|
||||
self.UpdateBlockBindableL = Instance.new("BindableEvent") :: BindableEvent
|
||||
|
||||
self.data = data :: {[typeof("")]: BlockData} -- "X,Y,Z": BlockData ("-1,-1,1": BlockData)
|
||||
return self
|
||||
end
|
||||
|
||||
function Chunk:DoesNeighboringBlockExist(rx, ry, rz, gx, gy, gz, offsetX, offsetY, offsetZ)
|
||||
task.desynchronize()
|
||||
-- Calculate the local position of the neighboring block
|
||||
local neighborRX, neighborRY, neighborRZ = rx + offsetX, ry + offsetY, rz + offsetZ
|
||||
local neighborGX, neighborGY, neighborGZ = gx, gy, gz
|
||||
|
||||
-- Adjust for chunk boundaries
|
||||
if neighborRX < 1 then
|
||||
neighborRX = 8
|
||||
neighborGX = gx - 1
|
||||
elseif neighborRX > 8 then
|
||||
neighborRX = 1
|
||||
neighborGX = gx + 1
|
||||
end
|
||||
|
||||
if neighborRY < 1 then
|
||||
neighborRY = 8
|
||||
neighborGY = gy - 1
|
||||
elseif neighborRY > 8 then
|
||||
neighborRY = 1
|
||||
neighborGY = gy + 1
|
||||
end
|
||||
|
||||
if neighborRZ < 1 then
|
||||
neighborRZ = 8
|
||||
neighborGZ = gz - 1
|
||||
elseif neighborRZ > 8 then
|
||||
neighborRZ = 1
|
||||
neighborGZ = gz + 1
|
||||
end
|
||||
|
||||
if neighborGY < 0 then
|
||||
return true
|
||||
end
|
||||
|
||||
-- Get the neighboring chunk
|
||||
local neighborChunk = Chunk.AllChunks[`{neighborGX},{neighborGY},{neighborGZ}`]
|
||||
if not neighborChunk then
|
||||
return true -- Assume block exists in an unloaded chunk
|
||||
end
|
||||
|
||||
-- Check if the block exists in the neighboring chunk
|
||||
return neighborChunk:GetBlockAt(neighborRX, neighborRY, neighborRZ) ~= nil
|
||||
end
|
||||
|
||||
function Chunk:IsBlockRenderable(rx, ry, rz)
|
||||
task.desynchronize()
|
||||
local gx, gy, gz = self.pos.X, self.pos.Y, self.pos.Z
|
||||
-- Check all six neighboring blocks
|
||||
local d = not (
|
||||
self:DoesNeighboringBlockExist(rx, ry, rz, gx, gy, gz, 1, 0, 0) and
|
||||
self:DoesNeighboringBlockExist(rx, ry, rz, gx, gy, gz, -1, 0, 0) and
|
||||
self:DoesNeighboringBlockExist(rx, ry, rz, gx, gy, gz, 0, 1, 0) and
|
||||
self:DoesNeighboringBlockExist(rx, ry, rz, gx, gy, gz, 0, -1, 0) and
|
||||
self:DoesNeighboringBlockExist(rx, ry, rz, gx, gy, gz, 0, 0, 1) and
|
||||
self:DoesNeighboringBlockExist(rx, ry, rz, gx, gy, gz, 0, 0, -1)
|
||||
)
|
||||
return d
|
||||
end
|
||||
|
||||
|
||||
function Chunk:Tick()
|
||||
self.inhabitedTime = tick()
|
||||
end
|
||||
|
||||
function Chunk:PropogateChanges(x: number,y: number,z: number,d:BlockData)
|
||||
self.UpdateBlockBindableL:Fire(x,y,z,d)
|
||||
end
|
||||
|
||||
function Chunk:GetBlockAt(x,y,z)
|
||||
task.desynchronize()
|
||||
if not self.data[`{tostring(x)},{tostring(y)},{tostring(z)}`] then
|
||||
return nil
|
||||
end
|
||||
return self.data[`{tostring(x)},{tostring(y)},{tostring(z)}`]
|
||||
end
|
||||
|
||||
function Chunk:CreateBlock(x: number,y: number,z: number,d:BlockData)
|
||||
self.data[`{tostring(x)},{tostring(y)},{tostring(z)}`] = d
|
||||
self:PropogateChanges(x,y,z,d)
|
||||
return self:GetBlockAt(x,y,z)
|
||||
end
|
||||
|
||||
function Chunk:RemoveBlock(x, y, z)
|
||||
self.data[x .. "," .. y .. "," .. z] = nil
|
||||
self:PropogateChanges(x,y,z,0)
|
||||
end
|
||||
|
||||
function Chunk:Load()
|
||||
local i = sel
|
||||
end
|
||||
|
||||
function Chunk:Unload()
|
||||
|
||||
task.synchronize()
|
||||
self.loaded = false
|
||||
|
||||
-- SLOWCLEAR
|
||||
|
||||
task.defer(function()
|
||||
local g = 0
|
||||
for _,v in pairs(self.instance:GetChildren()) do
|
||||
pcall(function()
|
||||
v:Destroy()
|
||||
end)
|
||||
g += 1
|
||||
if g == 30 then
|
||||
g = 0
|
||||
Swait(2)
|
||||
end
|
||||
end
|
||||
|
||||
task.synchronize()
|
||||
self.instance.Parent = nil
|
||||
self.instance:Destroy()
|
||||
self.unloadChunkHook()
|
||||
task.desynchronize()
|
||||
end)
|
||||
end
|
||||
|
||||
-- DO NOT INTERACT WITH CHUNK AFTER CALLING THIS
|
||||
function Chunk:Destroy()
|
||||
self.data = {}
|
||||
end
|
||||
|
||||
return Chunk :: typeof(Chunk)
|
||||
227
src/ReplicatedStorage/Shared/ChunkManager/ChunkBuilder.lua
Normal file
227
src/ReplicatedStorage/Shared/ChunkManager/ChunkBuilder.lua
Normal file
@@ -0,0 +1,227 @@
|
||||
local ChunkBuilder = {}
|
||||
|
||||
local Chunk = require("./Chunk")
|
||||
local BlockManager = require("./BlockManager")
|
||||
local util = require("../Util")
|
||||
|
||||
local objects = script.Parent.Parent.Parent.Objects
|
||||
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local ChunkBorderFolder = game:GetService("Workspace"):FindFirstChildOfClass("Terrain")
|
||||
|
||||
local function placeBorder(a,b,c)
|
||||
local pos = util.ChunkPosToCFrame(Vector3.new(a,b,c),Vector3.new(1,1,1)).Position - Vector3.new(2,2,2)
|
||||
local d = objects.ChunkLoading:Clone()
|
||||
d:PivotTo(CFrame.new(pos))
|
||||
d.Parent = ChunkBorderFolder
|
||||
return d
|
||||
end
|
||||
|
||||
local function Swait(l)
|
||||
for i = 1,l do
|
||||
RunService.Stepped:Wait()
|
||||
end
|
||||
end
|
||||
|
||||
local function propogateNeighboringBlockChanges(cx, cy, cz, x, y, z)
|
||||
--warn("propogateNeighboringBlockChanges",cx,cy,cz,x,y,z)
|
||||
-- updates block in another chunk
|
||||
local c = Chunk.AllChunks[`{cx},{cy},{cz}`]
|
||||
if not c then return end
|
||||
|
||||
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
|
||||
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
|
||||
else
|
||||
if c.instance:FindFirstChild(`{x},{y},{z}`) then
|
||||
c.instance:FindFirstChild(`{x},{y},{z}`):Destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ChunkBuilder:BuildChunk(c: typeof(Chunk.new(0,0,0)),parent: Instance?)
|
||||
|
||||
if c.loaded then
|
||||
return c.instance
|
||||
end
|
||||
|
||||
local blocks = c.data
|
||||
local newcache = {} :: {[typeof("")]: Chunk.BlockData}
|
||||
|
||||
local finished = false
|
||||
|
||||
|
||||
local ch = Instance.new("Folder")
|
||||
ch.Parent = parent
|
||||
ch.Name = `{c.pos.X},{c.pos.Y},{c.pos.Z}`
|
||||
|
||||
local conn = c.UpdateBlockBindableL.Event:Connect(function(x: number, y: number, z: number, d: BlockData)
|
||||
task.desynchronize()
|
||||
if finished == false then
|
||||
newcache[`{x},{y},{z}`] = d
|
||||
return
|
||||
end
|
||||
task.synchronize()
|
||||
for _, o in pairs({{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}}) do
|
||||
--warn("propogate",o[1],o[2],o[3])
|
||||
-- Adjust for chunk boundaries
|
||||
local b = {x = x + o[1], y = y + o[2], z = z + o[3]}
|
||||
local ch = {x = c.pos.X, y = c.pos.Y, z = c.pos.Z}
|
||||
|
||||
if b.x < 1 then ch.x = c.pos.X - 1 b.x = 8 end
|
||||
if b.x > 8 then ch.x = c.pos.X + 1 b.x = 1 end
|
||||
if b.y < 1 then ch.y = c.pos.Y - 1 b.y = 8 end
|
||||
if b.y > 8 then ch.y = c.pos.Y + 1 b.y = 1 end
|
||||
if b.z < 1 then ch.z = c.pos.Z - 1 b.z = 8 end
|
||||
if b.z > 8 then ch.z = c.pos.Z + 1 b.z = 1 end
|
||||
|
||||
propogateNeighboringBlockChanges(ch.x, ch.y, ch.z, b.x, b.y, b.z)
|
||||
--BlockManager:GetBlock(ch.x)
|
||||
end
|
||||
|
||||
if d == 0 then
|
||||
if ch:FindFirstChild(`{x},{y},{z}`) then
|
||||
task.synchronize()
|
||||
ch:FindFirstChild(`{x},{y},{z}`):Destroy()
|
||||
task.desynchronize()
|
||||
end
|
||||
return
|
||||
end
|
||||
if not c:IsBlockRenderable(x, y, z) then
|
||||
if ch:FindFirstChild(`{x},{y},{z}`) then
|
||||
task.synchronize()
|
||||
ch:FindFirstChild(`{x},{y},{z}`):Destroy()
|
||||
task.desynchronize()
|
||||
end
|
||||
return
|
||||
end
|
||||
if ch:FindFirstChild(`{x},{y},{z}`) then
|
||||
task.synchronize()
|
||||
ch:FindFirstChild(`{x},{y},{z}`):Destroy()
|
||||
task.desynchronize()
|
||||
end
|
||||
if not d then return end
|
||||
if d.id == 0 then return end
|
||||
local N = util.RotationStringToNormalId(d.state["r"] or "f")
|
||||
task.synchronize()
|
||||
local block = BlockManager:GetBlockRotated(d.id, N, d.state)
|
||||
block.Name = `{x},{y},{z}`
|
||||
block:PivotTo(util.ChunkPosToCFrame(c.pos, Vector3.new(x, y, z)))
|
||||
block.Parent = ch
|
||||
task.desynchronize()
|
||||
end)
|
||||
|
||||
c.unloadChunkHook = function()
|
||||
conn:Disconnect()
|
||||
blocks = nil
|
||||
c = nil
|
||||
end
|
||||
|
||||
task.defer(function()
|
||||
|
||||
local p = 0
|
||||
|
||||
task.synchronize()
|
||||
|
||||
local hb = false
|
||||
|
||||
for a,b in pairs(blocks) do
|
||||
hb = true
|
||||
end
|
||||
|
||||
local border = Instance.new("Part")
|
||||
if hb == true then
|
||||
border:Destroy()
|
||||
border = placeBorder(c.pos.X, c.pos.Y, c.pos.Z)
|
||||
end
|
||||
|
||||
for a,b in pairs(blocks) do
|
||||
task.desynchronize()
|
||||
local coords = util.BlockPosStringToCoords(a)
|
||||
if not c:IsBlockRenderable(coords.X, coords.Y, coords.Z) then
|
||||
if ch:FindFirstChild(a) then
|
||||
task.synchronize()
|
||||
ch:FindFirstChild(a):Destroy()
|
||||
task.desynchronize()
|
||||
end
|
||||
continue
|
||||
end
|
||||
task.desynchronize()
|
||||
local N = util.RotationStringToNormalId(b.state["r"] or "f")
|
||||
task.synchronize()
|
||||
local block = BlockManager:GetBlockRotated(b.id, N, b.state)
|
||||
if ch:FindFirstChild(a) then
|
||||
ch:FindFirstChild(a):Destroy()
|
||||
end
|
||||
block.Name = a
|
||||
block:PivotTo(util.ChunkPosToCFrame(c.pos, coords))
|
||||
block.Parent = ch
|
||||
p += 1
|
||||
if p == 15 then
|
||||
p = 0
|
||||
Swait(1)
|
||||
end
|
||||
end
|
||||
|
||||
finished = true
|
||||
|
||||
task.synchronize()
|
||||
border:Destroy()
|
||||
task.desynchronize()
|
||||
|
||||
task.defer(function()
|
||||
task.synchronize()
|
||||
for a,b in pairs(newcache) do
|
||||
for _, o in pairs({{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}}) do
|
||||
-- chunks are 8x8x8
|
||||
local b = {x=x+o[1],y=y+o[2],z=z+o[3]}
|
||||
local ch = {x=c.pos.X,y=c.pos.Y,z=c.pos.Z}
|
||||
if b.x == 0 then ch.x = c.pos.X - 1 b.x = 8 end
|
||||
if b.x == 9 then ch.x = c.pos.X + 1 b.x = 1 end
|
||||
|
||||
if b.y == 0 then ch.y = c.pos.Y - 1 b.y = 8 end
|
||||
if b.y == 9 then ch.y = c.pos.Y +1 b.y = 1 end
|
||||
|
||||
if b.z == 0 then ch.z = c.pos.Z - 1 b.z = 8 end
|
||||
if b.z == 9 then ch.z = c.pos.Z + 1 b.z = 1 end
|
||||
|
||||
propogateNeighboringBlockChanges(ch.x,ch.y,ch.z,b.x,b.y,b.z)
|
||||
end
|
||||
local coords = util.BlockPosStringToCoords(a)
|
||||
if not c:IsBlockRenderable(coords.X, coords.Y, coords.Z) then
|
||||
if ch:FindFirstChild(a) then
|
||||
ch:FindFirstChild(a):Destroy()
|
||||
end
|
||||
continue
|
||||
end
|
||||
if ch:FindFirstChild(a) then
|
||||
ch:FindFirstChild(a):Destroy()
|
||||
end
|
||||
local N = util.RotationStringToNormalId(b.state["r"] or "f")
|
||||
local block = BlockManager:GetBlockRotated(b.id,N,b.state)
|
||||
block.Name = a
|
||||
block:PivotTo(util.ChunkPosToCFrame(c.pos,coords))
|
||||
block.Parent = ch
|
||||
end
|
||||
newcache = nil
|
||||
blocks = nil
|
||||
end)
|
||||
task.desynchronize()
|
||||
end)
|
||||
|
||||
c.loaded = true
|
||||
|
||||
return ch
|
||||
|
||||
end
|
||||
|
||||
return ChunkBuilder
|
||||
208
src/ReplicatedStorage/Shared/ChunkManager/init.lua
Normal file
208
src/ReplicatedStorage/Shared/ChunkManager/init.lua
Normal file
@@ -0,0 +1,208 @@
|
||||
local ChunkManager = {}
|
||||
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local Chunk = require("./ChunkManager/Chunk")
|
||||
local BlockManager = require("./ChunkManager/BlockManager")
|
||||
local ChunkBuilder = require("./ChunkManager/ChunkBuilder")
|
||||
|
||||
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RecieveChunkPacket")
|
||||
local tickremote = game:GetService("ReplicatedStorage"):WaitForChild("Tick")
|
||||
|
||||
local ChunkFolder = Instance.new("Folder")
|
||||
ChunkFolder.Name = "$blockscraft_client"
|
||||
|
||||
ChunkManager.ChunkFolder = ChunkFolder
|
||||
|
||||
local CHUNK_RADIUS = 5
|
||||
local FORCELOAD_CHUNKS = {
|
||||
{0, 1, 0}
|
||||
}
|
||||
|
||||
local unloadingChunks = {}
|
||||
|
||||
local function Swait(l)
|
||||
task.synchronize()
|
||||
for _ = 1, l do
|
||||
RunService.Stepped:Wait()
|
||||
end
|
||||
end
|
||||
|
||||
function ChunkManager:GetChunk(x, y, z)
|
||||
local key = `{x},{y},{z}`
|
||||
if Chunk.AllChunks[key] then
|
||||
return Chunk.AllChunks[key]
|
||||
end
|
||||
|
||||
task.synchronize()
|
||||
local data = remote:InvokeServer(x, y, z)
|
||||
task.desynchronize()
|
||||
|
||||
local ch = Chunk.from(x, y, z, data)
|
||||
Chunk.AllChunks[key] = ch
|
||||
return ch
|
||||
end
|
||||
|
||||
local function ensureNeighboringChunksLoaded(x, y, z)
|
||||
local offsets = {
|
||||
{1, 0, 0}, {-1, 0, 0},
|
||||
{0, 1, 0}, {0, -1, 0},
|
||||
{0, 0, 1}, {0, 0, -1}
|
||||
}
|
||||
|
||||
for _, offset in ipairs(offsets) do
|
||||
local nx, ny, nz = x + offset[1], y + offset[2], z + offset[3]
|
||||
ChunkManager:GetChunk(nx, ny, nz):Tick()
|
||||
end
|
||||
end
|
||||
|
||||
function ChunkManager:LoadChunk(x, y, z)
|
||||
local key = `{x},{y},{z}`
|
||||
if unloadingChunks[key] or not Chunk.AllChunks[key] or Chunk.AllChunks[key].loaded then
|
||||
return
|
||||
end
|
||||
|
||||
unloadingChunks[key] = true
|
||||
task.defer(function()
|
||||
task.desynchronize()
|
||||
ensureNeighboringChunksLoaded(x, y, z)
|
||||
|
||||
local chunk = Chunk.AllChunks[key]
|
||||
if not chunk then
|
||||
chunk = ChunkManager:GetChunk(x, y, z)
|
||||
Chunk.AllChunks[key] = chunk
|
||||
end
|
||||
|
||||
task.synchronize()
|
||||
local instance = ChunkBuilder:BuildChunk(chunk, ChunkFolder)
|
||||
chunk.instance = instance
|
||||
chunk.loaded = true
|
||||
unloadingChunks[key] = nil
|
||||
end)
|
||||
end
|
||||
|
||||
function ChunkManager:ForceTick()
|
||||
for _, coords in ipairs(FORCELOAD_CHUNKS) do
|
||||
local key = `{coords[1]},{coords[2]},{coords[3]}`
|
||||
local chunk = Chunk.AllChunks[key]
|
||||
if not chunk then
|
||||
ChunkManager:LoadChunk(coords[1], coords[2], coords[3])
|
||||
else
|
||||
chunk:Tick()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ChunkManager:TickI()
|
||||
for key, chunk in pairs(Chunk.AllChunks) do
|
||||
if tick() - chunk.inhabitedTime <= 5 then
|
||||
tickremote:FireServer(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ChunkManager:Tick()
|
||||
ChunkManager:ForceTick()
|
||||
local player = game:GetService("Players").LocalPlayer
|
||||
if not player.Character then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = player.Character:GetPivot().Position
|
||||
local chunkPos = {
|
||||
x = math.round(pos.X / 32),
|
||||
y = math.round(pos.Y / 32),
|
||||
z = math.round(pos.Z / 32)
|
||||
}
|
||||
|
||||
task.defer(function()
|
||||
for y = -CHUNK_RADIUS, CHUNK_RADIUS do
|
||||
task.defer(function()
|
||||
for x = -CHUNK_RADIUS, CHUNK_RADIUS do
|
||||
task.desynchronize()
|
||||
for z = -CHUNK_RADIUS, CHUNK_RADIUS do
|
||||
local cx, cy, cz = chunkPos.x + x, chunkPos.y + y, chunkPos.z + z
|
||||
local key = `{cx},{cy},{cz}`
|
||||
local chunk = ChunkManager:GetChunk(cx, cy, cz)
|
||||
chunk.inhabitedTime = tick()
|
||||
if not chunk.loaded then
|
||||
ChunkManager:LoadChunk(cx, cy, cz)
|
||||
Swait(2)
|
||||
end
|
||||
end
|
||||
task.synchronize()
|
||||
end
|
||||
end)
|
||||
Swait(10)
|
||||
end
|
||||
end)
|
||||
|
||||
--[[
|
||||
task.defer(function()
|
||||
for y = 0, 2 do
|
||||
task.defer(function()
|
||||
for x = -CHUNK_RADIUS, CHUNK_RADIUS do
|
||||
task.desynchronize()
|
||||
for z = -CHUNK_RADIUS, CHUNK_RADIUS do
|
||||
local cx, cy, cz = chunkPos.x + x, y, chunkPos.z + z
|
||||
local key = `{cx},{cy},{cz}`
|
||||
local chunk = ChunkManager:GetChunk(cx, cy, cz)
|
||||
chunk.inhabitedTime = tick()
|
||||
if not chunk.loaded then
|
||||
ChunkManager:LoadChunk(cx, cy, cz)
|
||||
Swait(2)
|
||||
end
|
||||
end
|
||||
task.synchronize()
|
||||
end
|
||||
end)
|
||||
Swait(10)
|
||||
end
|
||||
end)
|
||||
--]]
|
||||
|
||||
for key, loadedChunk in pairs(Chunk.AllChunks) do
|
||||
if tick() - loadedChunk.inhabitedTime > 15 and not unloadingChunks[key] then
|
||||
unloadingChunks[key] = true
|
||||
task.defer(function()
|
||||
task.synchronize()
|
||||
loadedChunk:Unload()
|
||||
loadedChunk:Destroy()
|
||||
Chunk.AllChunks[key] = nil
|
||||
unloadingChunks[key] = nil
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ChunkManager:Init()
|
||||
if not RunService:IsClient() then
|
||||
error("ChunkManager:Init can only be called on the client")
|
||||
end
|
||||
|
||||
ChunkFolder.Parent = game:GetService("Workspace")
|
||||
ChunkManager:ForceTick()
|
||||
|
||||
task.defer(function()
|
||||
while true do
|
||||
wait(2)
|
||||
ChunkManager:TickI()
|
||||
end
|
||||
end)
|
||||
|
||||
task.defer(function()
|
||||
while true do
|
||||
task.defer(function()
|
||||
local success, err = pcall(function()
|
||||
ChunkManager:Tick()
|
||||
end)
|
||||
if not success then
|
||||
warn("[CHUNKMANAGER]", err)
|
||||
end
|
||||
end)
|
||||
Swait(20)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return ChunkManager
|
||||
47
src/ReplicatedStorage/Shared/ModLoader.lua
Normal file
47
src/ReplicatedStorage/Shared/ModLoader.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
local ML = {}
|
||||
|
||||
type modContext = {
|
||||
name: string,
|
||||
description: string,
|
||||
ns: string,
|
||||
author: {string},
|
||||
init: typeof(function()end)
|
||||
}
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Shared = ReplicatedStorage:WaitForChild("Shared")
|
||||
local ModsFolder = ReplicatedStorage:WaitForChild("Mods")
|
||||
|
||||
function ML.loadModsS()
|
||||
print("[SSModLoader] Loading Mods")
|
||||
|
||||
for _, m in pairs(ModsFolder:GetChildren()) do
|
||||
local success, reason = pcall(function()
|
||||
-- ignore type err
|
||||
local mod: modContext = require(m)
|
||||
mod.init()
|
||||
print(`[SSModLoader] Loaded {mod.name} ({mod.ns}) by {table.concat(mod.author,", ")}`)
|
||||
end)
|
||||
if not success then
|
||||
warn(`[CSModLoader] Error loading {m.Name}: {reason}`)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ML.loadModsC()
|
||||
print("[CSModLoader] Loading Mods")
|
||||
|
||||
for _, m in pairs(ModsFolder:GetChildren()) do
|
||||
local success, reason = pcall(function()
|
||||
-- ignore type err
|
||||
local mod: modContext = require(m)
|
||||
mod.init()
|
||||
print(`[CSModLoader] Loaded {mod.name} ({mod.ns}) by {table.concat(mod.author,", ")}`)
|
||||
end)
|
||||
if not success then
|
||||
warn(`[CSModLoader] Error loading {m.Name}: {reason}`)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return ML
|
||||
140
src/ReplicatedStorage/Shared/PlacementManager.lua
Normal file
140
src/ReplicatedStorage/Shared/PlacementManager.lua
Normal file
@@ -0,0 +1,140 @@
|
||||
local PlacementManager = {}
|
||||
|
||||
local ChunkManager = require("./ChunkManager")
|
||||
local Util = require("./Util")
|
||||
|
||||
PlacementManager.ChunkFolder = ChunkManager.ChunkFolder
|
||||
|
||||
local raycastParams = RaycastParams.new()
|
||||
raycastParams.FilterDescendantsInstances = {PlacementManager.ChunkFolder}
|
||||
raycastParams.FilterType = Enum.RaycastFilterType.Include
|
||||
raycastParams.IgnoreWater = true
|
||||
|
||||
if _G.SB then return nil end
|
||||
_G.SB = true
|
||||
|
||||
PlacementManager.SelectionBox = script.SelectionBox:Clone()
|
||||
PlacementManager.SelectionBox.Name = "$SelectionBox"..(game:GetService("RunService"):IsServer() and "_SERVER" or "")
|
||||
PlacementManager.SelectionBox.Parent = game:GetService("Workspace"):FindFirstChildOfClass("Terrain")
|
||||
|
||||
-- Trash method TODO: Fix this
|
||||
local function findParent(i: Instance): Instance
|
||||
local f = i:FindFirstAncestorOfClass("Folder")
|
||||
local d = i
|
||||
repeat
|
||||
d = d.Parent
|
||||
until d.Parent == f
|
||||
return d
|
||||
end
|
||||
|
||||
local Mouse: Mouse = nil
|
||||
|
||||
-- Gets the block and normalid of the block (and surface) the player is looking at
|
||||
function PlacementManager:Raycast()
|
||||
if not Mouse then
|
||||
Mouse = game:GetService("Players").LocalPlayer:GetMouse()
|
||||
end
|
||||
task.synchronize()
|
||||
local objLookingAt = Mouse.Target
|
||||
local dir = Mouse.TargetSurface
|
||||
if not objLookingAt then
|
||||
PlacementManager.SelectionBox.Adornee = nil
|
||||
script.RaycastResult.Value = nil
|
||||
return
|
||||
end
|
||||
|
||||
--if not objLookingAt:IsDescendantOf(ChunkManager.ChunkFolder) then return end
|
||||
local parent = findParent(objLookingAt)
|
||||
if parent:GetAttribute("ns") == true then
|
||||
PlacementManager.SelectionBox.Adornee = nil
|
||||
script.RaycastResult.Value = nil
|
||||
return
|
||||
end
|
||||
PlacementManager.SelectionBox.Adornee = parent
|
||||
script.RaycastResult.Value = parent
|
||||
return parent, dir
|
||||
end
|
||||
|
||||
function PlacementManager:RaycastGetResult()
|
||||
return script.RaycastResult.Value
|
||||
end
|
||||
|
||||
local placeRemote = game:GetService("ReplicatedStorage").PlaceBlock
|
||||
local breakRemote = game:GetService("ReplicatedStorage").BreakBlock
|
||||
local tickRemote = game:GetService("ReplicatedStorage").Tick
|
||||
|
||||
-- FIRES REMOTE
|
||||
function PlacementManager:PlaceBlock(cx, cy, cz, x, y, z, blockData)
|
||||
--print("placeblock")
|
||||
--local chunk = ChunkManager:GetChunk(cx, cy, cz)
|
||||
--chunk:CreateBlock(x, y, z, blockData)
|
||||
placeRemote:FireServer(cx, cy, cz, x, y, z, blockData)
|
||||
end
|
||||
|
||||
-- FIRES REMOTE
|
||||
function PlacementManager:BreakBlock(cx, cy, cz, x, y, z)
|
||||
--print("breakblock")
|
||||
--local chunk = ChunkManager:GetChunk(cx, cy, cz)
|
||||
--chunk:RemoveBlock(x, y, z)
|
||||
breakRemote:FireServer(cx, cy, cz, x, y, z)
|
||||
end
|
||||
|
||||
-- CLIENTSIDED
|
||||
function PlacementManager:PlaceBlockLocal(cx, cy, cz, x, y, z, blockData)
|
||||
local chunk = ChunkManager:GetChunk(cx, cy, cz)
|
||||
chunk:CreateBlock(x, y, z, blockData)
|
||||
end
|
||||
|
||||
-- CLIENTSIDED
|
||||
function PlacementManager:BreakBlockLocal(cx, cy, cz, x, y, z)
|
||||
local chunk = ChunkManager:GetChunk(cx, cy, cz)
|
||||
chunk:RemoveBlock(x, y, z)
|
||||
end
|
||||
|
||||
function PlacementManager:GetBlockAtMouse(): nil | {chunk:Vector3, block: Vector3}
|
||||
local selectedPart = PlacementManager:RaycastGetResult()
|
||||
--print(selectedPart and selectedPart:GetFullName() or nil)
|
||||
if selectedPart == nil then
|
||||
PlacementManager.SelectionBox.Adornee = nil
|
||||
script.RaycastResult.Value = nil
|
||||
return nil
|
||||
end
|
||||
if not selectedPart.Parent then
|
||||
PlacementManager.SelectionBox.Adornee = nil
|
||||
script.RaycastResult.Value = nil
|
||||
return nil
|
||||
end
|
||||
local chunkCoords = Util.BlockPosStringToCoords(selectedPart.Parent.Name)
|
||||
local blockCoords = Util.BlockPosStringToCoords(selectedPart.Name)
|
||||
|
||||
return {
|
||||
chunk = chunkCoords,
|
||||
block = blockCoords
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
function PlacementManager:Init()
|
||||
game:GetService("RunService").Heartbeat:Connect(function()
|
||||
local a,b = pcall(function()
|
||||
PlacementManager:Raycast()
|
||||
end)
|
||||
if not a then
|
||||
task.synchronize()
|
||||
PlacementManager.SelectionBox.Adornee = nil
|
||||
script.RaycastResult.Value = nil
|
||||
task.desynchronize()
|
||||
end
|
||||
end)
|
||||
tickRemote.OnClientEvent:Connect(function(m, cx, cy, cz, x, y, z, d)
|
||||
--warn("PROPOGATED TICK", m, cx, cy, cz, x, y, z, d)
|
||||
if m == "B_C" then
|
||||
PlacementManager:PlaceBlockLocal(cx, cy, cz, x, y ,z, d)
|
||||
end
|
||||
if m == "B_D" then
|
||||
PlacementManager:BreakBlockLocal(cx, cy, cz, x, y ,z)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return PlacementManager
|
||||
3
src/ReplicatedStorage/Shared/PlacementManager.meta.json
Normal file
3
src/ReplicatedStorage/Shared/PlacementManager.meta.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
48
src/ReplicatedStorage/Shared/Util.lua
Normal file
48
src/ReplicatedStorage/Shared/Util.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
local module = {}
|
||||
|
||||
function module.BlockPosStringToCoords(s: string): Vector3
|
||||
-- a,b,c
|
||||
local split = string.split(s,",")
|
||||
return Vector3.new(tonumber(split[1]), tonumber(split[2]), tonumber(split[3]))
|
||||
end
|
||||
|
||||
function module.RotationStringToNormalId(s: string): Enum.NormalId
|
||||
if not s then return Enum.NormalId.Front end
|
||||
if s == "f" then
|
||||
return Enum.NormalId.Front
|
||||
end
|
||||
if s == "b" then
|
||||
return Enum.NormalId.Back
|
||||
end
|
||||
if s == "l" then
|
||||
return Enum.NormalId.Left
|
||||
end
|
||||
if s == "r" then
|
||||
return Enum.NormalId.Right
|
||||
end
|
||||
if s == "t" then
|
||||
return Enum.NormalId.Top
|
||||
end
|
||||
if s == "b" then
|
||||
return Enum.NormalId.Bottom
|
||||
end
|
||||
warn("Could not convert",s,"to Enum.NormalId")
|
||||
return Enum.NormalId.Front
|
||||
end
|
||||
|
||||
-- chunk size 8x8x8 relative block indexs 1-8
|
||||
function module.GlobalBlockPosToRelative(x: number,y:number,z:number)
|
||||
return x%8,y%8,z%8
|
||||
end
|
||||
|
||||
function module.ChunkPosToCFrame(chunk: Vector3, block: Vector3): CFrame
|
||||
return CFrame.new(
|
||||
CFrame.new(
|
||||
(32*chunk.X)+(block.X*4)-18,
|
||||
(32*chunk.Y)+(block.Y*4)-18,
|
||||
(32*chunk.Z)+(block.Z*4)-18
|
||||
).Position
|
||||
)
|
||||
end
|
||||
|
||||
return module
|
||||
3
src/ReplicatedStorage/Shared/init.meta.json
Normal file
3
src/ReplicatedStorage/Shared/init.meta.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
local Node = {}
|
||||
Node.__index = Node
|
||||
|
||||
function Node.new(data)
|
||||
local node = setmetatable({}, Node)
|
||||
node.data = data
|
||||
node.left = nil
|
||||
node.right = nil
|
||||
return node
|
||||
end
|
||||
|
||||
-- return an iterator that traverses the tree in order
|
||||
function Node:inorder()
|
||||
local stack = {}
|
||||
local current = {self, ""}
|
||||
table.insert(stack, current)
|
||||
|
||||
return function()
|
||||
while current[1].left do
|
||||
local parent = current
|
||||
current = {parent[1].left, parent[2] .. "0"}
|
||||
table.insert(stack, current)
|
||||
end
|
||||
|
||||
if #stack > 0 then
|
||||
local node = table.remove(stack)
|
||||
|
||||
if node[1].right then
|
||||
local parent = node
|
||||
current = {parent[1].right, parent[2] .. "1"}
|
||||
table.insert(stack, current)
|
||||
end
|
||||
return node[1], node[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Node
|
||||
@@ -0,0 +1,232 @@
|
||||
--[[
|
||||
|
||||
PriorityQueue - v1.0.1 - public domain Lua priority queue
|
||||
implemented with indirect binary heap
|
||||
no warranty implied; use at your own risk
|
||||
|
||||
based on binaryheap library (github.com/iskolbin/binaryheap)
|
||||
|
||||
author: Ilya Kolbin (iskolbin@gmail.com)
|
||||
url: github.com/iskolbin/priorityqueue
|
||||
|
||||
See documentation in README file.
|
||||
|
||||
COMPATIBILITY
|
||||
|
||||
Lua 5.1, 5.2, 5.3, LuaJIT 1, 2
|
||||
|
||||
LICENSE
|
||||
|
||||
This software is dual-licensed to the public domain and under the following
|
||||
license: you are granted a perpetual, irrevocable license to copy, modify,
|
||||
publish, and distribute this file as you see fit.
|
||||
|
||||
--]]
|
||||
|
||||
local floor, setmetatable = math.floor, setmetatable
|
||||
|
||||
local function siftup( self, from )
|
||||
local items, priorities, indices, higherpriority = self, self._priorities, self._indices, self._higherpriority
|
||||
local index = from
|
||||
local parent = floor( index / 2 )
|
||||
while index > 1 and higherpriority( priorities[index], priorities[parent] ) do
|
||||
priorities[index], priorities[parent] = priorities[parent], priorities[index]
|
||||
items[index], items[parent] = items[parent], items[index]
|
||||
indices[items[index]], indices[items[parent]] = index, parent
|
||||
index = parent
|
||||
parent = floor( index / 2 )
|
||||
end
|
||||
return index
|
||||
end
|
||||
|
||||
local function siftdown( self, limit )
|
||||
local items, priorities, indices, higherpriority, size = self, self._priorities, self._indices, self._higherpriority, self._size
|
||||
for index = limit, 1, -1 do
|
||||
local left = index + index
|
||||
local right = left + 1
|
||||
while left <= size do
|
||||
local smaller = left
|
||||
if right <= size and higherpriority( priorities[right], priorities[left] ) then
|
||||
smaller = right
|
||||
end
|
||||
if higherpriority( priorities[smaller], priorities[index] ) then
|
||||
items[index], items[smaller] = items[smaller], items[index]
|
||||
priorities[index], priorities[smaller] = priorities[smaller], priorities[index]
|
||||
indices[items[index]], indices[items[smaller]] = index, smaller
|
||||
else
|
||||
break
|
||||
end
|
||||
index = smaller
|
||||
left = index + index
|
||||
right = left + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local PriorityQueueMt
|
||||
|
||||
local PriorityQueue = {}
|
||||
|
||||
local function minishigher( a, b )
|
||||
return a < b
|
||||
end
|
||||
|
||||
local function maxishigher( a, b )
|
||||
return a > b
|
||||
end
|
||||
|
||||
function PriorityQueue.new( priority_or_array )
|
||||
local t = type( priority_or_array )
|
||||
local higherpriority = minishigher
|
||||
|
||||
if t == 'table' then
|
||||
higherpriority = priority_or_array.higherpriority or higherpriority
|
||||
elseif t == 'function' or t == 'string' then
|
||||
higherpriority = priority_or_array
|
||||
elseif t ~= 'nil' then
|
||||
local msg = 'Wrong argument type to PriorityQueue.new, it must be table or function or string, has: %q'
|
||||
error( msg:format( t ))
|
||||
end
|
||||
|
||||
if type( higherpriority ) == 'string' then
|
||||
if higherpriority == 'min' then
|
||||
higherpriority = minishigher
|
||||
elseif higherpriority == 'max' then
|
||||
higherpriority = maxishigher
|
||||
else
|
||||
local msg = 'Wrong string argument to PriorityQueue.new, it must be "min" or "max", has: %q'
|
||||
error( msg:format( tostring( higherpriority )))
|
||||
end
|
||||
end
|
||||
|
||||
local self = setmetatable( {
|
||||
_priorities = {},
|
||||
_indices = {},
|
||||
_size = 0,
|
||||
_higherpriority = higherpriority or minishigher
|
||||
}, PriorityQueueMt )
|
||||
|
||||
if t == 'table' then
|
||||
self:batchenq( priority_or_array )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function PriorityQueue:enqueue( item, priority )
|
||||
local items, priorities, indices = self, self._priorities, self._indices
|
||||
if indices[item] ~= nil then
|
||||
error( 'Item ' .. tostring(indices[item]) .. ' is already in the heap' )
|
||||
end
|
||||
local size = self._size + 1
|
||||
self._size = size
|
||||
items[size], priorities[size], indices[item] = item, priority, size
|
||||
siftup( self, size )
|
||||
return self
|
||||
end
|
||||
|
||||
function PriorityQueue:remove( item )
|
||||
local index = self._indices[item]
|
||||
if index ~= nil then
|
||||
local size = self._size
|
||||
local items, priorities, indices = self, self._priorities, self._indices
|
||||
indices[item] = nil
|
||||
if size == index then
|
||||
items[size], priorities[size] = nil, nil
|
||||
self._size = size - 1
|
||||
else
|
||||
local lastitem = items[size]
|
||||
items[index], priorities[index] = items[size], priorities[size]
|
||||
items[size], priorities[size] = nil, nil
|
||||
indices[lastitem] = index
|
||||
size = size - 1
|
||||
self._size = size
|
||||
if size > 1 then
|
||||
siftdown( self, siftup( self, index ))
|
||||
end
|
||||
end
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function PriorityQueue:contains( item )
|
||||
return self._indices[item] ~= nil
|
||||
end
|
||||
|
||||
function PriorityQueue:update( item, priority )
|
||||
local ok = self:remove( item )
|
||||
if ok then
|
||||
self:enqueue( item, priority )
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function PriorityQueue:dequeue()
|
||||
local size = self._size
|
||||
|
||||
assert( size > 0, 'Heap is empty' )
|
||||
|
||||
local items, priorities, indices = self, self._priorities, self._indices
|
||||
local item, priority = items[1], priorities[1]
|
||||
indices[item] = nil
|
||||
|
||||
if size > 1 then
|
||||
local newitem = items[size]
|
||||
items[1], priorities[1] = newitem, priorities[size]
|
||||
items[size], priorities[size] = nil, nil
|
||||
indices[newitem] = 1
|
||||
size = size - 1
|
||||
self._size = size
|
||||
siftdown( self, 1 )
|
||||
else
|
||||
items[1], priorities[1] = nil, nil
|
||||
self._size = 0
|
||||
end
|
||||
|
||||
return item, priority
|
||||
end
|
||||
|
||||
function PriorityQueue:peek()
|
||||
return self[1], self._priorities[1]
|
||||
end
|
||||
|
||||
function PriorityQueue:len()
|
||||
return self._size
|
||||
end
|
||||
|
||||
function PriorityQueue:empty()
|
||||
return self._size <= 0
|
||||
end
|
||||
|
||||
function PriorityQueue:batchenq( iparray )
|
||||
local items, priorities, indices = self, self._priorities, self._indices
|
||||
local size = self._size
|
||||
for i = 1, #iparray, 2 do
|
||||
local item, priority = iparray[i], iparray[i+1]
|
||||
if indices[item] ~= nil then
|
||||
error( 'Item ' .. tostring(indices[item]) .. ' is already in the heap' )
|
||||
end
|
||||
size = size + 1
|
||||
items[size], priorities[size] = item, priority
|
||||
indices[item] = size
|
||||
end
|
||||
self._size = size
|
||||
if size > 1 then
|
||||
siftdown( self, floor( size / 2 ))
|
||||
end
|
||||
end
|
||||
|
||||
PriorityQueueMt = {
|
||||
__index = PriorityQueue,
|
||||
__len = PriorityQueue.len,
|
||||
}
|
||||
|
||||
return setmetatable( PriorityQueue, {
|
||||
__call = function( _, ... )
|
||||
return PriorityQueue.new( ... )
|
||||
end
|
||||
} )
|
||||
@@ -0,0 +1,114 @@
|
||||
--Huffman.lua
|
||||
--iiau, Sat May 18 2024
|
||||
--Implementation of huffman coding algorithm for use in Roblox
|
||||
|
||||
local Huffman = {}
|
||||
local PriorityQueue = require(script.PriorityQueue)
|
||||
local Node = require(script.Node)
|
||||
local BitBuffer = require(script.BitBuffer)
|
||||
|
||||
local CHUNK_SIZE = 256
|
||||
|
||||
--thanks to https://stackoverflow.com/a/32220398 for helping me with this
|
||||
local function to_bin(n)
|
||||
local t = {}
|
||||
for _ = 1, 32 do
|
||||
n = bit32.rrotate(n, -1)
|
||||
table.insert(t, bit32.band(n, 1))
|
||||
end
|
||||
return table.concat(t)
|
||||
end
|
||||
|
||||
-- Encode a string to huffman coded string. Limitation is that the data should not be more than 16777215 bytes.
|
||||
-- @param data The string to encode
|
||||
-- @return The encoded string
|
||||
Huffman.encode = function(data: string) : string
|
||||
assert(#data > 0, "Data must not be empty")
|
||||
local buffer = BitBuffer()
|
||||
|
||||
-- get the frequency of each character in the string
|
||||
local freq, dict, size = {}, {}, 0
|
||||
for c in data:gmatch(".") do
|
||||
freq[c] = (freq[c] or 0) + 1
|
||||
end
|
||||
for _ in pairs(freq) do
|
||||
size += 1
|
||||
end
|
||||
|
||||
local q = PriorityQueue.new 'min'
|
||||
for k: string, v: number in pairs(freq) do
|
||||
local leaf = Node.new(string.byte(k))
|
||||
q:enqueue(leaf, v)
|
||||
end
|
||||
|
||||
while q:len() > 1 do
|
||||
local left, freq_l = q:dequeue()
|
||||
local right, freq_r = q:dequeue()
|
||||
local parent = Node.new()
|
||||
parent.left = left
|
||||
parent.right = right
|
||||
|
||||
q:enqueue(parent, freq_l + freq_r)
|
||||
end
|
||||
local tree = q:dequeue()
|
||||
buffer.writeUInt8(size-1)
|
||||
buffer.writeUnsigned(24, #data)
|
||||
for node, bits: string in tree:inorder() do
|
||||
if not node.data then
|
||||
continue
|
||||
end
|
||||
local number = tonumber(bits, 2)
|
||||
local bit_array = string.split(bits, "")
|
||||
for i = 1, #bit_array do
|
||||
bit_array[i] = tonumber(bit_array[i])
|
||||
end
|
||||
|
||||
dict[string.char(node.data)] = bit_array
|
||||
buffer.writeUInt8(node.data) -- char
|
||||
buffer.writeUnsigned(5, #bits) -- number of bits
|
||||
buffer.writeUnsigned(#bits, number) -- bits
|
||||
end
|
||||
for c in data:gmatch(".") do
|
||||
buffer.writeBits(table.unpack(dict[c]))
|
||||
end
|
||||
|
||||
-- to avoid the dreaded too many results to unpack error
|
||||
local chunks = {}
|
||||
for _, chunk in buffer.exportChunk(CHUNK_SIZE) do
|
||||
table.insert(chunks, chunk)
|
||||
end
|
||||
return table.concat(chunks)
|
||||
end
|
||||
|
||||
-- Decode a string from huffman coded string
|
||||
-- @param data The string to decode
|
||||
-- @return The decoded string
|
||||
Huffman.decode = function(data: string) : string
|
||||
assert(#data > 0, "Data must not be empty")
|
||||
local buffer = BitBuffer(data)
|
||||
|
||||
local dict_size = buffer.readUInt8()+1
|
||||
local len_data = buffer.readUnsigned(24)
|
||||
local dict, read = {}, 0
|
||||
|
||||
for i = 1, dict_size do
|
||||
local char = buffer.readUInt8()
|
||||
local digits = buffer.readUnsigned(5)
|
||||
local bits = buffer.readUnsigned(digits)
|
||||
dict[to_bin(bits):sub(-digits)] = char
|
||||
end
|
||||
local decoded = {}
|
||||
local bits = ""
|
||||
while read < len_data do
|
||||
bits ..= buffer.readBits(1)[1]
|
||||
local char = dict[bits]
|
||||
if char then
|
||||
table.insert(decoded, string.char(char))
|
||||
bits = ""
|
||||
read += 1
|
||||
end
|
||||
end
|
||||
return table.concat(decoded)
|
||||
end
|
||||
|
||||
return Huffman
|
||||
@@ -0,0 +1,170 @@
|
||||
-- Module by 1waffle1 and boatbomber, optimized and fixed by iiau
|
||||
-- https://devforum.roblox.com/t/text-compression/163637/37
|
||||
|
||||
local dictionary = {} -- key to len
|
||||
|
||||
do -- populate dictionary
|
||||
local length = 0
|
||||
for i = 32, 127 do
|
||||
if i ~= 34 and i ~= 92 then
|
||||
local c = string.char(i)
|
||||
dictionary[c] = length
|
||||
dictionary[length] = c
|
||||
length = length + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local escapemap_126, escapemap_127 = {}, {}
|
||||
local unescapemap_126, unescapemap_127 = {}, {}
|
||||
|
||||
local blacklisted_126 = { 34, 92 }
|
||||
for i = 126, 180 do
|
||||
table.insert(blacklisted_126, i)
|
||||
end
|
||||
|
||||
do -- Populate escape map
|
||||
-- represents the numbers 0-31, 34, 92, 126, 127 (36 characters)
|
||||
-- and 128-180 (52 characters)
|
||||
-- https://devforum.roblox.com/t/text-compression/163637/5
|
||||
for i = 0, 31 + #blacklisted_126 do
|
||||
local b = blacklisted_126[i - 31]
|
||||
local s = i + 32
|
||||
|
||||
-- Note: 126 and 127 are magic numbers
|
||||
local c = string.char(b or i)
|
||||
local e = string.char(s + (s >= 34 and 1 or 0) + (s >= 91 and 1 or 0))
|
||||
|
||||
escapemap_126[c] = e
|
||||
unescapemap_126[e] = c
|
||||
end
|
||||
|
||||
for i = 1, 255 - 180 do
|
||||
local c = string.char(i + 180)
|
||||
local s = i + 34
|
||||
local e = string.char(s + (s >= 92 and 1 or 0))
|
||||
|
||||
escapemap_127[c] = e
|
||||
unescapemap_127[e] = c
|
||||
end
|
||||
end
|
||||
|
||||
local function escape(s)
|
||||
-- escape the control characters 0-31, double quote 34, backslash 92, Tilde 126, and DEL 127 (36 chars)
|
||||
-- escape characters 128-180 (53 chars)
|
||||
return string.gsub(string.gsub(s, '[%c"\\\126-\180]', function(c)
|
||||
return "\126" .. escapemap_126[c]
|
||||
end), '[\181-\255]', function(c)
|
||||
return "\127" .. escapemap_127[c]
|
||||
end)
|
||||
end
|
||||
local function unescape(s)
|
||||
return string.gsub(string.gsub(s, "\127(.)", function(e)
|
||||
return unescapemap_127[e]
|
||||
end), "\126(.)", function(e)
|
||||
return unescapemap_126[e]
|
||||
end)
|
||||
end
|
||||
|
||||
local b93Cache = {}
|
||||
local function tobase93(n)
|
||||
local value = b93Cache[n]
|
||||
if value then
|
||||
return value
|
||||
end
|
||||
|
||||
local c = n
|
||||
value = ""
|
||||
repeat
|
||||
local remainder = n % 93
|
||||
value = dictionary[remainder] .. value
|
||||
n = (n - remainder) / 93
|
||||
until n == 0
|
||||
|
||||
b93Cache[c] = value
|
||||
return value
|
||||
end
|
||||
|
||||
local b10Cache = {}
|
||||
local function tobase10(value)
|
||||
local n = b10Cache[value]
|
||||
if n then
|
||||
return n
|
||||
end
|
||||
|
||||
n = 0
|
||||
for i = 1, #value do
|
||||
n = n + math.pow(93, i - 1) * dictionary[string.sub(value, -i, -i)]
|
||||
end
|
||||
|
||||
b10Cache[value] = n
|
||||
return n
|
||||
end
|
||||
|
||||
local function compress(text)
|
||||
assert(type(text) == "string", "bad argument #1 to 'compress' (string expected, got " .. typeof(text) .. ")")
|
||||
local dictionaryCopy = table.clone(dictionary)
|
||||
local key, sequence, size = "", {}, #dictionary
|
||||
|
||||
local width, spans, span = 1, {}, 0
|
||||
local function listkey(k)
|
||||
local value = tobase93(dictionaryCopy[k])
|
||||
local valueLength = #value
|
||||
if valueLength > width then
|
||||
width, span, spans[width] = valueLength, 0, span
|
||||
end
|
||||
table.insert(sequence, string.rep(" ", width - valueLength) .. value)
|
||||
span += 1
|
||||
end
|
||||
text = escape(text)
|
||||
for i = 1, #text do
|
||||
local c = string.sub(text, i, i)
|
||||
local new = key .. c
|
||||
if dictionaryCopy[new] then
|
||||
key = new
|
||||
else
|
||||
listkey(key)
|
||||
key = c
|
||||
size += 1
|
||||
dictionaryCopy[new] = size
|
||||
dictionaryCopy[size] = new
|
||||
end
|
||||
end
|
||||
listkey(key)
|
||||
spans[width] = span
|
||||
return table.concat(spans, ",") .. "|" .. table.concat(sequence)
|
||||
end
|
||||
|
||||
local function decompress(text)
|
||||
assert(type(text) == "string", "bad argument #1 to 'decompress' (string expected, got " .. typeof(text) .. ")")
|
||||
local dictionaryCopy = table.clone(dictionary)
|
||||
local sequence, spans, content = {}, string.match(text, "(.-)|(.*)")
|
||||
local groups, start = {}, 1
|
||||
for span in string.gmatch(spans, "%d+") do
|
||||
local width = #groups + 1
|
||||
groups[width] = string.sub(content, start, start + span * width - 1)
|
||||
start = start + span * width
|
||||
end
|
||||
local previous
|
||||
|
||||
for width, group in ipairs(groups) do
|
||||
for value in string.gmatch(group, string.rep(".", width)) do
|
||||
local entry = dictionaryCopy[tobase10(value)]
|
||||
if previous then
|
||||
if entry then
|
||||
table.insert(dictionaryCopy, previous .. string.sub(entry, 1, 1))
|
||||
else
|
||||
entry = previous .. string.sub(previous, 1, 1)
|
||||
table.insert(dictionaryCopy, entry)
|
||||
end
|
||||
table.insert(sequence, entry)
|
||||
else
|
||||
sequence[1] = entry
|
||||
end
|
||||
previous = entry
|
||||
end
|
||||
end
|
||||
return unescape(table.concat(sequence))
|
||||
end
|
||||
|
||||
return { compress = compress, decompress = decompress }
|
||||
@@ -0,0 +1,19 @@
|
||||
--Deflate.lua
|
||||
--iiau, Sat May 18 2024
|
||||
|
||||
local Deflate = {}
|
||||
|
||||
local LZW = require(script.LZW)
|
||||
local Huffman = require(script.Huffman)
|
||||
|
||||
Deflate.encode = function(data: string) : string
|
||||
data = LZW.compress(data)
|
||||
return Huffman.encode(data)
|
||||
end
|
||||
|
||||
Deflate.decode = function(data: string) : string
|
||||
data = Huffman.decode(data)
|
||||
return LZW.decompress(data)
|
||||
end
|
||||
|
||||
return Deflate
|
||||
@@ -0,0 +1,65 @@
|
||||
local TerrainGen = {}
|
||||
|
||||
local deflate = require("./TerrainGen/Deflate")
|
||||
|
||||
local DSS = game:GetService("DataStoreService")
|
||||
local WORLDNAME = "DEFAULT"
|
||||
local WORLDID = "b73bb5a6-297d-4352-b637-daec7e8c8f3e"
|
||||
local Store = DSS:GetDataStore("BlockscraftWorldV1", WORLDID)
|
||||
|
||||
local ChunkManager = require(game:GetService("ReplicatedStorage"):WaitForChild("Shared").ChunkManager)
|
||||
local Chunk = require(game:GetService("ReplicatedStorage"):WaitForChild("Shared").ChunkManager.Chunk)
|
||||
|
||||
TerrainGen.ServerChunkCache = {} :: {[typeof("")]: typeof(Chunk.new(0,0,0))}
|
||||
|
||||
-- Load a chunk from the DataStore or generate it if not found
|
||||
function TerrainGen:GetChunk(x, y, z)
|
||||
|
||||
-- Generate a new chunk if it doesn't exist
|
||||
local chunk = Chunk.new(x, y, z)
|
||||
if y == 1 then
|
||||
for cx = 1, 8 do
|
||||
for cz = 1, 8 do
|
||||
--local perlin = math.noise(((x*8)+cx)/100,((z*8)+cz)/100)
|
||||
chunk:CreateBlock(cx, 1, cz, { id = 1, state = {} })
|
||||
--chunk:CreateBlock(x, 2, z, { id = 1, state = {} })
|
||||
end
|
||||
end
|
||||
end
|
||||
if y == 0 then
|
||||
for cx = 1, 8 do
|
||||
for cy = 1, 8 do
|
||||
for cz = 1, 8 do
|
||||
--local perlin = math.noise(((x*8)+cx)/100,((z*8)+cz)/100)
|
||||
chunk:CreateBlock(cx, cy, cz, { id = 2, state = {} })
|
||||
--chunk:CreateBlock(x, 2, z, { id = 1, state = {} })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return chunk
|
||||
end
|
||||
|
||||
-- Fake Chunk
|
||||
function TerrainGen:GetFakeChunk(x, y, z)
|
||||
|
||||
-- Generate a new chunk if it doesn't exist
|
||||
local chunk = Chunk.new(x, y, z)
|
||||
for cy = 1,8 do
|
||||
for cx = 1, 8 do
|
||||
for cz = 1, 8 do
|
||||
--local perlin = math.noise(((x*8)+cx)/100,((z*8)+cz)/100)
|
||||
chunk:CreateBlock(cx, cy, cz, { id = -2, state = {} })
|
||||
--chunk:CreateBlock(x, 2, z, { id = 1, state = {} })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return chunk
|
||||
end
|
||||
|
||||
|
||||
TerrainGen.CM = ChunkManager
|
||||
|
||||
return TerrainGen
|
||||
107
src/ServerScriptService/Actor/ServerChunkManager/init.server.lua
Normal file
107
src/ServerScriptService/Actor/ServerChunkManager/init.server.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
print("Hello world!")
|
||||
|
||||
task.synchronize()
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
|
||||
local Shared = ReplicatedStorage:WaitForChild("Shared")
|
||||
local ModsFolder = ReplicatedStorage:WaitForChild("Mods")
|
||||
|
||||
local PlacementManager = require(Shared.PlacementManager)
|
||||
local TG = require("./ServerChunkManager/TerrainGen")
|
||||
|
||||
do
|
||||
local workspaceModFolder = game:GetService("Workspace"):WaitForChild("mods")
|
||||
|
||||
for _,v in pairs(workspaceModFolder:GetChildren()) do
|
||||
v.Parent = ModsFolder
|
||||
end
|
||||
workspaceModFolder:Destroy()
|
||||
end
|
||||
|
||||
local ML = require(Shared.ModLoader)
|
||||
ML.loadModsS()
|
||||
|
||||
do
|
||||
local bv = Instance.new("BoolValue")
|
||||
bv.Name = "MLLoaded"
|
||||
bv.Value = true
|
||||
bv.Parent = ReplicatedStorage:WaitForChild("Objects")
|
||||
end
|
||||
|
||||
local MAX_CHUNK_DIST = 200
|
||||
|
||||
local FakeChunk = TG:GetFakeChunk(-5,-5,-5)
|
||||
|
||||
task.synchronize()
|
||||
|
||||
ReplicatedStorage.Tick.OnServerEvent:Connect(function(player: Player, v: string)
|
||||
if TG.ServerChunkCache[v] then
|
||||
pcall(function()
|
||||
TG.ServerChunkCache[v].inhabitedTime = tick()
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
ReplicatedStorage.RecieveChunkPacket.OnServerInvoke = function(plr: Player, x: number, y: number, z: number)
|
||||
-- validate xyz type and limit
|
||||
if typeof(x) ~= "number" or typeof(y) ~= "number" or typeof(z) ~= "number" then
|
||||
return {}
|
||||
end
|
||||
|
||||
if math.abs(x) > MAX_CHUNK_DIST or math.abs(y) > MAX_CHUNK_DIST or math.abs(z) > MAX_CHUNK_DIST then
|
||||
return FakeChunk.data
|
||||
end
|
||||
|
||||
task.desynchronize()
|
||||
local chunk = TG:GetChunk(x, y, z)
|
||||
local chunkdata = chunk.data
|
||||
task.synchronize()
|
||||
|
||||
return chunkdata
|
||||
|
||||
end
|
||||
|
||||
local tickRemote = ReplicatedStorage.Tick
|
||||
local function propogate(a, cx, cy, cz, x, y, z, bd)
|
||||
tickRemote:FireAllClients(a, cx, cy, cz, x, y, z, bd)
|
||||
end
|
||||
|
||||
ReplicatedStorage.PlaceBlock.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z, blockData)
|
||||
--print("place",player, cx, cy, cz, x, y, z, blockData)
|
||||
|
||||
if typeof(cx) ~= "number" or typeof(cy) ~= "number" or typeof(cz) ~= "number" then
|
||||
return
|
||||
end
|
||||
if typeof(x) ~= "number" or typeof(y) ~= "number" or typeof(z) ~= "number" then
|
||||
return
|
||||
end
|
||||
if math.abs(cx) > MAX_CHUNK_DIST or math.abs(cy) > MAX_CHUNK_DIST or math.abs(cz) > MAX_CHUNK_DIST then
|
||||
--return
|
||||
end
|
||||
|
||||
--local chunk = TG:GetChunk(cx, cy, cz)
|
||||
--PlacementManager:PlaceBlockLocal(cx, cy, cz, x, y, z, blockData)
|
||||
propogate("B_C", cx, cy, cz, x, y, z, blockData)
|
||||
end)
|
||||
|
||||
ReplicatedStorage.BreakBlock.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z)
|
||||
--print("del",player, cx, cy, cz, x, y, z)
|
||||
|
||||
if typeof(cx) ~= "number" or typeof(cy) ~= "number" or typeof(cz) ~= "number" then
|
||||
return
|
||||
end
|
||||
if typeof(x) ~= "number" or typeof(y) ~= "number" or typeof(z) ~= "number" then
|
||||
return
|
||||
end
|
||||
if math.abs(cx) > MAX_CHUNK_DIST or math.abs(cy) > MAX_CHUNK_DIST or math.abs(cz) > MAX_CHUNK_DIST then
|
||||
return
|
||||
end
|
||||
|
||||
--local chunk = TG:GetChunk(cx, cy, cz)
|
||||
--PlacementManager:BreakBlockLocal(cx, cy, cz, x, y, z)
|
||||
propogate("B_D", cx, cy, cz, x, y, z, 0)
|
||||
end)
|
||||
|
||||
task.desynchronize()
|
||||
4
src/ServerScriptService/Actor/init.meta.json
Normal file
4
src/ServerScriptService/Actor/init.meta.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"className": "Actor",
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
22
src/StarterGui/Crosshair/LocalScript.client.lua
Normal file
22
src/StarterGui/Crosshair/LocalScript.client.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
-- force first person mode on the person's camera
|
||||
|
||||
if not game:IsLoaded() then
|
||||
game.Loaded:Wait()
|
||||
end
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local UIS = game:GetService("UserInputService")
|
||||
|
||||
ReplicatedStorage:WaitForChild("Objects"):WaitForChild("MLLoaded")
|
||||
|
||||
game:GetService("Players").LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
|
||||
UIS.MouseIconEnabled = false
|
||||
|
||||
UIS.InputEnded:Connect(function(k)
|
||||
if k.KeyCode == Enum.KeyCode.M then
|
||||
local v = not script.Parent.DummyButton.Modal
|
||||
UIS.MouseIconEnabled = v
|
||||
script.Parent.CrosshairLabel.Visible = not v
|
||||
script.Parent.DummyButton.Modal = v
|
||||
end
|
||||
end)
|
||||
4
src/StarterGui/Crosshair/init.meta.json
Normal file
4
src/StarterGui/Crosshair/init.meta.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"className": "ScreenGui",
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
79
src/StarterGui/Game_UI/LocalScript.client.lua
Normal file
79
src/StarterGui/Game_UI/LocalScript.client.lua
Normal file
@@ -0,0 +1,79 @@
|
||||
if not game:IsLoaded() then
|
||||
game.Loaded:Wait()
|
||||
end
|
||||
|
||||
local ui = script.Parent
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local UIS = game:GetService("UserInputService")
|
||||
|
||||
ReplicatedStorage:WaitForChild("Objects"):WaitForChild("MLLoaded")
|
||||
|
||||
local cd = ReplicatedStorage.Objects.ChunkDebug:Clone()
|
||||
local sky = ReplicatedStorage.Objects.Sky:Clone()
|
||||
local base = ReplicatedStorage.Objects.FakeBaseplate:Clone()
|
||||
|
||||
|
||||
cd.Parent = game:GetService("Workspace"):FindFirstChildOfClass("Terrain")
|
||||
sky.Parent = game:GetService("Workspace"):FindFirstChildOfClass("Terrain")
|
||||
base.Parent = game:GetService("Workspace"):FindFirstChildOfClass("Terrain")
|
||||
|
||||
local PM = require(ReplicatedStorage.Shared.PlacementManager)
|
||||
|
||||
UIS.InputEnded:Connect(function(input: InputObject, gameProcessedEvent: boolean)
|
||||
if input.UserInputType == Enum.UserInputType.MouseButton1 then
|
||||
local mouseBlock = PM:GetBlockAtMouse()
|
||||
if not mouseBlock then return end
|
||||
PM:BreakBlock(mouseBlock.chunk.X, mouseBlock.chunk.Y, mouseBlock.chunk.Z, mouseBlock.block.X, mouseBlock.block.Y, mouseBlock.block.Z)
|
||||
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
|
||||
local mouseBlock = PM:GetBlockAtMouse()
|
||||
if not mouseBlock then return end
|
||||
PM:PlaceBlock(mouseBlock.chunk.X, mouseBlock.chunk.Y, mouseBlock.chunk.Z, mouseBlock.block.X, mouseBlock.block.Y, mouseBlock.block.Z, {
|
||||
id = 2,
|
||||
state = {}
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
||||
game:GetService("RunService").RenderStepped:Connect(function(dt)
|
||||
local fps = math.round(1/dt)
|
||||
pcall(function()
|
||||
-- pos in chunks of 32 studs of char
|
||||
local pos = game:GetService("Players").LocalPlayer.Character:GetPivot()
|
||||
local chunk = {
|
||||
x = math.round(pos.X/32),
|
||||
y = math.round(pos.Y/32),
|
||||
z = math.round(pos.Z/32)
|
||||
}
|
||||
|
||||
if math.abs(chunk.x) == 0 then chunk.x = 0 end
|
||||
if math.abs(chunk.y) == 0 then chunk.y = 0 end
|
||||
if math.abs(chunk.z) == 0 then chunk.z = 0 end
|
||||
|
||||
local bpos = {
|
||||
x = math.round(pos.X/4),
|
||||
y = math.round(pos.Y/4),
|
||||
z = math.round(pos.Z/4)
|
||||
}
|
||||
|
||||
if math.abs(bpos.x) == 0 then bpos.x = 0 end
|
||||
if math.abs(bpos.y) == 0 then bpos.y = 0 end
|
||||
if math.abs(bpos.z) == 0 then bpos.z = 0 end
|
||||
|
||||
sky.CFrame = pos
|
||||
ui.DebugUpperText.Text = `Chunk {chunk.x} {chunk.y} {chunk.z}\nPos {bpos.x} {bpos.y} {bpos.z}\n<b>{fps} FPS</b>`
|
||||
|
||||
cd:PivotTo(CFrame.new(
|
||||
chunk.x*32,
|
||||
chunk.y*32,
|
||||
chunk.z*32
|
||||
))
|
||||
|
||||
base.CFrame = CFrame.new(
|
||||
chunk.x*32,
|
||||
-24,
|
||||
chunk.z*32
|
||||
)
|
||||
|
||||
end)
|
||||
end)
|
||||
4
src/StarterGui/Game_UI/init.meta.json
Normal file
4
src/StarterGui/Game_UI/init.meta.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"className": "ScreenGui",
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
25
src/StarterPlayer/StarterPlayerScripts/Actor/Init.client.lua
Normal file
25
src/StarterPlayer/StarterPlayerScripts/Actor/Init.client.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
if not game:IsLoaded() then
|
||||
game.Loaded:Wait()
|
||||
end
|
||||
|
||||
pcall(function()
|
||||
game:GetService("Workspace"):WaitForChild("$blockscraft_server",5):Destroy()
|
||||
end)
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
ReplicatedStorage:WaitForChild("Objects"):WaitForChild("MLLoaded")
|
||||
|
||||
local ML = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("ModLoader"))
|
||||
|
||||
ML.loadModsC()
|
||||
|
||||
do
|
||||
local PM = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("PlacementManager"))
|
||||
PM:Init()
|
||||
end
|
||||
|
||||
do
|
||||
local CM = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("ChunkManager"))
|
||||
CM:Init()
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"className": "Actor",
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
3
src/Workspace/mods/init.meta.json
Normal file
3
src/Workspace/mods/init.meta.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
23
src/Workspace/mods/mc/init.lua
Normal file
23
src/Workspace/mods/mc/init.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
local mod = {
|
||||
name = "Blockscraft",
|
||||
description = "Base Blockscraft blocks",
|
||||
ns = "mc",
|
||||
author = { "ocbwoy3" }
|
||||
}
|
||||
|
||||
local rep = game:GetService("ReplicatedStorage"):WaitForChild("Blocks")
|
||||
local upd = game:GetService("ReplicatedStorage"):WaitForChild("BlockUpdateOperations")
|
||||
|
||||
function mod.init()
|
||||
for a,b in pairs(script.blocks:GetChildren()) do
|
||||
local upop = b:FindFirstChild("BlockUpdateOperation")
|
||||
if upop then
|
||||
upop.Name = b:GetAttribute("n")
|
||||
upop:SetAttribute("n",b:GetAttribute("n"))
|
||||
upop.Parent = upd
|
||||
end
|
||||
b:Clone().Parent = rep
|
||||
end
|
||||
end
|
||||
|
||||
return mod
|
||||
3
src/Workspace/mods/mc/init.meta.json
Normal file
3
src/Workspace/mods/mc/init.meta.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
3
src/Workspace/mods/mc/upds/BlockUpdateOperation.lua
Normal file
3
src/Workspace/mods/mc/upds/BlockUpdateOperation.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
return function(p: typeof(script.Parent.Parent.blocks["mc:grass_block"]))
|
||||
p.block.Grass.Color = Color3.new(p:GetAttribute("x"),p:GetAttribute("x"),p:GetAttribute("x"))
|
||||
end
|
||||
3
src/Workspace/mods/mc/upds/init.meta.json
Normal file
3
src/Workspace/mods/mc/upds/init.meta.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
Reference in New Issue
Block a user