Im making a *********************** (secret) and i need help with coding. I need much more costum blocks than its possible, so i had an idea. What if i make only one costum block (or 2-4) and when i click it, it checks the block under it (actually not under it, but doesnt rly matter), and if its stone block, it spawns...umm...idk, maybe a stone block over it. BUT, if its a diamond block, it spawns an emerald block over it. So i dont need that much blocks, i only need to variate the blocks under it. The only problem is i dont know how to do that.
if(blockId == 222){
[Command for checking the block];
if(checked block id is 1){
setTile(x,y+1,z,16,0);
}
}
How do i do this? Is it eaveb possible with java script?
Anyway, thanks for reading! I hope you know the answer. If you do, pls write it down in this thread, and kik me, my name is MattZCrafter and my profil pic is a base entrance (a big one)
Can you explain it a bit more specific? Like whats switch, whats y-- or z++, where do i set whats the block what im tapping, where is the block it checks...
x, y, z are the coords you have from useItem(). x++ and y-- are just the same as x=x+1 and y=y-1. The only bad thing at useItem is, that it gives you the coords from the block over the Block you tapped. Ups, I made a mistake, it should be:
function useItem(x, y, z, itemId, blockId, side){
y=y-2;
switch(Level.getTile(x, y, z)){
case 1:
...
}
}
Switch:
switch helps really good, because you don't need things like:
if(){
}
if(){
}
if(){
}
You put the thing you want to compare in the () after the switch. It compares that with the cases:
var num=4;
switch(num){
case 1:
clientMessage("num=1");
break;
case 2:
clientMessage("num=2");
break;
case 4:
clientMessage("num=4");
break;
default:
clientMessage("num is not 1, 2 or 4");
break;
}
You need the break; because if it wouldn't be there it would do everything after the first case it becomes active.
That helped a lot, and i wonder if i can do this 6 separate ways. I mean if i click a dirt block, it checks y+1, -1, x+1, -1, z+1, -1, and if any of them dirt, it destroys it and start it again, but now with the coordinates of the dirtS it destroyed/checked (yes, i wrote dirts, whit s) i was thinking abaut a way to do it, and i just couldnt find one. With this i could make tools what can rid of a massive amaunt of a specific block, make tree cutting/ mining much faster...
Whenever you want to do something often you should use loops, there are 3: for, while and doWhile (doWhile is used rare), you should google how they work, but that's quite easy, I think then you'll easily find a way to do that.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Im making a *********************** (secret) and i need help with coding. I need much more costum blocks than its possible, so i had an idea. What if i make only one costum block (or 2-4) and when i click it, it checks the block under it (actually not under it, but doesnt rly matter), and if its stone block, it spawns...umm...idk, maybe a stone block over it. BUT, if its a diamond block, it spawns an emerald block over it. So i dont need that much blocks, i only need to variate the blocks under it. The only problem is i dont know how to do that.
if(blockId == 222){
[Command for checking the block];
if(checked block id is 1){
setTile(x,y+1,z,16,0);
}
}
How do i do this? Is it eaveb possible with java script?
Anyway, thanks for reading! I hope you know the answer. If you do, pls write it down in this thread, and kik me, my name is MattZCrafter and my profil pic is a base entrance (a big one)
Have a good day!
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumwith useItem():
function useItem(x, y, z, itemId, blockId, side){
switch(side){
case 0:
case 2:
case 3:
case 4:
case 5:
y--;
}
switch(side){
case 0:
y--;
break;
case 2:
z--;
break;
case 3:
z++;
break;
case 4:
x--;
break;
case 5:
x++;
break;
}
y=y-2;
switch(Level.getTile(x, y, z)){
case 1:
//if the Id of the block under the block the Player tapped is one put what you want to do here;
break;
case 2:
// “
break;
default:
//if the Id is none of the checked until now, but you can let it away (if you let it away don't forget to make the break away)
break;
}
}
with modTick():
function modTick(){
switch(Level.getTile(getPlayerX(), getPlayerY()-3, getPlayerZ())){
case 1:
//if the Id of the block under the block the Player is on is one put what you want to do here;
break;
case 2:
// “
break;
default:
//if the Id is none of the checked until now, but you can let it away (if you let it away don't forget to make the break away)
break;
}
}
Thank you!
Can you explain it a bit more specific? Like whats switch, whats y-- or z++, where do i set whats the block what im tapping, where is the block it checks...
Ill start the map anyway, the mod can wait...
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumx, y, z are the coords you have from useItem(). x++ and y-- are just the same as x=x+1 and y=y-1. The only bad thing at useItem is, that it gives you the coords from the block over the Block you tapped. Ups, I made a mistake, it should be:
function useItem(x, y, z, itemId, blockId, side){
y=y-2;
switch(Level.getTile(x, y, z)){
case 1:
...
}
}
Switch:
switch helps really good, because you don't need things like:
if(){
}
if(){
}
if(){
}
You put the thing you want to compare in the () after the switch. It compares that with the cases:
var num=4;
switch(num){
case 1:
clientMessage("num=1");
break;
case 2:
clientMessage("num=2");
break;
case 4:
clientMessage("num=4");
break;
default:
clientMessage("num is not 1, 2 or 4");
break;
}
You need the break; because if it wouldn't be there it would do everything after the first case it becomes active.
Hey guys! I'm just a beginner.. can someone help me with this code? It doesn't work. It always shows some errors according to BlockLauncher
function modTick()
{
var b = Level.getTile(x,y-2,z);
var d = Level.getData(x,y-2,z);
if(b==159 && d==5)
{
Level.explode(Player.getX(),Player.getY()+1,Player.getZ(),4);
Player.setHealth(0);
clientMessage("You stepped on a minefield");
}
}
and I also tried putting the declaration of the variables before the function. Both doesn't work
That helped a lot, and i wonder if i can do this 6 separate ways. I mean if i click a dirt block, it checks y+1, -1, x+1, -1, z+1, -1, and if any of them dirt, it destroys it and start it again, but now with the coordinates of the dirtS it destroyed/checked (yes, i wrote dirts, whit s) i was thinking abaut a way to do it, and i just couldnt find one. With this i could make tools what can rid of a massive amaunt of a specific block, make tree cutting/ mining much faster...
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWhenever you want to do something often you should use loops, there are 3: for, while and doWhile (doWhile is used rare), you should google how they work, but that's quite easy, I think then you'll easily find a way to do that.