Namespace: Block

Block

Methods

staticBlock.defineBlock(blockId, blockName, texture, materialSource, isOpaque, renderType)

Define a custom block with the specified blockId and attributes. See MCPE Textures for a list of current textures.

Name Type Description
blockId int

a valid, unused block ID between 0 and 255; see: Block IDs

blockName string

the block name

texture Array.<string, int>

the texture and offset used to decorate this block

materialSource int optional

the material (block ID) this block is based on (useful for determining which tool is best used to break your block; see: Block IDs)

isOpaque boolean optional

opaque if true, transparent if false

renderType int optional

the type of block to render see: Block Render Types

Example

Credit: Zhuowei Zhang

// create new block at level startup
var initialized = false;
var ID = 220;

function selectLevelHook() {
  if (!initialized) {
    // make a Foo Stone
    Block.defineBlock(ID, "Foo Stone", ["glass", 0], 1, false, 0);
    Block.setDestroyTime(ID, 0);
    Block.setLightLevel(ID, 15);
    Block.setLightOpacity(ID, 0);
    Block.setColor(ID, [0xF5A9D0]);
    Block.setRenderLayer(ID, 1);
    initialized = true;
  }
}

staticBlock.getAllBlockIds(){Array.<int>}

Return all available block IDs.

Returns:
Type Description
Array.<int>
  • the block IDs

staticBlock.getDestroyTime()

desc

staticBlock.getFriction()

desc

staticBlock.getRenderType(blockId){int}

Return the render type (shape) of a block with the specified blockId.

Name Type Description
blockId int

the block ID (see: Block IDs)

Returns:
Type Description
int
Example
// write all render types to a file
function writeRenderTypes() {
  var bids = Block.getAllBlockIds();
  var file = "rendertypes.txt";
  var bw = new java.io.BufferedWriter(new java.io.FileWriter(file));
  for (var i = 0; i < bids.length; i++) {
    var rt = Block.getRenderType(bids[i]);
    var name = Item.getName(bids[i], 0, false);
    bw.write(name + " - " + rt + "\n");
  }
  bw.close();
}

staticBlock.setColor(blockId, color)

Set the color of a block with the specified blockId and color.

Name Type Description
blockId int

the block ID (see: Block IDs)

color Array.<number>

a hexadecimal color value in the form: [0xRRGGBB]

Example
// make a block red
Block.setColor(220, [0xFF0000])

staticBlock.setDestroyTime(blockId, hardness)

Set the hardness of a block with the specified blockId and hardness.

Name Type Description
blockId int

the block ID (see: Block IDs)

hardness double

the hardness (-1 = unbreakable; destroy time will vary depending on tool used)

Example
// make Glass Pane unbreakable
Block.setDestroyTime(102, -1);

staticBlock.setExplosionResistance(blockId, resistance)

Set the explosion resistance of a block with the specified blockId and resistance.

Name Type Description
blockId int

the block ID (see: Block IDs)

resistance double

the explosion resistance

Example
// make Gorilla Glass by changing Glass Pane from 1.5 to 6000 (same as obsidian)
Block.setExplosionResistance(102, 6000);

staticBlock.setFriction()

desc

staticBlock.setLightLevel(blockId, lightLevel)

Set the light level of a block with the specified blockId and lightLevel.

Name Type Description
blockId int

the block ID (see: Block IDs)

lightLevel int

the light level of the block (0-15)

Example
// tone down that glowstone
Block.setLightLevel(89, 4);

staticBlock.setLightOpacity(blockId, opacity)

Set the light opacity of a block with the specified blockId and opacity.

Name Type Description
blockId int

the block ID (see: Block IDs)

opacity int

the block's opacity to light passing through (0-10 where 0 = most light can pass through, 10 = least light can pass through)

staticBlock.setRedstoneConsumer()

desc

staticBlock.setRenderLayer(blockId, layer)

Set the render layer for a block with the specified blockId and layer.

Name Type Description
blockId int

the block ID (see: Block IDs)

layer int

the render layer [0: opaque, 1: transparent, 2 : translucent - broken?]

  • find out if translucent (2) is working
Example
// render a transparent block
Block.setRenderLayer(220, 1);

staticBlock.setRenderType(blockId, type)

Set the render type for a block with the specified blockId and type.

Name Type Description
blockId int

the block ID (see: Block IDs)

type int

the type of block to render (see: Block Render Types)

Example
// render custom block with blockId 220 using the cactus shape
Block.setRenderType(220, 13);

staticBlock.setShape(blockId, startX, startY, startZ, finishX, finishY, finishZ)

Name Type Description
blockId int

the block ID (see: Block IDs)

startX double

the starting x coordinate

startY double

the starting y coordinate

startZ double

the starting z coordinate

finishX double

the finishing x coordinate

finishY double

the finishing y coordinate

finishZ double

the finishing z coordinate

Example
// set the shape of a block to be 1m wide(X) by 1m long(Z) by .75m high(Y)
Block.setShape(45, 0, 0, 0, 1, 0.75, 1);