FANDOM


CS2 This example ONLY works in CS2. There is no way to accomplish the following example that would give the same results.
Bone and Ore

Why is there a bone?!?

Information

In CS2, unless you are making stairs type blocks or something similar, blocks will not normally face your direction. The following example intends to provide a way of emulating that same feature for use in your own custom blocks.

This could potentially be used for furnaces that actually face the player when placed with just a few small changes. Hopefully you will find this example of use.

The Files

en_US.lang

tile.directionalBlock0.name=Directional Block
tile.directionalBlock1.name=Directional Block
tile.directionalBlock2.name=Directional Block
tile.directionalBlock3.name=Directional Block

mod.js

mod.addBlock("directionalBlock.js", "normal");

directionalBlock.js

name = "directionalBlock";

material = "rock";
stepSound = "stone";

hardness[0] = 0.3;
resistance[0] = 0;
hardness[1] = 0.3;
resistance[1] = 0;
hardness[2] = 0.3;
resistance[2] = 0;
hardness[3] = 0.3;
resistance[3] = 0;

pick[0] = mod.getModName()+":directionalBlock:0";
pick[1] = mod.getModName()+":directionalBlock:0";
pick[2] = mod.getModName()+":directionalBlock:0";
pick[3] = mod.getModName()+":directionalBlock:0";

creativeTab = "decorations";
addToCreative[0] = true;
addToCreative[1] = false;
addToCreative[2] = false;
addToCreative[3] = false;

textureFile = "directionalBlock_side.png";
textureIndexXP[0] = "directionalBlock_side.png";
textureIndexXN[0] = "directionalBlock_side.png";
textureIndexYP[0] = "directionalBlock_side.png";
textureIndexYN[0] = "directionalBlock_side.png";
textureIndexZP[0] = "directionalBlock_front.png";;
textureIndexZN[0] = "directionalBlock_side.png";

textureIndexXP[1] = "directionalBlock_side.png";
textureIndexXN[1] = "directionalBlock_front.png";;
textureIndexYP[1] = "directionalBlock_side.png";
textureIndexYN[1] = "directionalBlock_side.png";
textureIndexZP[1] = "directionalBlock_side.png";
textureIndexZN[1] = "directionalBlock_side.png";

textureIndexXP[2] = "directionalBlock_side.png";
textureIndexXN[2] = "directionalBlock_side.png";
textureIndexYP[2] = "directionalBlock_side.png";
textureIndexYN[2] = "directionalBlock_side.png";
textureIndexZP[2] = "directionalBlock_side.png";
textureIndexZN[2] = "directionalBlock_front.png";;

textureIndexXP[3] = "directionalBlock_front.png";;
textureIndexXN[3] = "directionalBlock_side.png";
textureIndexYP[3] = "directionalBlock_side.png";
textureIndexYN[3] = "directionalBlock_side.png";
textureIndexZP[3] = "directionalBlock_side.png";
textureIndexZN[3] = "directionalBlock_side.png";

drop[0] = mod.getModName()+":directionalBlock:0 1";
drop[1] = mod.getModName()+":directionalBlock:0 1";
drop[2] = mod.getModName()+":directionalBlock:0 1";
drop[3] = mod.getModName()+":directionalBlock:0 1";

onPlacedBy[0] = "mod.loadScript('directionalPlacement.js');";

directionalPlacement.js

var posX = Math.round(living.getPosX()) + 0.5;
var posZ = Math.round(living.getPosZ()) + 0.5;

if(posX + 1 <= position.x + 0.5) {
  //make face XN
  world.setBlockMetadata(position, 1);
}
else if(posZ + 1 <= position.z + 0.5) {
  //make face ZN
  world.setBlockMetadata(position, 2);
}
else if(posX - 1 >= position.x + 0.5) {
  //make face XP
  world.setBlockMetadata(position, 3);
}
//if none, default to ZP (meta data 0)

Final Notes

The most important part to remember is the following 4 lines from above are the "front" of your block that faces you when you placed the block.

textureIndexZP[0] = "directionalBlock_front.png";
textureIndexZN[1] = "directionalBlock_front.png";
textureIndexXN[2] = "directionalBlock_front.png";
textureIndexXP[3] = "directionalBlock_front.png";

Group them together like this if you think it would be easier to keep track of.

Lastly, textureIndexXN and textureIndexZN are swapped in versions below 0.9.4. If you are using 0.9.3 or lower, you will need to swap these values to get the correct visual orientations.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.