Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Bukkit plug-in development tutorial -Block (block)
Bukkit plug-in development tutorial -Block (block)
Because we are operating on another block, we need to get a block object first. We can get a block object by the following methods.

In the first case, what we need first is something called position, which is used to represent a point in the MC world. It is similar to a point in the rectangular coordinate system in mathematics, except that there are two things outside it, pitch and yaw, so Location has a concept called direction, which can be represented by BlockFace in BukkitAPI.

To get a location object, we might as well use the Entity#getLocation method to get it directly.

In the following example, we use player to create an entity.

In the second case, a concept called world is introduced to represent an MC world. If you want to get a square of the world, you can use the World#getBlockAt(int, int, int) method.

Fill in three plastic shapes, then it can be approximately equal to Location(world, int, int, int).

In BukkitAPI, Block exists as a "living" object, so if we want to further operate a Block, we need to get its BlockState object first.

BlockState can be used to represent a "snapshot" of a block at the current beat. After manipulating it, you can call its update () method to update the block.

Example: Adding an Item to a Box

In the above example, we didn't call the update method to update the box, because in the high version, the changes we made in the current tick will be automatically updated in the next tick, so we don't need to update it manually (of course, you can also update it manually when you find it impossible).