In BlockLauncher 1.5.5, scripts can now define custom blocks. Since there is some confusion with the new function calls, I've decided to write up a short tutorial.
The last three parameters are optional: so the simplest call would be
Block.defineBlock(187, "Evil dirt", 2);
You can specify the texture in three ways.
Textures in Minecraft are specified by ID, starting from 0, which is the id on the first row and first column, to 255, on the last row of the last column. Since there are 16 textures per row, this means that, for example, sapling's texture coordinate is 15, and bedrock's is 17.
Here's the terrain.png for reference.
If your block has the same texture on all sides, just specify the number directly.
Block.defineBlock(187, "Evil dirt", 2);
If your block has different textures on each side, you can specify an array of values for each side, in the order [bottom, top, south, north, west, east].
Additionally, if you are using the array syntax, you can specify row-column coordinates as well. So, for example, if you have
, you'll have a block with all sides set to the nether reactor's texture. (row 14, column 10) This has the same effect as writing
Block.defineBlock(187, "Evil reactor", 234)
If your block has different textures on each side, you can specify an array of values for each side, in the order [bottom, top, south, north, west, east]
Blocks, as you might know, have damage values. If you want to specify damage values, simply add more than 6 textures to the array: the first 6 textures will be used for data value 0, the second set of 6 for data value 1, and so on.
I highly recommend using damage values: instead of defining, for example, white wool, black wool, and purple wool, use damage value textures and save 2 block IDs.
So now we have an enchantment table: let's set the heights of it. For that, we can use Block.setShape.
Block.setShape takes 6 parameters: According to Minecraft Coder Pack's authors (from the Desktop edition), the function parameters are:
Sets the bounds of the block. minX, minY, minZ, maxX, maxY, maxZ
For example, if you want to have a block float off the ground, you can change its minimum y value, and if you want it to be half height, you can change its maximum y value.
For our block, we want it to be 1 block wide, one block deep, but only 3/4 the height of a normal block. So we can call
Block.setShape(187, 0, 0, 0, 1, 3/4, 1);
If you omit the setShape call, you'll just get a regular shaped block.
Let's take a look at the shaped block!
You'll notice that irregularly shaped blocks are extremely glitchy: if you put a block behind it, some faces won't render. This will be fixed.
Here's the full script for the enchantment table:
var initialized = false;
function selectLevelHook() { //This is called before the first world is loaded
if (!initialized) { //if we have not set up our custom block
// define a block with ID 187, name "Enchantment table", and the following textures
// in the order (bottom, top, south, north, west, east).
// in this case, the side textures are the same, and the top/bottom textures are different.
Block.defineBlock(187, "Enchantment table", [[2, 5], [10, 6], [11, 6], [11, 6], [11, 6], [11, 6]]);
// sets the block's boundaries.
// in this case, the block starts at y = 0, and stops at y = 0.75 - this is a block 3/4 m high.
Block.setShape(187, 0, 0, 0, 1, 3/4, 1);
initialized = true;
}
}
You can also set the explosion resistance for the block with
Block.setExplosionResistance(id, amount).
setDestroyTime automatically sets up the explosion resistance value to a sane default, so you probably don't need to call this yourself.
Finally, let's make it do something!
Since it's just like any other block, the standard ModPE callbacks will work with it. Let's set it up so that it opens a workbench screen when called.
To do that, we need to change the block into a workbench when the user clicks on it, and change it back when the user stops using it.
We'll define three variables: currentWorkbenchX, currentWorkbenchY, currentWorkbenchZ.
Now, we can set the blocks in useItem, and change it back a tick later.
The final code is shown here:
var initialized = false;
var ENCHANTMENT_TABLE_ID = 187;
var currentWorkbenchX, currentWorkbenchY, currentWorkbenchZ;
var needToSwitchBack = false;
function selectLevelHook() { //This is called before the first world is loaded
if (!initialized) { //if we have not set up our custom block
// define a block with ID 187, name "Enchantment table", and the following textures
// in the order (bottom, top, south, north, west, east).
// in this case, the side textures are the same, and the top/bottom textures are different.
Block.defineBlock(ENCHANTMENT_TABLE_ID, "Enchantment table", [[2, 5], [10, 6], [11, 6], [11, 6], [11, 6], [11, 6]]);
// sets the block's boundaries.
// the order of parameters
// in this case, the block starts at y = 0, and stops at y = 0.75 - this is a block 3/4 m high.
Block.setShape(ENCHANTMENT_TABLE_ID, 0, 0, 0, 1, 3/4, 1);
Block.setDestroyTime(ENCHANTMENT_TABLE_ID, 1);
initialized = true;
}
}
function useItem(x, y, z, itemId, blockId, side) {
if (blockId == ENCHANTMENT_TABLE_ID) {
currentWorkbenchX = x;
currentWorkbenchY = y;
currentWorkbenchZ = z;
setTile(x, y, z, 58);
needToSwitchBack = true;
}
}
function modTick() {
if (needToSwitchBack) {
needToSwitchBack = false;
setTile(currentWorkbenchX, currentWorkbenchY, currentWorkbenchZ, ENCHANTMENT_TABLE_ID);
}
}
In part 3 of the tutorial, some more aspects of custom blocks are showcased, including the ability to recolour textures, and some stupid tricks you can use with custom blocks.
But what if you had one carpet texture, and you want to re-colour it for different carpet types?
Well, Block.setColor to the rescue!
Here's part 3 of the tutorial, where I explain some random stuff that's left over.
Block.setColor allows you to re-colour different textures - for example, I used it to re-colour the clay texture for the coloured clay mod.
Block.setColor(id, colours)
Colours is an array of colour values. the bottom 8 bits specify blue, the next 8 bits specify green, and so on: it's the same as HTML colour codes.
So, if I wanted to create a purple ore, I can do
Block.defineBlock(187, "Ore of evil", [[3, 2]]);
Block.setColor(187, [0xff00ff]);
If you put more elements in the array, those damage values will get different colours.
Block.setLightValue(id, level)
Sets the light level. Level is an integer from 0 to 15 - so if you want full brightness for our ore of evil,
Block.setLightValue(187, 15);
Our completed ore of evil:
Block.setRenderLayer(id, layer)
Some semitransparent blocks needs to render on a different layer to blend - for example, water renders on layer 2, glass renders on layer 1.
Finally, abusing the custom block API. None of these ideas are recommended, of course. They may break in a future BlockLauncher release. (Some of these tricks were discovered by Byteandahalf - thanks)
- Custom blocks can overwrite existing blocks.
- Block.setShape, Block.setDestroyTime, Block.setExplosionResistance, and Block.setLightLevel will work on existing Minecraft PE blocks
- If you don't want your block to be placeable, use ModPE.setItem with the block's ID to override its item when held.
Ok, nice tutorial but I still dont understand how to get the texture
Example:
If I want to add Soul Sand
var initialized = false;
var SOUL_SAND_ID = 187;
function selectLevelHook(){
if(!initialized){
Block.defineBlock(SOUL_SAND_ID, "Soul Sand", what textures???
I used the ID 187
Thanks for Your help
Like set item, edit terrain.png like you edit items.png. thats how
But what if you had one carpet texture, and you want to re-colour it for different carpet types?
Well, Block.setColor to the rescue!
Here's part 3 of the tutorial, where I explain some random stuff that's left over.
Block.setColor allows you to re-colour different textures - for example, I used it to re-colour the clay texture for the coloured clay mod.
Block.setColor(id, colours)
Colours is an array of colour values. the bottom 8 bits specify blue, the next 8 bits specify green, and so on: it's the same as HTML colour codes.
So, if I wanted to create a purple ore, I can do
Block.defineBlock(187, "Ore of evil", [[3, 2]]);
Block.setColor(187, [0xff00ff]);
If you put more elements in the array, those damage values will get different colours.
Block.setLightValue(id, level)
Sets the light level. Level is an integer from 0 to 15 - so if you want full brightness for our ore of evil,
Block.setLightValue(187, 15);
Our completed ore of evil:
Block.setRenderLayer(id, layer)
Some semitransparent blocks needs to render on a different layer to blend - for example, water renders on layer 2, glass renders on layer 1.
After overriding the breaking mechanic to drop purple dye, I now have purple ore of evil!
Here's the script. It also uses item ID 187, so don't activate it with the previous script. https://raw.github.c...0ise_evilore.js
Finally, abusing the custom block API. None of these ideas are recommended, of course. They may break in a future BlockLauncher release. (Some of these tricks were discovered by Byteandahalf - thanks)
- Custom blocks can overwrite existing blocks.
- Block.setShape, Block.setDestroyTime, Block.setExplosionResistance, and Block.setLightLevel will work on existing Minecraft PE blocks
- If you don't want your block to be placeable, use ModPE.setItem with the block's ID to override its item when held.
Future additions:
- Render Types - Minecraft has special shapes for some blocks, such as crosses for flowers. I've added render type setup to the latest beta: go to https://github.com/C...ki/Render-types for a list of block rendering types (scroll down).
If you want a demo script, grab the beta at http://tinyw.in/bl and run https://raw.github.c...e_rendertype.js (this uses ID 187 as well, so disable the other scripts)
If you just want the completed mod, https://raw.github.com/zhuowei/ModPEScripts/master/500ise_enchantingbench.js type /enchanttable to get an enchantment table block. If you want to see how it's made, read on!
To define a block, use the new command
The last three parameters are optional: so the simplest call would be
You can specify the texture in three ways.
Textures in Minecraft are specified by ID, starting from 0, which is the id on the first row and first column, to 255, on the last row of the last column. Since there are 16 textures per row, this means that, for example, sapling's texture coordinate is 15, and bedrock's is 17.
Here's the terrain.png for reference.
If your block has the same texture on all sides, just specify the number directly.
If your block has different textures on each side, you can specify an array of values for each side, in the order [bottom, top, south, north, west, east].
Additionally, if you are using the array syntax, you can specify row-column coordinates as well. So, for example, if you have
, you'll have a block with all sides set to the nether reactor's texture. (row 14, column 10) This has the same effect as writing
If your block has different textures on each side, you can specify an array of values for each side, in the order [bottom, top, south, north, west, east]
Blocks, as you might know, have damage values. If you want to specify damage values, simply add more than 6 textures to the array: the first 6 textures will be used for data value 0, the second set of 6 for data value 1, and so on.
I highly recommend using damage values: instead of defining, for example, white wool, black wool, and purple wool, use damage value textures and save 2 block IDs.
So now we have an enchantment table: let's set the heights of it. For that, we can use Block.setShape.
Block.setShape takes 6 parameters: According to Minecraft Coder Pack's authors (from the Desktop edition), the function parameters are:
Sets the bounds of the block. minX, minY, minZ, maxX, maxY, maxZ
For example, if you want to have a block float off the ground, you can change its minimum y value, and if you want it to be half height, you can change its maximum y value.
For our block, we want it to be 1 block wide, one block deep, but only 3/4 the height of a normal block. So we can call
If you omit the setShape call, you'll just get a regular shaped block.
Let's take a look at the shaped block!
You'll notice that irregularly shaped blocks are extremely glitchy: if you put a block behind it, some faces won't render. This will be fixed.
Here's the full script for the enchantment table:
In the next part of this tutorial, I'll explain how to let the user interact with custom blocks.
The way you are doing it is perfectly fine - it might not be as clear, but if it works...
Anyways, part 2.
First, since we might need to change our block IDs, I decided to move the block ID into a variable.
Now, we need to make our enchantment table interactive. First, let's make it breakable. For that, we'll use the Block.setDestroyTime method.
We'll make our table break at the same rate as signs: we'll consult the list of hardnesses from
http://minecraft.gamepedia.com/Digging#Blocks_by_hardness
Signs have a hardness of 1, so we can write
to give our block the same strength as a sign.
You can also set the explosion resistance for the block with
Block.setExplosionResistance(id, amount).
setDestroyTime automatically sets up the explosion resistance value to a sane default, so you probably don't need to call this yourself.
Finally, let's make it do something!
Since it's just like any other block, the standard ModPE callbacks will work with it. Let's set it up so that it opens a workbench screen when called.
To do that, we need to change the block into a workbench when the user clicks on it, and change it back when the user stops using it.
We'll define three variables: currentWorkbenchX, currentWorkbenchY, currentWorkbenchZ.
Now, we can set the blocks in useItem, and change it back a tick later.
The final code is shown here:
https://raw.github.com/zhuowei/ModPEScripts/master/500ise_enchantingbench.js
In part 3 of the tutorial, some more aspects of custom blocks are showcased, including the ability to recolour textures, and some stupid tricks you can use with custom blocks.
But what if you had one carpet texture, and you want to re-colour it for different carpet types?
Well, Block.setColor to the rescue!
Here's part 3 of the tutorial, where I explain some random stuff that's left over.
Block.setColor allows you to re-colour different textures - for example, I used it to re-colour the clay texture for the coloured clay mod.
Colours is an array of colour values. the bottom 8 bits specify blue, the next 8 bits specify green, and so on: it's the same as HTML colour codes.
So, if I wanted to create a purple ore, I can do
Block.defineBlock(187, "Ore of evil", [[3, 2]]);
Block.setColor(187, [0xff00ff]);
If you put more elements in the array, those damage values will get different colours.
Block.setLightValue(id, level)
Sets the light level. Level is an integer from 0 to 15 - so if you want full brightness for our ore of evil,
Block.setLightValue(187, 15);
Our completed ore of evil:
Block.setRenderLayer(id, layer)
Some semitransparent blocks needs to render on a different layer to blend - for example, water renders on layer 2, glass renders on layer 1.
After overriding the breaking mechanic to drop purple dye, I now have purple ore of evil!
Here's the script. It also uses item ID 187, so don't activate it with the previous script.
https://raw.github.com/zhuowei/ModPEScripts/master/500ise_evilore.js
Finally, abusing the custom block API. None of these ideas are recommended, of course. They may break in a future BlockLauncher release. (Some of these tricks were discovered by Byteandahalf - thanks)
- Custom blocks can overwrite existing blocks.
- Block.setShape, Block.setDestroyTime, Block.setExplosionResistance, and Block.setLightLevel will work on existing Minecraft PE blocks
- If you don't want your block to be placeable, use ModPE.setItem with the block's ID to override its item when held.
Future additions:
- Render Types - Minecraft has special shapes for some blocks, such as crosses for flowers. I've added render type setup to the latest beta: go to https://github.com/Connor4898/ModPE-Scripts/wiki/Render-types for a list of block rendering types (scroll down).
If you want a demo script, grab the beta at http://tinyw.in/bl and run https://raw.github.com/zhuowei/ModPEScripts/master/500ise_rendertype.js (this uses ID 187 as well, so disable the other scripts)
+1 for you!
Click Banner to SUBSCRIBE!!! I'm in the Team Flame Clan!!! Click that little green arrow!! -------------->
Minecraft PE has special support for rendering some non-square blocks. A list can be found at https://github.com/Connor4898/ModPE-Scripts/wiki/Render-types
BlockLauncher 1.5.6 beta supports changing the render types of custom blocks:
http://tinyw.in/bl after installing, try https://raw.github.com/zhuowei/ModPEScripts/master/500ise_rendertype.js (tap on ground)
Here's the first 5 render types: http://imgur.com/a/XUv4j
Question: how do I make such that it spawns the ore randomly
Qiestion 2: how do I make the ruby ingot craft new items
ModPE!?
(Like chads image)
ModPE!?
I'm pretty sure the texture is number 66; however, my image had the red wool texture to make it look like carpet.
ModPE!?
I'm not smart enough for that: modding for iOS is much harder.
Btw Good Job! This will enable a lot of mods.
Like set item, edit terrain.png like you edit items.png. thats how
What if I dont disable the other scripts?
If only we could slow down players using soul sand
P = player
T = top
Other letter indicates direction (north, south, etc.)
N
W T E
S
P
In other words, is south towards you and north away from you? Or vice-virsa?
Willing to work on Android apps or multi-platform games, see profile bio for information.
Founder and CEO of Temena Development
Twitter: @TemenaPE
Instagram: @ItsLiterallyMath