(Fixed pick attribute (caused crashes)) |
No edit summary Tags: Visual edit apiedit |
||
(10 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
⚫ | |||
⚫ | |||
+ | [[File:Bone_and_Ore.png|thumb|320px|left|Why is there a bone?!?]] |
||
⚫ | |||
+ | ==Information== |
||
− | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | {{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"); |
|
+ | </pre> |
||
'''directionalBlock.js''' |
'''directionalBlock.js''' |
||
+ | <pre> |
||
− | name = "dirBlock"; |
||
+ | name = "directionalBlock"; |
||
− | id = config.getBlockId("dirBlockID"); |
||
+ | |||
− | displayName[0] = "Directional Block"; |
||
+ | material = "rock"; |
||
− | |||
− | + | stepSound = "stone"; |
|
+ | |||
− | 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; |
|
+ | |||
− | 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"; |
|
+ | |||
− | pick[3] = config.getBlockId("dirBlockID") + ":0"; |
||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
− | + | addToCreative[1] = false; |
|
− | + | addToCreative[2] = false; |
|
− | + | addToCreative[3] = false; |
|
+ | |||
⚫ | |||
+ | textureFile = "directionalBlock_side.png"; |
||
− | |||
− | + | textureIndexXP[0] = "directionalBlock_side.png"; |
|
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
− | textureIndexXP[2] = 13; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
+ | 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"; |
|
+ | |||
− | drop[3] = config.getBlockId("dirBlockID") + ":0 1"; |
||
⚫ | |||
− | |||
+ | </pre> |
||
⚫ | |||
'''directionalPlacement.js''' |
'''directionalPlacement.js''' |
||
+ | <pre> |
||
⚫ | |||
− | + | var posX = Math.round(living.getPosX()) + 0.5; |
|
⚫ | |||
− | |||
+ | |||
− | + | if(posX + 1 <= position.x + 0.5) { |
|
⚫ | |||
⚫ | |||
− | + | world.setBlockMetadata(position, 1); |
|
− | + | } |
|
− | + | else if(posZ + 1 <= position.z + 0.5) { |
|
⚫ | |||
⚫ | |||
− | + | 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) |
|
+ | </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] = "directionalBlock_front.png"; |
|
− | + | textureIndexZN[1] = "directionalBlock_front.png"; |
|
− | + | textureIndexXN[2] = "directionalBlock_front.png"; |
|
− | + | 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. |
+ | 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:Scripting]] |
||
+ | [[Category:Workaround]] |
||
[[Category:Examples]] |
[[Category:Examples]] |
||
[[Category:Examples (CS2)]] |
[[Category:Examples (CS2)]] |
||
⚫ |
Latest revision as of 22:55, 25 February 2015
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.