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 ( integer paletteIndex )

Creates a Block with {0,0,0} coordinates. (Block.Position)

Block.PaletteIndex is set to paletteIndex, but Block.Properties remains nil before the block is added to a MutableShape (owns the Palette).

Block ( integer paletteIndex, number x, number y, number z )

Creates a Block with {x,y,z} coordinates. (Block.Position)

Block.PaletteIndex is set to paletteIndex, but Block.Properties remains nil before the block is added to a MutableShape (owns the Palette).

Block ( integer paletteIndex, Number3 position )

Creates a Block with position coordinates. (Block.Position)

Block.PaletteIndex is set to paletteIndex, but Block.Properties remains nil before the block is added to a MutableShape (owns the Palette).

Functions

Block AddNeighbor ( Block block, BlockFace face )

Adds a Block, adjacent to the face passed as parameter.

Returns created Block (or nil if it fails).

⚠️ 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(Block(1), 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, see if it touches a block
  local impact = Player:CastRay()
  -- won't do anything if impact.Block is nil
  impact.Block:Remove()
end
nil Replace ( Block block )

Replaces the Block with the one passed as parameter. The position remains the same, Block.PaletteIndex is the only property being set.

block:Replace(otherBlock) actually has the same effect as block.PaletteIndex = otherBlock.PaletteIndex

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

-- replace block when Action2 is triggered
Client.Action2 = function()
  -- cast a ray, see if it touches a block
  local impact = Player:CastRay()
  -- won't do anything if impact.Block is nil
  impact.Block:Replace(Block(1)) -- make it a block with PaletteIndex == 1
end

Properties

Number3 Coordinates read-only

Block's coordinates in Shape or MutableShape.

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.

Position of Block's center in local coordinates (local to parent Shape or MutableShape)

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

Block's palette index. (first index is 1)

⚠️ Block.Properties remains nil if the block does not belong to a Shape or MutableShape (instances owning a Palette).

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

Position of Block's negative X-Y-Z corner in world coordinates.

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

Returns Block's BlockProperties.

nil if the Block does not belong to a Shape or MutableShape.