I want to make a 5x5 vertical block pole in Minecraft.

Asked 2 years ago, Updated 2 years ago, 315 views

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)
}

javascript

2022-11-12 19:35

1 Answers

Assume that this is a question for Code Connection for Minecraft (Microsoft MakeCode).

Two major issues

  • Algorithm Problems
  • Minecraft running environment problems

There appears to be .

First of all, regarding the algorithm for making squares, the task of making one side is

  • Take two steps and load three blocks there

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)

  • Repeat the following four times (4 sides)
    • Repeat the following four times (four columns)
      • Take two steps and load three blocks
    • Turn right
  • Repeat the following four times (four columns)
    • Take two steps and load three blocks
  • Turn right
  • Take two steps and load three blocks

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);
}


2022-11-12 23:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.