Compare commits
4 Commits
da7de7b08a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bc62f8bd70 | |||
| 4785795640 | |||
| 2a0dd51659 | |||
| 2c41f40151 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
Packages/
|
Packages/
|
||||||
|
ServerPackages/
|
||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
|||||||
[submodule "ThirdParty/Character-Realism"]
|
|
||||||
path = ThirdParty/Character-Realism
|
|
||||||
url = https://github.com/MaximumADHD/Character-Realism
|
|
||||||
@@ -13,6 +13,7 @@ local Globals = require(script.Parent:WaitForChild("Globals"))
|
|||||||
|
|
||||||
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RecieveChunkPacket")
|
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RecieveChunkPacket")
|
||||||
local tickremote = game:GetService("ReplicatedStorage"):WaitForChild("Tick")
|
local tickremote = game:GetService("ReplicatedStorage"):WaitForChild("Tick")
|
||||||
|
local Players = game:GetService("Players")
|
||||||
|
|
||||||
local ChunkFolder = Instance.new("Folder")
|
local ChunkFolder = Instance.new("Folder")
|
||||||
ChunkFolder.Name = "$blockscraft_client"
|
ChunkFolder.Name = "$blockscraft_client"
|
||||||
@@ -23,7 +24,7 @@ local CHUNK_RADIUS = Globals.RenderDistance or 5
|
|||||||
local LOAD_BATCH = Globals.LoadBatch or 8
|
local LOAD_BATCH = Globals.LoadBatch or 8
|
||||||
local RESYNC_INTERVAL = Globals.ResyncInterval or 5
|
local RESYNC_INTERVAL = Globals.ResyncInterval or 5
|
||||||
local RESYNC_RADIUS = Globals.ResyncRadius or 2
|
local RESYNC_RADIUS = Globals.ResyncRadius or 2
|
||||||
local DEBUG_RESYNC = true
|
local DEBUG_RESYNC = false
|
||||||
local FORCELOAD_CHUNKS = {
|
local FORCELOAD_CHUNKS = {
|
||||||
{0, 1, 0}
|
{0, 1, 0}
|
||||||
}
|
}
|
||||||
@@ -35,7 +36,11 @@ local lastChunkKey: string? = nil
|
|||||||
local lastHeavyTick = 0
|
local lastHeavyTick = 0
|
||||||
local HEAVY_TICK_INTERVAL = 1.5
|
local HEAVY_TICK_INTERVAL = 1.5
|
||||||
local lastUnloadSweep = 0
|
local lastUnloadSweep = 0
|
||||||
local UNLOAD_SWEEP_INTERVAL = 1.5
|
local UNLOAD_SWEEP_INTERVAL = 3 -- slower sweep cadence
|
||||||
|
local MAX_LOADED_CHUNKS = 0
|
||||||
|
local SPAWN_CHUNK_KEY: string? = nil
|
||||||
|
local playerFrozen = false
|
||||||
|
local storedMovementState = nil
|
||||||
|
|
||||||
local function worldToChunkCoord(v: number): number
|
local function worldToChunkCoord(v: number): number
|
||||||
return math.floor((v + 16) / 32)
|
return math.floor((v + 16) / 32)
|
||||||
@@ -53,6 +58,11 @@ do
|
|||||||
table.sort(CHUNK_OFFSETS, function(a, b)
|
table.sort(CHUNK_OFFSETS, function(a, b)
|
||||||
return a[4] < b[4]
|
return a[4] < b[4]
|
||||||
end)
|
end)
|
||||||
|
MAX_LOADED_CHUNKS = math.max(1, math.floor(#CHUNK_OFFSETS * 2)) -- tighter cap than full render cube
|
||||||
|
if FORCELOAD_CHUNKS[1] then
|
||||||
|
local forced = FORCELOAD_CHUNKS[1]
|
||||||
|
SPAWN_CHUNK_KEY = `{forced[1]},{forced[2]},{forced[3]}`
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChunkManager:UnloadAllNow()
|
function ChunkManager:UnloadAllNow()
|
||||||
@@ -77,6 +87,126 @@ local function Swait(l)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function setCharacterFrozen(shouldFreeze: boolean)
|
||||||
|
local player = Players.LocalPlayer
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local character = player.Character
|
||||||
|
if not character then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local humanoid = character:FindFirstChildOfClass("Humanoid")
|
||||||
|
local root = character:FindFirstChild("HumanoidRootPart")
|
||||||
|
if not humanoid or not root then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if shouldFreeze == playerFrozen then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if shouldFreeze then
|
||||||
|
if not storedMovementState then
|
||||||
|
storedMovementState = {
|
||||||
|
walkSpeed = humanoid.WalkSpeed,
|
||||||
|
autoRotate = humanoid.AutoRotate,
|
||||||
|
}
|
||||||
|
if humanoid.UseJumpPower then
|
||||||
|
storedMovementState.jumpPower = humanoid.JumpPower
|
||||||
|
else
|
||||||
|
storedMovementState.jumpHeight = humanoid.JumpHeight
|
||||||
|
end
|
||||||
|
end
|
||||||
|
humanoid.AutoRotate = false
|
||||||
|
humanoid.WalkSpeed = 0
|
||||||
|
if humanoid.UseJumpPower then
|
||||||
|
humanoid.JumpPower = 0
|
||||||
|
else
|
||||||
|
humanoid.JumpHeight = 0
|
||||||
|
end
|
||||||
|
root.Anchored = true
|
||||||
|
else
|
||||||
|
root.Anchored = false
|
||||||
|
if storedMovementState then
|
||||||
|
humanoid.AutoRotate = storedMovementState.autoRotate
|
||||||
|
humanoid.WalkSpeed = storedMovementState.walkSpeed
|
||||||
|
if humanoid.UseJumpPower and storedMovementState.jumpPower then
|
||||||
|
humanoid.JumpPower = storedMovementState.jumpPower
|
||||||
|
elseif storedMovementState.jumpHeight then
|
||||||
|
humanoid.JumpHeight = storedMovementState.jumpHeight
|
||||||
|
end
|
||||||
|
end
|
||||||
|
storedMovementState = nil
|
||||||
|
end
|
||||||
|
playerFrozen = shouldFreeze
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getLocalPlayerChunkPos()
|
||||||
|
local player = Players.LocalPlayer
|
||||||
|
if not player then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local character = player.Character
|
||||||
|
if not character then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local root = character:FindFirstChild("HumanoidRootPart")
|
||||||
|
if not root then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local pos = root.Position
|
||||||
|
return {
|
||||||
|
x = worldToChunkCoord(pos.X),
|
||||||
|
y = worldToChunkCoord(pos.Y),
|
||||||
|
z = worldToChunkCoord(pos.Z)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function isWithinRenderDistance(chunkPos: Vector3, centerChunkPos): boolean
|
||||||
|
if not centerChunkPos then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return math.abs(chunkPos.X - centerChunkPos.x) <= CHUNK_RADIUS
|
||||||
|
and math.abs(chunkPos.Y - centerChunkPos.y) <= CHUNK_RADIUS
|
||||||
|
and math.abs(chunkPos.Z - centerChunkPos.z) <= CHUNK_RADIUS
|
||||||
|
end
|
||||||
|
|
||||||
|
local function shouldSkipUnload(key: string): boolean
|
||||||
|
return SPAWN_CHUNK_KEY ~= nil and key == SPAWN_CHUNK_KEY
|
||||||
|
end
|
||||||
|
|
||||||
|
local function scheduleChunkUnload(key: string, chunk)
|
||||||
|
if not chunk or unloadingChunks[key] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
unloadingChunks[key] = true
|
||||||
|
task.defer(function()
|
||||||
|
chunk:Unload()
|
||||||
|
chunk:Destroy()
|
||||||
|
Chunk.AllChunks[key] = nil
|
||||||
|
unloadingChunks[key] = nil
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function evictOutOfRangeChunks(centerChunkPos)
|
||||||
|
if not centerChunkPos then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local loadedCount = 0
|
||||||
|
for key, loadedChunk in pairs(Chunk.AllChunks) do
|
||||||
|
if loadedChunk.loaded and not shouldSkipUnload(key) then
|
||||||
|
local inRange = isWithinRenderDistance(loadedChunk.pos, centerChunkPos)
|
||||||
|
if inRange then
|
||||||
|
loadedCount += 1
|
||||||
|
if loadedCount > MAX_LOADED_CHUNKS then
|
||||||
|
scheduleChunkUnload(key, loadedChunk)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
scheduleChunkUnload(key, loadedChunk)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function ChunkManager:GetChunk(x, y, z)
|
function ChunkManager:GetChunk(x, y, z)
|
||||||
local key = `{x},{y},{z}`
|
local key = `{x},{y},{z}`
|
||||||
if Chunk.AllChunks[key] then
|
if Chunk.AllChunks[key] then
|
||||||
@@ -112,7 +242,10 @@ local function ensureNeighboringChunksLoaded(x, y, z)
|
|||||||
|
|
||||||
for _, offset in ipairs(offsets) do
|
for _, offset in ipairs(offsets) do
|
||||||
local nx, ny, nz = x + offset[1], y + offset[2], z + offset[3]
|
local nx, ny, nz = x + offset[1], y + offset[2], z + offset[3]
|
||||||
ChunkManager:GetChunk(nx, ny, nz):Tick()
|
local neighbor = ChunkManager:GetChunk(nx, ny, nz)
|
||||||
|
if neighbor then
|
||||||
|
neighbor:Tick()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -136,6 +269,7 @@ function ChunkManager:LoadChunk(x, y, z)
|
|||||||
chunk.instance = instance
|
chunk.instance = instance
|
||||||
chunk.loaded = true
|
chunk.loaded = true
|
||||||
unloadingChunks[key] = nil
|
unloadingChunks[key] = nil
|
||||||
|
evictOutOfRangeChunks(getLocalPlayerChunkPos())
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -251,7 +385,7 @@ end
|
|||||||
|
|
||||||
function ChunkManager:Tick()
|
function ChunkManager:Tick()
|
||||||
ChunkManager:ForceTick()
|
ChunkManager:ForceTick()
|
||||||
local player = game:GetService("Players").LocalPlayer
|
local player = Players.LocalPlayer
|
||||||
if not player.Character then
|
if not player.Character then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -263,6 +397,7 @@ function ChunkManager:Tick()
|
|||||||
z = worldToChunkCoord(pos.Z)
|
z = worldToChunkCoord(pos.Z)
|
||||||
}
|
}
|
||||||
local ck = `{chunkPos.x},{chunkPos.y},{chunkPos.z}`
|
local ck = `{chunkPos.x},{chunkPos.y},{chunkPos.z}`
|
||||||
|
local currentChunk = Chunk.AllChunks[ck]
|
||||||
local now = tick()
|
local now = tick()
|
||||||
local shouldHeavyTick = (ck ~= lastChunkKey) or (now - lastHeavyTick >= HEAVY_TICK_INTERVAL)
|
local shouldHeavyTick = (ck ~= lastChunkKey) or (now - lastHeavyTick >= HEAVY_TICK_INTERVAL)
|
||||||
lastChunkKey = ck
|
lastChunkKey = ck
|
||||||
@@ -270,26 +405,29 @@ function ChunkManager:Tick()
|
|||||||
lastHeavyTick = now
|
lastHeavyTick = now
|
||||||
end
|
end
|
||||||
|
|
||||||
|
setCharacterFrozen(not (currentChunk and currentChunk.loaded))
|
||||||
|
|
||||||
if shouldHeavyTick then
|
if shouldHeavyTick then
|
||||||
task.defer(function()
|
task.defer(function()
|
||||||
local processed = 0
|
local processed = 0
|
||||||
for _, offset in ipairs(CHUNK_OFFSETS) do
|
for _, offset in ipairs(CHUNK_OFFSETS) do
|
||||||
local cx, cy, cz = chunkPos.x + offset[1], chunkPos.y + offset[2], chunkPos.z + offset[3]
|
local cx, cy, cz = chunkPos.x + offset[1], chunkPos.y + offset[2], chunkPos.z + offset[3]
|
||||||
local chunk = ChunkManager:GetChunk(cx, cy, cz)
|
local chunk = ChunkManager:GetChunk(cx, cy, cz)
|
||||||
chunk.inhabitedTime = now
|
if chunk then
|
||||||
if not chunk.loaded then
|
chunk.inhabitedTime = now
|
||||||
ChunkManager:LoadChunk(cx, cy, cz)
|
if not chunk.loaded then
|
||||||
processed += 1
|
ChunkManager:LoadChunk(cx, cy, cz)
|
||||||
if processed % LOAD_BATCH == 0 then
|
processed += 1
|
||||||
Swait(1)
|
if processed % LOAD_BATCH == 0 then
|
||||||
|
Swait(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
local current = Chunk.AllChunks[ck]
|
if currentChunk then
|
||||||
if current then
|
currentChunk.inhabitedTime = now
|
||||||
current.inhabitedTime = now
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -318,14 +456,8 @@ function ChunkManager:Tick()
|
|||||||
if now - lastUnloadSweep >= UNLOAD_SWEEP_INTERVAL then
|
if now - lastUnloadSweep >= UNLOAD_SWEEP_INTERVAL then
|
||||||
lastUnloadSweep = now
|
lastUnloadSweep = now
|
||||||
for key, loadedChunk in pairs(Chunk.AllChunks) do
|
for key, loadedChunk in pairs(Chunk.AllChunks) do
|
||||||
if now - loadedChunk.inhabitedTime > 15 and not unloadingChunks[key] then
|
if now - loadedChunk.inhabitedTime > 30 and not unloadingChunks[key] and not shouldSkipUnload(key) then -- keep chunks around longer before unloading
|
||||||
unloadingChunks[key] = true
|
scheduleChunkUnload(key, loadedChunk)
|
||||||
task.defer(function()
|
|
||||||
loadedChunk:Unload()
|
|
||||||
loadedChunk:Destroy()
|
|
||||||
Chunk.AllChunks[key] = nil
|
|
||||||
unloadingChunks[key] = nil
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
130
ReplicatedStorage/Shared/ClientState.lua
Normal file
130
ReplicatedStorage/Shared/ClientState.lua
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
--!native
|
||||||
|
--!optimize 2
|
||||||
|
|
||||||
|
local RunService = game:GetService("RunService")
|
||||||
|
|
||||||
|
if RunService:IsServer() then
|
||||||
|
error("ClientState can only be required on the client")
|
||||||
|
end
|
||||||
|
|
||||||
|
local Players = game:GetService("Players")
|
||||||
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
|
|
||||||
|
local Replica = require(ReplicatedStorage.Packages.replica)
|
||||||
|
|
||||||
|
local ClientState = {}
|
||||||
|
|
||||||
|
local HOTBAR_SIZE = 10
|
||||||
|
|
||||||
|
local localPlayer = Players.LocalPlayer
|
||||||
|
local replicaForPlayer = nil
|
||||||
|
local changed = Instance.new("BindableEvent")
|
||||||
|
|
||||||
|
local function fireChanged()
|
||||||
|
changed:Fire()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onReplicaNew(replica)
|
||||||
|
local tags = replica.Tags or {}
|
||||||
|
if tags.UserId ~= localPlayer.UserId and tags.Player ~= localPlayer then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
replicaForPlayer = replica
|
||||||
|
replica:OnChange(fireChanged)
|
||||||
|
fireChanged()
|
||||||
|
end
|
||||||
|
|
||||||
|
Replica.OnNew("ClientState", onReplicaNew)
|
||||||
|
Replica.RequestData()
|
||||||
|
|
||||||
|
function ClientState:IsReady(): boolean
|
||||||
|
return replicaForPlayer ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientState:GetReplica()
|
||||||
|
return replicaForPlayer
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientState:GetSelectedSlot(): number?
|
||||||
|
if not replicaForPlayer then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return replicaForPlayer.Data.selectedSlot
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getInventory()
|
||||||
|
return replicaForPlayer and replicaForPlayer.Data.inventory or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientState:GetItemInfo(blockId: any)
|
||||||
|
if not replicaForPlayer or not blockId then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local inv = getInventory()
|
||||||
|
local entry = inv and inv[tostring(blockId)]
|
||||||
|
if not entry then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
id = tostring(blockId),
|
||||||
|
name = entry.name or tostring(blockId),
|
||||||
|
count = entry.count,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientState:GetHotbarSlots(): {string}
|
||||||
|
if not replicaForPlayer then
|
||||||
|
local slots = table.create(HOTBAR_SIZE)
|
||||||
|
for i = 1, HOTBAR_SIZE do
|
||||||
|
slots[i] = ""
|
||||||
|
end
|
||||||
|
return slots
|
||||||
|
end
|
||||||
|
|
||||||
|
return replicaForPlayer.Data.hotbar or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientState:GetSlotInfo(slot: number)
|
||||||
|
if not replicaForPlayer then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local hotbar = replicaForPlayer.Data.hotbar
|
||||||
|
if not hotbar then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local id = hotbar[slot]
|
||||||
|
if not id then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return ClientState:GetItemInfo(id)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientState:GetSelectedBlock()
|
||||||
|
if not replicaForPlayer then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local slot = ClientState:GetSelectedSlot()
|
||||||
|
if not slot then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return ClientState:GetSlotInfo(slot)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientState:SetSelectedSlot(slot: number)
|
||||||
|
if not replicaForPlayer then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local hotbar = replicaForPlayer.Data.hotbar
|
||||||
|
if not hotbar then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if slot and slot >= 1 and slot <= HOTBAR_SIZE then
|
||||||
|
replicaForPlayer:FireServer("SelectHotbarSlot", slot)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ClientState.Changed = changed.Event
|
||||||
|
|
||||||
|
return ClientState
|
||||||
@@ -6,7 +6,7 @@ local PlacementManager = {}
|
|||||||
local ChunkManager = require("./ChunkManager")
|
local ChunkManager = require("./ChunkManager")
|
||||||
local Util = require("./Util")
|
local Util = require("./Util")
|
||||||
|
|
||||||
local DEBUG_PLACEMENT = true
|
local DEBUG_PLACEMENT = false
|
||||||
local function debugPlacementLog(...: any)
|
local function debugPlacementLog(...: any)
|
||||||
if DEBUG_PLACEMENT then
|
if DEBUG_PLACEMENT then
|
||||||
Util.StudioLog(...)
|
Util.StudioLog(...)
|
||||||
@@ -79,7 +79,7 @@ local function findBlockRoot(inst: Instance, chunkFolder: Instance): Instance?
|
|||||||
if current:IsA("BasePart") then
|
if current:IsA("BasePart") then
|
||||||
return current
|
return current
|
||||||
end
|
end
|
||||||
current = current.Parent
|
current = current.Parent
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -265,13 +265,15 @@ local function ensureChunkFolder(): Instance?
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Gets the block and normalid of the block (and surface) the player is looking at
|
-- Gets the block and normalid of the block (and surface) the player is looking at
|
||||||
function PlacementManager:Raycast()
|
function PlacementManager:Raycast(skipSelection: boolean?)
|
||||||
if not Mouse then
|
if not Mouse then
|
||||||
Mouse = game:GetService("Players").LocalPlayer:GetMouse()
|
Mouse = game:GetService("Players").LocalPlayer:GetMouse()
|
||||||
end
|
end
|
||||||
local chunkFolder = ensureChunkFolder()
|
local chunkFolder = ensureChunkFolder()
|
||||||
if not chunkFolder then
|
if not chunkFolder then
|
||||||
clearSelection("chunk folder missing")
|
if not skipSelection then
|
||||||
|
clearSelection("chunk folder missing")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -285,7 +287,9 @@ function PlacementManager:Raycast()
|
|||||||
local ray = Mouse.UnitRay
|
local ray = Mouse.UnitRay
|
||||||
local result = workspace:Raycast(ray.Origin, ray.Direction * MAX_REACH, raycastParams)
|
local result = workspace:Raycast(ray.Origin, ray.Direction * MAX_REACH, raycastParams)
|
||||||
if not result then
|
if not result then
|
||||||
clearSelection("raycast miss")
|
if not skipSelection then
|
||||||
|
clearSelection("raycast miss")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
debugPlacementLog("[PLACE][CLIENT][RAYCAST]", "miss")
|
debugPlacementLog("[PLACE][CLIENT][RAYCAST]", "miss")
|
||||||
return
|
return
|
||||||
@@ -293,7 +297,9 @@ function PlacementManager:Raycast()
|
|||||||
|
|
||||||
local objLookingAt = result.Instance
|
local objLookingAt = result.Instance
|
||||||
if not objLookingAt then
|
if not objLookingAt then
|
||||||
clearSelection("raycast nil instance")
|
if not skipSelection then
|
||||||
|
clearSelection("raycast nil instance")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
debugPlacementWarn("[PLACE][CLIENT][RAYCAST]", "nil instance in result")
|
debugPlacementWarn("[PLACE][CLIENT][RAYCAST]", "nil instance in result")
|
||||||
return
|
return
|
||||||
@@ -308,7 +314,9 @@ function PlacementManager:Raycast()
|
|||||||
"parent",
|
"parent",
|
||||||
objLookingAt.Parent and objLookingAt.Parent:GetFullName() or "nil"
|
objLookingAt.Parent and objLookingAt.Parent:GetFullName() or "nil"
|
||||||
)
|
)
|
||||||
clearSelection("target not in chunk folder")
|
if not skipSelection then
|
||||||
|
clearSelection("target not in chunk folder")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -318,7 +326,9 @@ function PlacementManager:Raycast()
|
|||||||
"chunk flagged ns",
|
"chunk flagged ns",
|
||||||
hitChunkFolder:GetFullName()
|
hitChunkFolder:GetFullName()
|
||||||
)
|
)
|
||||||
clearSelection("target chunk marked ns")
|
if not skipSelection then
|
||||||
|
clearSelection("target chunk marked ns")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -327,7 +337,9 @@ function PlacementManager:Raycast()
|
|||||||
local blockRoot = findBlockRoot(objLookingAt, chunkFolder) or objLookingAt
|
local blockRoot = findBlockRoot(objLookingAt, chunkFolder) or objLookingAt
|
||||||
local chunkName, blockName = findChunkAndBlock(blockRoot)
|
local chunkName, blockName = findChunkAndBlock(blockRoot)
|
||||||
if not chunkName or not blockName then
|
if not chunkName or not blockName then
|
||||||
clearSelection("failed to resolve chunk/block")
|
if not skipSelection then
|
||||||
|
clearSelection("failed to resolve chunk/block")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -338,7 +350,9 @@ function PlacementManager:Raycast()
|
|||||||
return Util.BlockPosStringToCoords(blockName)
|
return Util.BlockPosStringToCoords(blockName)
|
||||||
end)
|
end)
|
||||||
if not okChunk or not okBlock then
|
if not okChunk or not okBlock then
|
||||||
clearSelection("failed to parse chunk/block names")
|
if not skipSelection then
|
||||||
|
clearSelection("failed to parse chunk/block names")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -347,7 +361,9 @@ function PlacementManager:Raycast()
|
|||||||
|
|
||||||
-- block is being optimistically broken, do not highlight it
|
-- block is being optimistically broken, do not highlight it
|
||||||
if getPendingBreak(chunkKey, blockKey) then
|
if getPendingBreak(chunkKey, blockKey) then
|
||||||
clearSelection("block pending break")
|
if not skipSelection then
|
||||||
|
clearSelection("block pending break")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -356,22 +372,28 @@ function PlacementManager:Raycast()
|
|||||||
local chunk = ChunkManager:GetChunk(chunkCoords.X, chunkCoords.Y, chunkCoords.Z)
|
local chunk = ChunkManager:GetChunk(chunkCoords.X, chunkCoords.Y, chunkCoords.Z)
|
||||||
local blockData = chunk and chunk:GetBlockAt(blockCoords.X, blockCoords.Y, blockCoords.Z)
|
local blockData = chunk and chunk:GetBlockAt(blockCoords.X, blockCoords.Y, blockCoords.Z)
|
||||||
if not blockData or blockData == 0 or blockData.id == 0 then
|
if not blockData or blockData == 0 or blockData.id == 0 then
|
||||||
clearSelection("block missing/air")
|
if not skipSelection then
|
||||||
|
clearSelection("block missing/air")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local blockInstance = resolveBlockInstance(chunkFolder, chunkName, blockName) or blockRoot
|
local blockInstance = resolveBlockInstance(chunkFolder, chunkName, blockName) or blockRoot
|
||||||
if not blockInstance then
|
if not blockInstance then
|
||||||
clearSelection("missing block instance")
|
if not skipSelection then
|
||||||
|
clearSelection("missing block instance")
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
lastRaycastFailure = nil
|
lastRaycastFailure = nil
|
||||||
if lastSelectedChunkKey ~= chunkKey or lastSelectedBlockKey ~= blockKey then
|
if not skipSelection then
|
||||||
setSelection(blockInstance, PlacementManager.ChunkFolder)
|
if lastSelectedChunkKey ~= chunkKey or lastSelectedBlockKey ~= blockKey then
|
||||||
lastSelectedChunkKey = chunkKey
|
setSelection(blockInstance, PlacementManager.ChunkFolder)
|
||||||
lastSelectedBlockKey = blockKey
|
lastSelectedChunkKey = chunkKey
|
||||||
|
lastSelectedBlockKey = blockKey
|
||||||
|
end
|
||||||
end
|
end
|
||||||
script.RaycastResult.Value = objLookingAt
|
script.RaycastResult.Value = objLookingAt
|
||||||
lastNormalId = vectorToNormalId(result.Normal)
|
lastNormalId = vectorToNormalId(result.Normal)
|
||||||
@@ -400,6 +422,10 @@ local tickRemote = game:GetService("ReplicatedStorage").Tick
|
|||||||
-- FIRES REMOTE
|
-- FIRES REMOTE
|
||||||
function PlacementManager:PlaceBlock(cx, cy, cz, x, y, z, blockId: string)
|
function PlacementManager:PlaceBlock(cx, cy, cz, x, y, z, blockId: string)
|
||||||
debugPlacementLog("[PLACE][CLIENT][PLACE_CALL]", "chunk", cx, cy, cz, "block", x, y, z, "blockId", blockId)
|
debugPlacementLog("[PLACE][CLIENT][PLACE_CALL]", "chunk", cx, cy, cz, "block", x, y, z, "blockId", blockId)
|
||||||
|
if blockId == "hand" then
|
||||||
|
debugPlacementWarn("[PLACE][CLIENT][REJECT]", "hand cannot place")
|
||||||
|
return
|
||||||
|
end
|
||||||
if typeof(cx) ~= "number" or typeof(cy) ~= "number" or typeof(cz) ~= "number" then
|
if typeof(cx) ~= "number" or typeof(cy) ~= "number" or typeof(cz) ~= "number" then
|
||||||
debugPlacementWarn("[PLACE][CLIENT][REJECT]", "chunk type", cx, cy, cz, x, y, z, blockId)
|
debugPlacementWarn("[PLACE][CLIENT][REJECT]", "chunk type", cx, cy, cz, x, y, z, blockId)
|
||||||
return
|
return
|
||||||
@@ -551,14 +577,16 @@ local function applyBreakBlockLocal(cx, cy, cz, x, y, z)
|
|||||||
chunk:RemoveBlock(x, y, z)
|
chunk:RemoveBlock(x, y, z)
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlacementManager:GetBlockAtMouse(): nil | {chunk:Vector3, block: Vector3}
|
function PlacementManager:GetBlockAtMouse(skipSelection: boolean?): nil | {chunk:Vector3, block: Vector3}
|
||||||
pcall(function()
|
pcall(function()
|
||||||
PlacementManager:Raycast()
|
PlacementManager:Raycast(skipSelection)
|
||||||
end)
|
end)
|
||||||
local selectedPart = PlacementManager:RaycastGetResult()
|
local selectedPart = PlacementManager:RaycastGetResult()
|
||||||
--print(selectedPart and selectedPart:GetFullName() or nil)
|
--print(selectedPart and selectedPart:GetFullName() or nil)
|
||||||
if selectedPart == nil then
|
if selectedPart == nil then
|
||||||
clearSelection()
|
if not skipSelection then
|
||||||
|
clearSelection()
|
||||||
|
end
|
||||||
script.RaycastResult.Value = nil
|
script.RaycastResult.Value = nil
|
||||||
debugPlacementLog("[PLACE][CLIENT][TARGET]", "no selectedPart after raycast", lastRaycastFailure)
|
debugPlacementLog("[PLACE][CLIENT][TARGET]", "no selectedPart after raycast", lastRaycastFailure)
|
||||||
return nil
|
return nil
|
||||||
@@ -607,8 +635,8 @@ function PlacementManager:GetBlockAtMouse(): nil | {chunk:Vector3, block: Vector
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlacementManager:GetTargetAtMouse(): nil | {chunk:Vector3, block: Vector3, normal: Enum.NormalId}
|
function PlacementManager:GetTargetAtMouse(skipSelection: boolean?): nil | {chunk:Vector3, block: Vector3, normal: Enum.NormalId}
|
||||||
local hit = PlacementManager:GetBlockAtMouse()
|
local hit = PlacementManager:GetBlockAtMouse(skipSelection)
|
||||||
if not hit then
|
if not hit then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -621,8 +649,8 @@ function PlacementManager:GetTargetAtMouse(): nil | {chunk:Vector3, block: Vecto
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlacementManager:GetPlacementAtMouse(): nil | {chunk:Vector3, block: Vector3}
|
function PlacementManager:GetPlacementAtMouse(skipSelection: boolean?): nil | {chunk:Vector3, block: Vector3}
|
||||||
local hit = PlacementManager:GetTargetAtMouse()
|
local hit = PlacementManager:GetTargetAtMouse(skipSelection)
|
||||||
if not hit then
|
if not hit then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -647,8 +675,8 @@ function PlacementManager:GetPlacementAtMouse(): nil | {chunk:Vector3, block: Ve
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlacementManager:DebugGetPlacementOrWarn()
|
function PlacementManager:DebugGetPlacementOrWarn(skipSelection: boolean?)
|
||||||
local placement = PlacementManager:GetPlacementAtMouse()
|
local placement = PlacementManager:GetPlacementAtMouse(skipSelection)
|
||||||
if not placement then
|
if not placement then
|
||||||
debugPlacementWarn("[PLACE][CLIENT][REJECT]", "no placement target under mouse", lastRaycastFailure)
|
debugPlacementWarn("[PLACE][CLIENT][REJECT]", "no placement target under mouse", lastRaycastFailure)
|
||||||
end
|
end
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
local RunService = game:GetService("RunService")
|
local RunService = game:GetService("RunService")
|
||||||
local IS_STUDIO = RunService:IsStudio()
|
local IS_STUDIO = RunService:IsStudio()
|
||||||
|
local ENABLE_STUDIO_LOG = false
|
||||||
|
|
||||||
local module = {}
|
local module = {}
|
||||||
|
|
||||||
-- Prints only when running in Studio (avoids noisy live logs)
|
-- Prints only when running in Studio (avoids noisy live logs)
|
||||||
function module.StudioLog(...: any)
|
function module.StudioLog(...: any)
|
||||||
if not IS_STUDIO then
|
if not IS_STUDIO or not ENABLE_STUDIO_LOG then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
print(...)
|
print(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function module.StudioWarn(...: any)
|
function module.StudioWarn(...: any)
|
||||||
if not IS_STUDIO then
|
if not IS_STUDIO or not ENABLE_STUDIO_LOG then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
warn(...)
|
warn(...)
|
||||||
196
ServerScriptService/Actor/ClientState.lua
Normal file
196
ServerScriptService/Actor/ClientState.lua
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
--!native
|
||||||
|
--!optimize 2
|
||||||
|
|
||||||
|
local Players = game:GetService("Players")
|
||||||
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
|
|
||||||
|
local Replica = require(ReplicatedStorage.Packages.replica)
|
||||||
|
|
||||||
|
local ClientStateService = {}
|
||||||
|
|
||||||
|
local HOTBAR_SIZE = 10
|
||||||
|
|
||||||
|
local token = Replica.Token("ClientState")
|
||||||
|
|
||||||
|
local blockCatalog = {}
|
||||||
|
local playerReplicas = {} :: {[Player]: any}
|
||||||
|
local blocksFolder: Folder? = nil
|
||||||
|
local readyConnections = {} :: {[Player]: RBXScriptConnection}
|
||||||
|
|
||||||
|
local function sortBlocks()
|
||||||
|
table.sort(blockCatalog, function(a, b)
|
||||||
|
local na = tonumber(a.id)
|
||||||
|
local nb = tonumber(b.id)
|
||||||
|
if na and nb then
|
||||||
|
return na < nb
|
||||||
|
end
|
||||||
|
if na then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if nb then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return a.id < b.id
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function rebuildBlockCatalog()
|
||||||
|
table.clear(blockCatalog)
|
||||||
|
if not blocksFolder then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, block in ipairs(blocksFolder:GetChildren()) do
|
||||||
|
local id = block:GetAttribute("n")
|
||||||
|
if id ~= nil then
|
||||||
|
local displayName = block:GetAttribute("name") or block:GetAttribute("displayName") or block:GetAttribute("dn") or block.Name
|
||||||
|
table.insert(blockCatalog, {
|
||||||
|
id = tostring(id),
|
||||||
|
name = displayName,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
sortBlocks()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function makeBaseState()
|
||||||
|
local inventory = {}
|
||||||
|
local hotbar = {}
|
||||||
|
|
||||||
|
for _, entry in ipairs(blockCatalog) do
|
||||||
|
inventory[entry.id] = {
|
||||||
|
name = entry.name,
|
||||||
|
count = 999999,
|
||||||
|
}
|
||||||
|
if #hotbar < HOTBAR_SIZE then
|
||||||
|
table.insert(hotbar, entry.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
inventory = inventory,
|
||||||
|
hotbar = hotbar,
|
||||||
|
selectedSlot = #hotbar > 0 and 1 or 0,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function sanitizeSelection(hotbar, selectedSlot)
|
||||||
|
if type(selectedSlot) ~= "number" then
|
||||||
|
return (#hotbar > 0) and 1 or 0
|
||||||
|
end
|
||||||
|
if selectedSlot < 1 or selectedSlot > HOTBAR_SIZE then
|
||||||
|
return (#hotbar > 0) and 1 or 0
|
||||||
|
end
|
||||||
|
return selectedSlot
|
||||||
|
end
|
||||||
|
|
||||||
|
local function refreshReplica(replica)
|
||||||
|
local state = makeBaseState()
|
||||||
|
replica:Set({"inventory"}, state.inventory)
|
||||||
|
replica:Set({"hotbar"}, state.hotbar)
|
||||||
|
replica:Set({"selectedSlot"}, sanitizeSelection(state.hotbar, replica.Data.selectedSlot))
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientStateService:SetBlocksFolder(folder: Folder?)
|
||||||
|
blocksFolder = folder
|
||||||
|
rebuildBlockCatalog()
|
||||||
|
for _, replica in pairs(playerReplicas) do
|
||||||
|
refreshReplica(replica)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientStateService:GetReplica(player: Player)
|
||||||
|
return playerReplicas[player]
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientStateService:GetSelectedBlockId(player: Player)
|
||||||
|
local replica = playerReplicas[player]
|
||||||
|
if not replica then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local data = replica.Data
|
||||||
|
local hotbar = data.hotbar or {}
|
||||||
|
local selectedSlot = sanitizeSelection(hotbar, data.selectedSlot)
|
||||||
|
return hotbar[selectedSlot]
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientStateService:HasInInventory(player: Player, blockId: any): boolean
|
||||||
|
local replica = playerReplicas[player]
|
||||||
|
if not replica or not blockId then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local inv = replica.Data.inventory
|
||||||
|
return inv and inv[tostring(blockId)] ~= nil or false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function handleReplicaEvents(player: Player, replica)
|
||||||
|
replica.OnServerEvent:Connect(function(plr, action, payload)
|
||||||
|
if plr ~= player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if action == "SelectHotbarSlot" then
|
||||||
|
local slot = tonumber(payload)
|
||||||
|
local hotbar = replica.Data.hotbar
|
||||||
|
if not hotbar then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if slot and slot >= 1 and slot <= HOTBAR_SIZE then
|
||||||
|
replica:Set({"selectedSlot"}, slot)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onPlayerAdded(player: Player)
|
||||||
|
local replica = Replica.New({
|
||||||
|
Token = token,
|
||||||
|
Tags = {
|
||||||
|
UserId = player.UserId,
|
||||||
|
Player = player,
|
||||||
|
},
|
||||||
|
Data = makeBaseState(),
|
||||||
|
})
|
||||||
|
|
||||||
|
if Replica.ReadyPlayers[player] then
|
||||||
|
replica:Subscribe(player)
|
||||||
|
else
|
||||||
|
readyConnections[player] = Replica.NewReadyPlayer:Connect(function(newPlayer)
|
||||||
|
if newPlayer ~= player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if readyConnections[player] then
|
||||||
|
readyConnections[player]:Disconnect()
|
||||||
|
readyConnections[player] = nil
|
||||||
|
end
|
||||||
|
replica:Subscribe(player)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
handleReplicaEvents(player, replica)
|
||||||
|
playerReplicas[player] = replica
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onPlayerRemoving(player: Player)
|
||||||
|
local replica = playerReplicas[player]
|
||||||
|
if replica then
|
||||||
|
replica:Destroy()
|
||||||
|
playerReplicas[player] = nil
|
||||||
|
end
|
||||||
|
if readyConnections[player] then
|
||||||
|
readyConnections[player]:Disconnect()
|
||||||
|
readyConnections[player] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClientStateService:Init()
|
||||||
|
rebuildBlockCatalog()
|
||||||
|
|
||||||
|
for _, player in ipairs(Players:GetPlayers()) do
|
||||||
|
onPlayerAdded(player)
|
||||||
|
end
|
||||||
|
Players.PlayerAdded:Connect(onPlayerAdded)
|
||||||
|
Players.PlayerRemoving:Connect(onPlayerRemoving)
|
||||||
|
end
|
||||||
|
|
||||||
|
return ClientStateService
|
||||||
@@ -63,9 +63,7 @@ function TerrainGen:GetChunk(x, y, z)
|
|||||||
if y == 1 then
|
if y == 1 then
|
||||||
for cx = 1, 8 do
|
for cx = 1, 8 do
|
||||||
for cz = 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 = "mc:grass_block", state = {} })
|
||||||
chunk:CreateBlock(cx, 1, cz, { id = 1, state = {} })
|
|
||||||
--chunk:CreateBlock(x, 2, z, { id = 1, state = {} })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -73,9 +71,7 @@ function TerrainGen:GetChunk(x, y, z)
|
|||||||
for cx = 1, 8 do
|
for cx = 1, 8 do
|
||||||
for cy = 1, 8 do
|
for cy = 1, 8 do
|
||||||
for cz = 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 = "mc:dirt_block", state = {} })
|
||||||
chunk:CreateBlock(cx, cy, cz, { id = 2, state = {} })
|
|
||||||
--chunk:CreateBlock(x, 2, z, { id = 1, state = {} })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -93,9 +89,7 @@ function TerrainGen:GetFakeChunk(x, y, z)
|
|||||||
for cy = 1,8 do
|
for cy = 1,8 do
|
||||||
for cx = 1, 8 do
|
for cx = 1, 8 do
|
||||||
for cz = 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 = "invalid", state = {} })
|
||||||
chunk:CreateBlock(cx, cy, cz, { id = -2, state = {} })
|
|
||||||
--chunk:CreateBlock(x, 2, z, { id = 1, state = {} })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2,15 +2,39 @@
|
|||||||
--!optimize 2
|
--!optimize 2
|
||||||
|
|
||||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
|
local ServerStorage = game:GetService("ServerStorage")
|
||||||
|
local ClientStateService = require(script.Parent.ClientState)
|
||||||
|
|
||||||
local Shared = ReplicatedStorage:WaitForChild("Shared")
|
local Shared = ReplicatedStorage:WaitForChild("Shared")
|
||||||
local ModsFolder = ReplicatedStorage:WaitForChild("Mods")
|
local ModsFolder = ReplicatedStorage:WaitForChild("Mods")
|
||||||
|
local BlocksFolderRS = ReplicatedStorage:FindFirstChild("Blocks") or Instance.new("Folder")
|
||||||
|
BlocksFolderRS.Name = "Blocks"
|
||||||
|
BlocksFolderRS.Parent = ReplicatedStorage
|
||||||
|
local BlocksFolderSS = ServerStorage:FindFirstChild("Blocks") or Instance.new("Folder")
|
||||||
|
BlocksFolderSS.Name = "Blocks"
|
||||||
|
BlocksFolderSS.Parent = ServerStorage
|
||||||
|
|
||||||
local Util = require(Shared.Util)
|
local Util = require(Shared.Util)
|
||||||
local TG = require("./ServerChunkManager/TerrainGen")
|
local TG = require(script.TerrainGen)
|
||||||
local Players = game:GetService("Players")
|
local Players = game:GetService("Players")
|
||||||
|
|
||||||
|
local blockIdMap = {}
|
||||||
|
local rebuildBlockIdMap
|
||||||
|
|
||||||
|
local function syncBlocksToServerStorage()
|
||||||
|
BlocksFolderSS:ClearAllChildren()
|
||||||
|
for _, child in ipairs(BlocksFolderRS:GetChildren()) do
|
||||||
|
child:Clone().Parent = BlocksFolderSS
|
||||||
|
end
|
||||||
|
ClientStateService:SetBlocksFolder(BlocksFolderSS)
|
||||||
|
if rebuildBlockIdMap then
|
||||||
|
rebuildBlockIdMap()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
BlocksFolderRS.ChildAdded:Connect(syncBlocksToServerStorage)
|
||||||
|
BlocksFolderRS.ChildRemoved:Connect(syncBlocksToServerStorage)
|
||||||
|
|
||||||
do
|
do
|
||||||
local workspaceModFolder = game:GetService("Workspace"):WaitForChild("mods")
|
local workspaceModFolder = game:GetService("Workspace"):WaitForChild("mods")
|
||||||
|
|
||||||
@@ -22,6 +46,8 @@ end
|
|||||||
|
|
||||||
local ML = require(Shared.ModLoader)
|
local ML = require(Shared.ModLoader)
|
||||||
ML.loadModsS()
|
ML.loadModsS()
|
||||||
|
syncBlocksToServerStorage()
|
||||||
|
ClientStateService:Init()
|
||||||
|
|
||||||
do
|
do
|
||||||
local bv = Instance.new("BoolValue")
|
local bv = Instance.new("BoolValue")
|
||||||
@@ -67,7 +93,7 @@ local tickRemote = ReplicatedStorage.Tick
|
|||||||
local remotes = ReplicatedStorage:WaitForChild("Remotes")
|
local remotes = ReplicatedStorage:WaitForChild("Remotes")
|
||||||
local placeRemote = remotes:WaitForChild("PlaceBlock")
|
local placeRemote = remotes:WaitForChild("PlaceBlock")
|
||||||
local breakRemote = remotes:WaitForChild("BreakBlock")
|
local breakRemote = remotes:WaitForChild("BreakBlock")
|
||||||
local blocksFolder = ReplicatedStorage:WaitForChild("Blocks")
|
local blocksFolder = BlocksFolderSS
|
||||||
local function propogate(a, cx, cy, cz, x, y, z, bd)
|
local function propogate(a, cx, cy, cz, x, y, z, bd)
|
||||||
task.synchronize()
|
task.synchronize()
|
||||||
tickRemote:FireAllClients(a, cx, cy, cz, x, y, z, bd)
|
tickRemote:FireAllClients(a, cx, cy, cz, x, y, z, bd)
|
||||||
@@ -75,9 +101,8 @@ local function propogate(a, cx, cy, cz, x, y, z, bd)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local MAX_REACH = 512
|
local MAX_REACH = 512
|
||||||
local blockIdMap = {}
|
|
||||||
|
|
||||||
local function rebuildBlockIdMap()
|
rebuildBlockIdMap = function()
|
||||||
table.clear(blockIdMap)
|
table.clear(blockIdMap)
|
||||||
for _, block in ipairs(blocksFolder:GetChildren()) do
|
for _, block in ipairs(blocksFolder:GetChildren()) do
|
||||||
local id = block:GetAttribute("n")
|
local id = block:GetAttribute("n")
|
||||||
@@ -113,6 +138,17 @@ local function resolveBlockId(blockId: any): string | number | nil
|
|||||||
return blockIdMap[blockId]
|
return blockIdMap[blockId]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function playerCanUseBlock(player: Player, resolvedId: any): boolean
|
||||||
|
if not ClientStateService:HasInInventory(player, resolvedId) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local selected = ClientStateService:GetSelectedBlockId(player)
|
||||||
|
if not selected then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return tostring(selected) == tostring(resolvedId)
|
||||||
|
end
|
||||||
|
|
||||||
local function getServerChunk(cx: number, cy: number, cz: number)
|
local function getServerChunk(cx: number, cy: number, cz: number)
|
||||||
task.desynchronize()
|
task.desynchronize()
|
||||||
local chunk = TG:GetChunk(cx, cy, cz)
|
local chunk = TG:GetChunk(cx, cy, cz)
|
||||||
@@ -176,6 +212,9 @@ placeRemote.OnServerEvent:Connect(function(player, cx, cy, cz, x, y, z, blockId)
|
|||||||
if not resolvedId then
|
if not resolvedId then
|
||||||
return reject("invalid id")
|
return reject("invalid id")
|
||||||
end
|
end
|
||||||
|
if not playerCanUseBlock(player, resolvedId) then
|
||||||
|
return reject("not in inventory/hotbar")
|
||||||
|
end
|
||||||
|
|
||||||
local blockPos = Util.ChunkPosToCFrame(Vector3.new(cx, cy, cz), Vector3.new(x, y, z)).Position
|
local blockPos = Util.ChunkPosToCFrame(Vector3.new(cx, cy, cz), Vector3.new(x, y, z)).Position
|
||||||
if isBlockInsidePlayer(blockPos) then
|
if isBlockInsidePlayer(blockPos) then
|
||||||
@@ -18,8 +18,7 @@ local PM = require(ReplicatedStorage.Shared.PlacementManager)
|
|||||||
local BlockManager = require(ReplicatedStorage.Shared.ChunkManager.BlockManager)
|
local BlockManager = require(ReplicatedStorage.Shared.ChunkManager.BlockManager)
|
||||||
local PlacementState = require(ReplicatedStorage.Shared.PlacementState)
|
local PlacementState = require(ReplicatedStorage.Shared.PlacementState)
|
||||||
local Util = require(ReplicatedStorage.Shared.Util)
|
local Util = require(ReplicatedStorage.Shared.Util)
|
||||||
|
local ClientState = require(ReplicatedStorage.Shared.ClientState)
|
||||||
local blocksFolder = ReplicatedStorage:WaitForChild("Blocks")
|
|
||||||
|
|
||||||
local HOTBAR_SIZE = 10
|
local HOTBAR_SIZE = 10
|
||||||
|
|
||||||
@@ -53,33 +52,34 @@ local function isTextInputFocused(): boolean
|
|||||||
return config ~= nil and config.IsFocused
|
return config ~= nil and config.IsFocused
|
||||||
end
|
end
|
||||||
|
|
||||||
local function buildHotbarIds(): {string}
|
local function resolveSelectedSlot(slots, desired)
|
||||||
local ids = {}
|
if desired and desired >= 1 and desired <= HOTBAR_SIZE then
|
||||||
local names = {}
|
return desired
|
||||||
for _, block in ipairs(blocksFolder:GetChildren()) do
|
|
||||||
local id = block:GetAttribute("n")
|
|
||||||
if id ~= nil then
|
|
||||||
local n = tonumber(id)
|
|
||||||
if n and n > 0 then
|
|
||||||
local idStr = tostring(n)
|
|
||||||
table.insert(ids, idStr)
|
|
||||||
names[idStr] = block:GetAttribute("displayName") or block:GetAttribute("dn") or block.Name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
table.sort(ids, function(a, b)
|
|
||||||
local na = tonumber(a)
|
|
||||||
local nb = tonumber(b)
|
|
||||||
if na and nb then
|
|
||||||
return na < nb
|
|
||||||
end
|
|
||||||
return a < b
|
|
||||||
end)
|
|
||||||
local slots = table.create(HOTBAR_SIZE)
|
|
||||||
for i = 1, HOTBAR_SIZE do
|
for i = 1, HOTBAR_SIZE do
|
||||||
slots[i] = ids[i] or ""
|
if slots[i] and slots[i] ~= "" then
|
||||||
|
return i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return slots, names
|
return desired or 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local function buildHotbarFromState()
|
||||||
|
local slots = table.create(HOTBAR_SIZE)
|
||||||
|
local names = {}
|
||||||
|
|
||||||
|
for i = 1, HOTBAR_SIZE do
|
||||||
|
local info = ClientState:GetSlotInfo(i)
|
||||||
|
if info then
|
||||||
|
slots[i] = tostring(info.id)
|
||||||
|
names[slots[i]] = info.name or slots[i]
|
||||||
|
else
|
||||||
|
slots[i] = ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local selected = resolveSelectedSlot(slots, ClientState:GetSelectedSlot())
|
||||||
|
return slots, names, selected
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ensurePreviewRig(part: Instance)
|
local function ensurePreviewRig(part: Instance)
|
||||||
@@ -131,42 +131,46 @@ end
|
|||||||
local Hotbar = Roact.Component:extend("Hotbar")
|
local Hotbar = Roact.Component:extend("Hotbar")
|
||||||
|
|
||||||
function Hotbar:init()
|
function Hotbar:init()
|
||||||
|
local slots, names, selected = buildHotbarFromState()
|
||||||
self.state = {
|
self.state = {
|
||||||
slots = nil,
|
slots = slots,
|
||||||
names = nil,
|
names = names,
|
||||||
selected = 1,
|
selected = selected,
|
||||||
}
|
}
|
||||||
local slots, names = buildHotbarIds()
|
|
||||||
self.state.slots = slots
|
|
||||||
self.state.names = names
|
|
||||||
local initialId = slots and slots[1] or ""
|
|
||||||
if initialId and initialId ~= "" then
|
|
||||||
local initialName = names and (names[initialId] or initialId) or initialId
|
|
||||||
PlacementState:SetSelected(initialId, initialName)
|
|
||||||
end
|
|
||||||
|
|
||||||
self._updateSlots = function()
|
self._syncFromClientState = function()
|
||||||
local nextSlots, nextNames = buildHotbarIds()
|
local nextSlots, nextNames, nextSelected = buildHotbarFromState()
|
||||||
|
nextSelected = resolveSelectedSlot(nextSlots, nextSelected or self.state.selected)
|
||||||
self:setState({
|
self:setState({
|
||||||
slots = nextSlots,
|
slots = nextSlots,
|
||||||
names = nextNames,
|
names = nextNames,
|
||||||
|
selected = nextSelected,
|
||||||
})
|
})
|
||||||
|
local rawId = nextSlots[nextSelected] or ""
|
||||||
|
local effectiveId = rawId ~= "" and rawId or "hand"
|
||||||
|
local name = ""
|
||||||
|
if rawId ~= "" then
|
||||||
|
name = nextNames[rawId] or rawId
|
||||||
|
end
|
||||||
|
PlacementState:SetSelected(effectiveId, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
self._setSelected = function(slot: number)
|
self._setSelected = function(slot: number)
|
||||||
if slot < 1 or slot > HOTBAR_SIZE then
|
if slot < 1 or slot > HOTBAR_SIZE then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
ClientState:SetSelectedSlot(slot)
|
||||||
self:setState({
|
self:setState({
|
||||||
selected = slot,
|
selected = slot,
|
||||||
})
|
})
|
||||||
local id = self.state.slots and self.state.slots[slot] or ""
|
local rawId = self.state.slots[slot] or ""
|
||||||
|
local effectiveId = rawId ~= "" and rawId or "hand"
|
||||||
local name = ""
|
local name = ""
|
||||||
if id ~= "" and self.state.names then
|
if rawId ~= "" then
|
||||||
name = self.state.names[id] or id
|
name = self.state.names[rawId] or rawId
|
||||||
end
|
end
|
||||||
Util.StudioLog("[PLACE][CLIENT][SELECT]", "slot", slot, "id", id, "name", name)
|
Util.StudioLog("[PLACE][CLIENT][SELECT]", "slot", slot, "id", effectiveId, "name", name)
|
||||||
PlacementState:SetSelected(id, name)
|
PlacementState:SetSelected(effectiveId, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
self._handleInput = function(input: InputObject, gameProcessedEvent: boolean)
|
self._handleInput = function(input: InputObject, gameProcessedEvent: boolean)
|
||||||
@@ -204,7 +208,7 @@ function Hotbar:init()
|
|||||||
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
|
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
|
||||||
Util.StudioLog("[INPUT][CLIENT]", "MouseButton2", "processed", gameProcessedEvent)
|
Util.StudioLog("[INPUT][CLIENT]", "MouseButton2", "processed", gameProcessedEvent)
|
||||||
-- Allow click even if gameProcessedEvent (UI can set this), but only if we're actually pointing at a block
|
-- Allow click even if gameProcessedEvent (UI can set this), but only if we're actually pointing at a block
|
||||||
local mouseBlock = PM:DebugGetPlacementOrWarn()
|
local mouseBlock = PM:DebugGetPlacementOrWarn(true) -- skip selection outline on right click
|
||||||
if not mouseBlock then
|
if not mouseBlock then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -246,7 +250,7 @@ function Hotbar:init()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local delta = direction > 0 and -1 or 1
|
local delta = direction > 0 and -1 or 1
|
||||||
local nextSlot = math.clamp(self.state.selected + delta, 1, HOTBAR_SIZE)
|
local nextSlot = ((self.state.selected - 1 + delta) % HOTBAR_SIZE) + 1
|
||||||
if nextSlot ~= self.state.selected then
|
if nextSlot ~= self.state.selected then
|
||||||
self._setSelected(nextSlot)
|
self._setSelected(nextSlot)
|
||||||
end
|
end
|
||||||
@@ -258,19 +262,20 @@ end
|
|||||||
|
|
||||||
function Hotbar:didMount()
|
function Hotbar:didMount()
|
||||||
self._connections = {
|
self._connections = {
|
||||||
blocksFolder.ChildAdded:Connect(self._updateSlots),
|
ClientState.Changed:Connect(self._syncFromClientState),
|
||||||
blocksFolder.ChildRemoved:Connect(self._updateSlots),
|
|
||||||
UIS.InputBegan:Connect(self._handleInput),
|
UIS.InputBegan:Connect(self._handleInput),
|
||||||
UIS.InputChanged:Connect(self._handleScroll),
|
UIS.InputChanged:Connect(self._handleScroll),
|
||||||
}
|
}
|
||||||
|
self._syncFromClientState()
|
||||||
self:_refreshViewports()
|
self:_refreshViewports()
|
||||||
-- initialize selection broadcast
|
-- initialize selection broadcast
|
||||||
local id = self.state.slots and self.state.slots[self.state.selected] or ""
|
local rawId = self.state.slots and self.state.slots[self.state.selected] or ""
|
||||||
|
local effectiveId = rawId ~= "" and rawId or "hand"
|
||||||
local name = ""
|
local name = ""
|
||||||
if id ~= "" and self.state.names then
|
if rawId ~= "" and self.state.names then
|
||||||
name = self.state.names[id] or id
|
name = self.state.names[rawId] or rawId
|
||||||
end
|
end
|
||||||
PlacementState:SetSelected(id, name)
|
PlacementState:SetSelected(effectiveId, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hotbar:willUnmount()
|
function Hotbar:willUnmount()
|
||||||
@@ -310,6 +315,7 @@ function Hotbar:render()
|
|||||||
for i = 1, HOTBAR_SIZE do
|
for i = 1, HOTBAR_SIZE do
|
||||||
local id = self.state.slots[i] or ""
|
local id = self.state.slots[i] or ""
|
||||||
local isSelected = i == self.state.selected
|
local isSelected = i == self.state.selected
|
||||||
|
local displayName = id ~= "" and (self.state.names and self.state.names[id] or id) or ""
|
||||||
|
|
||||||
slotElements[`Slot{i-1}`] = Roact.createElement("TextButton", {
|
slotElements[`Slot{i-1}`] = Roact.createElement("TextButton", {
|
||||||
Size = UDim2.fromOffset(50, 50),
|
Size = UDim2.fromOffset(50, 50),
|
||||||
@@ -341,7 +347,7 @@ function Hotbar:render()
|
|||||||
}),
|
}),
|
||||||
IndexLabel = Roact.createElement("TextLabel", {
|
IndexLabel = Roact.createElement("TextLabel", {
|
||||||
BackgroundTransparency = 1,
|
BackgroundTransparency = 1,
|
||||||
Position = UDim2.fromOffset(4, 2),
|
Position = UDim2.fromOffset(8, 4),
|
||||||
Size = UDim2.fromOffset(18, 14),
|
Size = UDim2.fromOffset(18, 14),
|
||||||
Font = Enum.Font.Gotham,
|
Font = Enum.Font.Gotham,
|
||||||
Text = i == 10 and "0" or tostring(i),
|
Text = i == 10 and "0" or tostring(i),
|
||||||
@@ -355,7 +361,7 @@ function Hotbar:render()
|
|||||||
Position = UDim2.fromOffset(4, 26),
|
Position = UDim2.fromOffset(4, 26),
|
||||||
Size = UDim2.new(1, -8, 0, 18),
|
Size = UDim2.new(1, -8, 0, 18),
|
||||||
Font = Enum.Font.GothamBold,
|
Font = Enum.Font.GothamBold,
|
||||||
Text = id,
|
Text = displayName,
|
||||||
TextColor3 = colors.text,
|
TextColor3 = colors.text,
|
||||||
TextSize = 15,
|
TextSize = 15,
|
||||||
TextWrapped = true,
|
TextWrapped = true,
|
||||||
@@ -408,6 +414,7 @@ function Hotbar:render()
|
|||||||
BorderSizePixel = 0,
|
BorderSizePixel = 0,
|
||||||
Position = UDim2.new(0.5, 0, 1, -80-10),
|
Position = UDim2.new(0.5, 0, 1, -80-10),
|
||||||
Size = UDim2.fromOffset(0, 25),
|
Size = UDim2.fromOffset(0, 25),
|
||||||
|
Visible = selectedName ~= "",
|
||||||
}, {
|
}, {
|
||||||
Corner = Roact.createElement("UICorner", {
|
Corner = Roact.createElement("UICorner", {
|
||||||
CornerRadius = UDim.new(0, 8),
|
CornerRadius = UDim.new(0, 8),
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
"ReplicatedStorage": {
|
"ReplicatedStorage": {
|
||||||
"$className": "ReplicatedStorage",
|
"$className": "ReplicatedStorage",
|
||||||
"$ignoreUnknownInstances": true,
|
"$ignoreUnknownInstances": true,
|
||||||
"$path": "src/ReplicatedStorage",
|
"$path": "ReplicatedStorage",
|
||||||
|
|
||||||
"Packages": {
|
"Packages": {
|
||||||
"$className": "Folder",
|
"$className": "Folder",
|
||||||
@@ -17,23 +17,19 @@
|
|||||||
"ReplicatedFirst": {
|
"ReplicatedFirst": {
|
||||||
"$className": "ReplicatedFirst",
|
"$className": "ReplicatedFirst",
|
||||||
"$ignoreUnknownInstances": true,
|
"$ignoreUnknownInstances": true,
|
||||||
"$path": "src/ReplicatedFirst"
|
"$path": "ReplicatedFirst"
|
||||||
},
|
},
|
||||||
|
|
||||||
"ServerScriptService": {
|
"ServerScriptService": {
|
||||||
"$className": "ServerScriptService",
|
"$className": "ServerScriptService",
|
||||||
"$ignoreUnknownInstances": true,
|
"$ignoreUnknownInstances": true,
|
||||||
"$path": "src/ServerScriptService",
|
"$path": "ServerScriptService"
|
||||||
|
|
||||||
"RealismServer": {
|
|
||||||
"$path": "ThirdParty/Character-Realism/Realism.server.lua"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"StarterGui": {
|
"StarterGui": {
|
||||||
"$className": "StarterGui",
|
"$className": "StarterGui",
|
||||||
"$ignoreUnknownInstances": true,
|
"$ignoreUnknownInstances": true,
|
||||||
"$path": "src/StarterGui"
|
"$path": "StarterGui"
|
||||||
},
|
},
|
||||||
|
|
||||||
"StarterPlayer": {
|
"StarterPlayer": {
|
||||||
@@ -43,18 +39,14 @@
|
|||||||
"StarterPlayerScripts": {
|
"StarterPlayerScripts": {
|
||||||
"$className": "StarterPlayerScripts",
|
"$className": "StarterPlayerScripts",
|
||||||
"$ignoreUnknownInstances": true,
|
"$ignoreUnknownInstances": true,
|
||||||
"$path": "src/StarterPlayer/StarterPlayerScripts",
|
"$path": "StarterPlayer/StarterPlayerScripts"
|
||||||
|
|
||||||
"RealismClient": {
|
|
||||||
"$path": "ThirdParty/Character-Realism/RealismClient"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"Workspace": {
|
"Workspace": {
|
||||||
"$className": "Workspace",
|
"$className": "Workspace",
|
||||||
"$ignoreUnknownInstances": true,
|
"$ignoreUnknownInstances": true,
|
||||||
"$path": "src/Workspace"
|
"$path": "Workspace"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
--!native
|
|
||||||
--!optimize 2
|
|
||||||
|
|
||||||
local Players = game:GetService("Players")
|
|
||||||
|
|
||||||
local SCALE = 1.3
|
|
||||||
|
|
||||||
local function applyScale(character: Model)
|
|
||||||
if character.ScaleTo then
|
|
||||||
pcall(function()
|
|
||||||
character:ScaleTo(SCALE)
|
|
||||||
end)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local humanoid = character:FindFirstChildOfClass("Humanoid")
|
|
||||||
if not humanoid then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if humanoid.RigType == Enum.HumanoidRigType.R15 then
|
|
||||||
for _, name in ipairs({"BodyHeightScale", "BodyWidthScale", "BodyDepthScale", "HeadScale"}) do
|
|
||||||
local scaleValue = humanoid:FindFirstChild(name)
|
|
||||||
if scaleValue then
|
|
||||||
scaleValue.Value = SCALE
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function onCharacterAdded(character: Model)
|
|
||||||
character:WaitForChild("Humanoid", 5)
|
|
||||||
applyScale(character)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function onPlayerAdded(player: Player)
|
|
||||||
player.CharacterAdded:Connect(onCharacterAdded)
|
|
||||||
if player.Character then
|
|
||||||
onCharacterAdded(player.Character)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, player in ipairs(Players:GetPlayers()) do
|
|
||||||
onPlayerAdded(player)
|
|
||||||
end
|
|
||||||
|
|
||||||
Players.PlayerAdded:Connect(onPlayerAdded)
|
|
||||||
@@ -7,10 +7,15 @@ name = "evaera/cmdr"
|
|||||||
version = "1.12.0"
|
version = "1.12.0"
|
||||||
dependencies = []
|
dependencies = []
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ivasmigins/replica"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ocbwoy3-development-studios/minecraft-roblox"
|
name = "ocbwoy3-development-studios/minecraft-roblox"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [["cmdr", "evaera/cmdr@1.12.0"], ["roact", "roblox/roact@1.4.4"]]
|
dependencies = [["cmdr", "evaera/cmdr@1.12.0"], ["replica", "ivasmigins/replica@0.1.0"], ["roact", "roblox/roact@1.4.4"]]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "roblox/roact"
|
name = "roblox/roact"
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ realm = "shared"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cmdr = "evaera/cmdr@1.12.0"
|
cmdr = "evaera/cmdr@1.12.0"
|
||||||
roact = "roblox/roact@1.4.4"
|
roact = "roblox/roact@1.4.4"
|
||||||
|
replica = "ivasmigins/replica@0.1.0"
|
||||||
Reference in New Issue
Block a user