Block

A Block represents one block in a Shape or MutableShape (like the Map).

A Block can be built with one of the constructors, but it can also be obtained from a Shape or MutableShape with Shape.GetBlock or MutableShape.GetBlock.

⚠️ A Block obtained from an immutable object (like Shape) is in fact read-only, none of its properties can be set in that case.

Constructors

Block ( Color color, Number3 coordinates optional )
Block ( Color color, number x, number y, number z )
Block ( )

Creates a Block with given color and optional coordinates, { 0, 0, 0 } by default.

Functions

boolean AddNeighbor ( Block block, Face face )
boolean AddNeighbor ( integer paletteIndex, Face face )
boolean AddNeighbor ( Color color, Face face )

Adds a Block to the Block adjacent to the face passed as parameter. You may provide a Block, a palette index to an existing color in the original Shape's Palette, or any color which will be added automatically to the Shape's Palette if needed.

Returns true if a block was successfully added.

⚠️ Won't work with read-only Blocks.

-- add block when Action2 is triggered
Client.Action2 = function()
  -- cast a ray, see if it touches a block
  local impact = Player:CastRay()
  if impact.Block ~= nil then
    -- add block, adjacent to the face that's been touched
    impact.Block:AddNeighbor(Color(200, 0, 200), impact.FaceTouched)
  end
end
nil Remove ( )

Removes the Block from its parent MutableShape.

⚠️ Won't work with read-only Blocks.

-- remove block when Action2 is triggered
Client.Action2 = function()
  -- cast a ray and see if it touches a block
  local impact = Player:CastRay()
  if impact.Block ~= nil then
    -- a Block has been found, remove it
    impact.Block:Remove()
  end
end
nil Replace ( Block block )
nil Replace ( Color color )
nil Replace ( integer paletteIndex )

Replaces the Block visual properties to be either: identical to the ones from the given Block, to the given Color, or to the ones located at given palette index.

The position remains the same.

⚠️ Only works with blocks from a MutableShape, not Shape.

-- replace block when Action2 is triggered
Client.Action2 = function()
  -- cast a ray and, see if it touches a block
  local impact = Player:CastRay()
  if impact.Block ~= nil then
    -- a Block has been found, replace it
    impact.Block:Replace(Color(255, 0, 0)) -- make it a red block
  end
end

Properties

Color of the block.

Number3 Coordinates read-only

Block's coordinates in the Shape or MutableShape model. Block's origin is its bottom-left-down corner.

local b = someShape:GetBlock(1, 2, 3)
if b ~= nil then
  print(b.Coordinates) -- prints "[Number3 X: 1 Y: 2 Z: 3]"
end
Number3 Coords read-only

Shortcut to Coordinates.

Block's coordinates converted in local space, i.e. relative to the Shape's or MutableShape's parent.

local b = someShape:GetBlock(1, 2, 3)
if b ~= nil then
  print(b.LocalPosition)
end

Block's Palette index in its original Shape. (first index is 1)

⚠️ This has no effect if the block does not belong to a Shape or MutableShape.

local b = someMutableShape:GetBlock(1, 2, 3)
if b ~= nil then
  -- changes block's properties
  -- using different palette index
  b.PaletteIndex = 10 
end
Number3 Pos read-only

Shortcut to Position.

Number3 Position read-only

Block's coordinates converted in world space.

local b = someShape:GetBlock(1, 2, 3)
if b ~= nil then
  print(b.Position)
end