Minecraft JavaScript
What you want to do
1. Place three blocks vertically in the position where the area is located
2.Take two steps and re-arrange the same block vertically with the area
I want to go around the square 5x5 while repeating 3.2
□□□□□
□ □
□ □
□ □
□□□□□
I want to make it look like above
For some reason, the agent stops halfway.
Please let me know if you know why.
letl_stones: number [ ] = [ ]
let index = 0
let A0: Position = null
player.onChat("comehere", function(){
agent.teleportToPlayer()
})
player.onChat("1", function(){
for (let index2=0; index2<4;index2++) {
_1()
}
})
function_1(){
l_stones = [STONE, GRASS, WOOL]
for (let index2=0; index2<5;index2++) {
index = 0
A0 = agent.getPosition()
for (let index2=0; index2<l_stones.length;index2++) {
blocks.place(l_stones [index], positions.add(
A0,
pos(0,index,0)
))
index+=1
}
agent.move (FORWARD, 2)
}
agent.turn(RIGHT_TURN)
}
Assume that this is a question for Code Connection for Minecraft (Microsoft MakeCode).
Two major issues
There appears to be .
First of all, regarding the algorithm for making squares, the task of making one side is
That means you repeat it four times (not five times).
Then, turn right and do the same thing, and do it for four sides.
In other words, the procedure to be carried out this time is as follows.
(If you think about it while writing it on paper, it will be easy to understand)
When converted to JavaScript:
player.onChat("1", function(){
// repeat for four sides
for(let side=0;side<4;side++){
_1();
}
});
function_1(){
// repeat for four columns
for(let pole=0; pole<4;pole++){
// take two steps forward
agent.move (FORWARD, 2);
let A0 = agent.getPosition();
// Load 3 blocks (l_stones.length)
for(leti=0;i<l_stones.length;i++){
blocks.place(l_stones[i], positions.add(A0, pos(0, i, 0)));
}
}
// look to the right
agent.turn(RIGHT_TURN);
}
Also, you should avoid naming variables with different meanings, such as index2
in the code in the question sentence, or naming them that are difficult to infer the role.
The second Minecraft running environment issue is:
In this code, the block is placed in the position where the agent is standing, but it seems that this will cause the agent to be buried in the block and not proceed as expected.
This needs to be devised according to the needs of the questioner.
In the following code sample, blocks are stacked vertically (in the air) to avoid conflicts with agents.
blocks.place(l_stones[i], positions.add(A0,pos(0,i+1,0)));
To sum up the above, the overall results are as follows:
letl_stones=[STONE, GRASS, WOOL];
player.onChat("comehere", function(){
agent.teleportToPlayer();
});
player.onChat("1", function(){
// repeat for four sides
for(let side=0;side<4;side++){
_1();
}
});
function_1(){
// repeat for four columns
for(let pole=0; pole<4;pole++){
// take two steps forward
agent.move (FORWARD, 2);
let A0 = agent.getPosition();
// Load 3 blocks (l_stones.length)
for(leti=0;i<l_stones.length;i++){
blocks.place(l_stones[i], positions.add(A0,pos(0,i+1,0)));
}
}
// look to the right
agent.turn(RIGHT_TURN);
}
© 2024 OneMinuteCode. All rights reserved.