Minecraftmodcustomstuff Wiki
(Fixed pick attribute (caused crashes))
No edit summary
Tags: Visual edit apiedit
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
<div style="text-align: center; background-color:#CBB; color:#000; margin-bottom:1em; padding:0.75em;">[[File:CS2.png|frameless|middle|24px]] '''This example ONLY works in CS2. There is no way to accomplish the following example that would give the same results.'''</div>
[[File:Bone_and_Ore.png|thumb|210px|Why is there a bone?!?]]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.
 
   
  +
[[File:Bone_and_Ore.png|thumb|320px|left|Why is there a bone?!?]]
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.
 
  +
==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 example ONLY works in CS2. There is no way to accomplish the following example that would give the same results.'''''
 
   
 
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.
  +
{{Clear}}
 
==The Files==
 
==The Files==
  +
'''en_US.lang'''
  +
<pre>
  +
tile.directionalBlock0.name=Directional Block
  +
tile.directionalBlock1.name=Directional Block
  +
tile.directionalBlock2.name=Directional Block
  +
tile.directionalBlock3.name=Directional Block
  +
</pre>
 
'''mod.js'''
 
'''mod.js'''
  +
<pre>
config.addBlockIdProperty("dirBlockID", 170);
 
mod.addBlock("directionalBlock.js", "normal");
+
mod.addBlock("directionalBlock.js", "normal");
  +
</pre>
   
 
'''directionalBlock.js'''
 
'''directionalBlock.js'''
  +
<pre>
name = "dirBlock";
 
  +
name = "directionalBlock";
id = config.getBlockId("dirBlockID");
 
  +
displayName[0] = "Directional Block";
 
  +
material = "rock";
 
material = "rock";
+
stepSound = "stone";
  +
stepSound = "stone";
 
  +
hardness[0] = 0.3;
 
hardness[0] = 0.3;
+
resistance[0] = 0;
resistance[0] = 0;
+
hardness[1] = 0.3;
hardness[1] = 0.3;
+
resistance[1] = 0;
resistance[1] = 0;
+
hardness[2] = 0.3;
hardness[2] = 0.3;
+
resistance[2] = 0;
resistance[2] = 0;
+
hardness[3] = 0.3;
hardness[3] = 0.3;
+
resistance[3] = 0;
  +
resistance[3] = 0;
 
  +
pick[0] = mod.getModName()+":directionalBlock:0";
 
pick[0] = config.getBlockId("dirBlockID") + ":0";
+
pick[1] = mod.getModName()+":directionalBlock:0";
pick[1] = config.getBlockId("dirBlockID") + ":0";
+
pick[2] = mod.getModName()+":directionalBlock:0";
pick[2] = config.getBlockId("dirBlockID") + ":0";
+
pick[3] = mod.getModName()+":directionalBlock:0";
  +
pick[3] = config.getBlockId("dirBlockID") + ":0";
 
 
creativeTab = "decorations";
 
 
addToCreative[0] = true;
creativeTab = "decorations";
 
addToCreative[0] = true;
+
addToCreative[1] = false;
addToCreative[1] = false;
+
addToCreative[2] = false;
addToCreative[2] = false;
+
addToCreative[3] = false;
  +
addToCreative[3] = false;
 
  +
textureFile = "directionalBlock_side.png";
 
textureFile = "customstuff.png";
+
textureIndexXP[0] = "directionalBlock_side.png";
 
textureIndexXN[0] = "directionalBlock_side.png";
textureIndexXP[0] = 13;
 
 
textureIndexYP[0] = "directionalBlock_side.png";
textureIndexXN[0] = 13;
 
 
textureIndexYN[0] = "directionalBlock_side.png";
textureIndexYP[0] = 13;
 
 
textureIndexZP[0] = "directionalBlock_front.png";;
textureIndexYN[0] = 13;
 
 
textureIndexZN[0] = "directionalBlock_side.png";
textureIndexZP[0] = 17;
 
  +
textureIndexZN[0] = 13;
 
 
textureIndexXP[1] = "directionalBlock_side.png";
 
 
textureIndexXN[1] = "directionalBlock_front.png";;
textureIndexXP[1] = 13;
 
 
textureIndexYP[1] = "directionalBlock_side.png";
textureIndexXN[1] = 13;
 
 
textureIndexYN[1] = "directionalBlock_side.png";
textureIndexYP[1] = 13;
 
 
textureIndexZP[1] = "directionalBlock_side.png";
textureIndexYN[1] = 13;
 
 
textureIndexZN[1] = "directionalBlock_side.png";
textureIndexZP[1] = 13;
 
  +
textureIndexZN[1] = 17;
 
 
textureIndexXP[2] = "directionalBlock_side.png";
 
 
textureIndexXN[2] = "directionalBlock_side.png";
textureIndexXP[2] = 13;
 
 
textureIndexYP[2] = "directionalBlock_side.png";
textureIndexXN[2] = 17;
 
 
textureIndexYN[2] = "directionalBlock_side.png";
textureIndexYP[2] = 13;
 
 
textureIndexZP[2] = "directionalBlock_side.png";
textureIndexYN[2] = 13;
 
 
textureIndexZN[2] = "directionalBlock_front.png";;
textureIndexZP[2] = 13;
 
  +
textureIndexZN[2] = 13;
 
 
textureIndexXP[3] = "directionalBlock_front.png";;
 
 
textureIndexXN[3] = "directionalBlock_side.png";
textureIndexXP[3] = 17;
 
 
textureIndexYP[3] = "directionalBlock_side.png";
textureIndexXN[3] = 13;
 
 
textureIndexYN[3] = "directionalBlock_side.png";
textureIndexYP[3] = 13;
 
 
textureIndexZP[3] = "directionalBlock_side.png";
textureIndexYN[3] = 13;
 
 
textureIndexZN[3] = "directionalBlock_side.png";
textureIndexZP[3] = 13;
 
  +
textureIndexZN[3] = 13;
 
  +
drop[0] = mod.getModName()+":directionalBlock:0 1";
 
drop[0] = config.getBlockId("dirBlockID") + ":0 1";
+
drop[1] = mod.getModName()+":directionalBlock:0 1";
drop[1] = config.getBlockId("dirBlockID") + ":0 1";
+
drop[2] = mod.getModName()+":directionalBlock:0 1";
drop[2] = config.getBlockId("dirBlockID") + ":0 1";
+
drop[3] = mod.getModName()+":directionalBlock:0 1";
  +
drop[3] = config.getBlockId("dirBlockID") + ":0 1";
 
 
onPlacedBy[0] = "mod.loadScript('directionalPlacement.js');";
 
  +
</pre>
onPlacedBy[0] = "mod.loadScript('directionalPlacement.js');";
 
   
 
'''directionalPlacement.js'''
 
'''directionalPlacement.js'''
  +
<pre>
var posX = Math.round(living.getPosX()) + 0.5;
 
var posZ = Math.round(living.getPosZ()) + 0.5;
+
var posX = Math.round(living.getPosX()) + 0.5;
 
var posZ = Math.round(living.getPosZ()) + 0.5;
 
  +
if(posX + 1 <= position.x + 0.5) {
+
if(posX + 1 <= position.x + 0.5) {
//make face ZN
 
 
//make face XN
world.setBlockMetadata(position, 1);
+
world.setBlockMetadata(position, 1);
}
+
}
else if(posZ + 1 <= position.z + 0.5) {
+
else if(posZ + 1 <= position.z + 0.5) {
//make face XN
 
 
//make face ZN
world.setBlockMetadata(position, 2);
+
world.setBlockMetadata(position, 2);
}
+
}
else if(posX - 1 >= position.x + 0.5) {
+
else if(posX - 1 >= position.x + 0.5) {
//make face XP
+
//make face XP
world.setBlockMetadata(position, 3);
+
world.setBlockMetadata(position, 3);
}
+
}
//if none, default to ZP (meta data 0)
+
//if none, default to ZP (meta data 0)
  +
</pre>
   
 
==Final Notes==
 
==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.
 
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.
  +
<pre>
textureIndexZP[0] = 17;
+
textureIndexZP[0] = "directionalBlock_front.png";
textureIndexZN[1] = 17;
+
textureIndexZN[1] = "directionalBlock_front.png";
textureIndexXN[2] = 17;
+
textureIndexXN[2] = "directionalBlock_front.png";
textureIndexXP[3] = 17;
+
textureIndexXP[3] = "directionalBlock_front.png";
  +
</pre>
 
Group them together like this if you think it would be easier to keep track of.
 
Group them together like this if you think it would be easier to keep track of.
   
Lastly, textureIndexXN and textureIndexZN are swapped in 0.9.3 and lower. A future version will hopefully fix this and this example will be updated. Just keep that fact in mind when you update beyond 0.9.3.
+
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.
 
[[Category:Custom Stuff 2]]
  +
[[Category:Scripting]]
  +
[[Category:Workaround]]
 
[[Category:Examples]]
 
[[Category:Examples]]
 
[[Category:Examples (CS2)]]
 
[[Category:Examples (CS2)]]
[[Category:Scripting]]
 

Latest revision as of 22:55, 25 February 2015

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.