Skip to content

Commit 1777d18

Browse files
authored
Merge pull request #246 from Architector4/patch-constructoring-out-of-bounds
Prevent Constructor from building out of bounds
2 parents 4f4c2b5 + 75d052b commit 1777d18

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

Data/Base.rte/Devices/Tools/Constructor/Constructor.lua

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ function Update(self)
471471

472472
if cursorMovement:MagnitudeIsGreaterThan(0) then
473473
self.cursor = self.cursor + (mouseControlled and cursorMovement or cursorMovement:SetMagnitude(self.cursorMoveSpeed * (aiming and 0.5 or 1)));
474+
475+
SceneMan:ForceBounds(self.cursor);
474476
end
475477

476478
local precise = not mouseControlled and aiming;
@@ -562,21 +564,23 @@ function Update(self)
562564
for x = 1, cellSize do
563565
for y = 1, cellSize do
564566
local pos = Vector(startPos.X + x, startPos.Y + y);
565-
local strengthRatio = SceneMan:GetMaterialFromID(SceneMan:GetTerrMatter(pos.X, pos.Y)).StructuralIntegrity/self.digStrength;
566-
if strengthRatio < 1 and SceneMan:GetMOIDPixel(pos.X, pos.Y) == rte.NoMOID then
567-
local name = "";
568-
if bx + x == 0 or bx + x == self.buildList[1][4] - 1 or by + y == 0 or by + y == self.buildList[1][4] - 1 then
569-
name = "Base.rte/Constructor Border Tile " .. math.random(4);
570-
else
571-
name = "Base.rte/Constructor Tile " .. math.random(16);
572-
end
573-
574-
local terrainObject = CreateTerrainObject(name);
575-
terrainObject.Pos = pos;
576-
SceneMan:AddSceneObject(terrainObject);
567+
if SceneMan:IsWithinBounds(pos.X, pos.Y, 0) then
568+
local strengthRatio = SceneMan:GetMaterialFromID(SceneMan:GetTerrMatter(pos.X, pos.Y)).StructuralIntegrity/self.digStrength;
569+
if strengthRatio < 1 and SceneMan:GetMOIDPixel(pos.X, pos.Y) == rte.NoMOID then
570+
local name = "";
571+
if bx + x == 0 or bx + x == self.buildList[1][4] - 1 or by + y == 0 or by + y == self.buildList[1][4] - 1 then
572+
name = "Base.rte/Constructor Border Tile " .. math.random(4);
573+
else
574+
name = "Base.rte/Constructor Tile " .. math.random(16);
575+
end
577576

578-
didBuild = true;
579-
totalCost = 1 - strengthRatio;
577+
local terrainObject = CreateTerrainObject(name);
578+
terrainObject.Pos = pos;
579+
SceneMan:AddSceneObject(terrainObject);
580+
581+
didBuild = true;
582+
totalCost = 1 - strengthRatio;
583+
end
580584
end
581585
end
582586
end

0 commit comments

Comments
 (0)