|
1 | 1 | package mrtjp.projectred.api; |
2 | 2 |
|
3 | | -import net.minecraft.core.Direction; |
4 | 3 | import net.minecraft.core.BlockPos; |
| 4 | +import net.minecraft.core.Direction; |
5 | 5 | import net.minecraft.world.level.Level; |
6 | 6 |
|
7 | 7 | /** |
8 | 8 | * Interface for an object that manages the movement of blocks and tiles that are |
9 | 9 | * registered to it. This class should be registered through the {@link IExpansionAPI}. |
| 10 | + * <p> |
| 11 | + * The order of calls are: |
| 12 | + * <ol> |
| 13 | + * <li>Server receives {@link #canMove(Level, BlockPos)} </li> |
| 14 | + * <li>Server receives {@link #move(Level, BlockPos, Direction)}</li> |
| 15 | + * <li>Client receives {@link #move(Level, BlockPos, Direction)}</li> |
| 16 | + * <li>Client receives {@link #postMove(Level, BlockPos)}</li> |
| 17 | + * <li>Server receives {@link #postMove(Level, BlockPos)}</li> |
| 18 | + * </ol> |
10 | 19 | */ |
11 | 20 | public interface BlockMover { |
| 21 | + |
12 | 22 | /** |
13 | 23 | * Used to check if the block at the given position can move. This |
14 | 24 | * method is only called if the specified block is tied to this |
15 | 25 | * handler, so there is no need to check if the block is valid |
16 | 26 | * for this handler. This is called before actually moving. If |
17 | 27 | * everything is able to move, an animation will start. |
18 | 28 | * <p> |
19 | | - * Called server-side only when determining what to move. |
| 29 | + * Called server-side only. |
20 | 30 | * |
21 | | - * @param w The world. |
22 | | - * @param pos The position of the block to move. |
| 31 | + * @param w The world. |
| 32 | + * @param pos The position of the block before movement. |
23 | 33 | * @return True if the block at the given position is able to move. |
24 | 34 | */ |
25 | 35 | boolean canMove(Level w, BlockPos pos); |
26 | 36 |
|
27 | 37 | /** |
28 | 38 | * Method used to actually move the tile. Called after the animation |
29 | | - * has run. This is where you should tell the tile that it is time |
30 | | - * to move, and peform any extra checks or calls. This should also |
31 | | - * move the block and tile as well. This is called |
32 | | - * on every block in the moving structure sequentially. |
| 39 | + * has run. This is where you should tell the tile that it is time |
| 40 | + * to move, and perform any extra checks or calls. This should also |
| 41 | + * move the block and tile as well. This is called on every block in |
| 42 | + * the moving structure sequentially. |
33 | 43 | * <p> |
34 | | - * Called on both server and client. |
| 44 | + * Called on server then client. Note that after server call, block |
| 45 | + * positions of client/server are out of sync. Do not send packets |
| 46 | + * to client referencing blocks by position, update neighbors, mark |
| 47 | + * chunk for re-render, etc. |
35 | 48 | * |
36 | 49 | * @param w The world. |
37 | | - * @param pos The position of the block to move. |
| 50 | + * @param pos The position of the block before movement. |
38 | 51 | * @param dir The ForgeDirection the structure is moving in. |
39 | 52 | */ |
40 | 53 | void move(Level w, BlockPos pos, Direction dir); |
41 | 54 |
|
42 | 55 | /** |
43 | | - * Called after all blocks in the group have moved to their |
44 | | - * new locations. This is where you would reload your tile, |
45 | | - * tell it to refresh or reacknowledge its new position. |
| 56 | + * Called after all blocks in the group have moved to their new locations. |
| 57 | + * This is where you would reload your tile, tell it to refresh or |
| 58 | + * re-acknowledge its new position. No need to update neighbors, since |
| 59 | + * they are batch-notified after all blocks (moved and adjacent to moved) |
| 60 | + * get postMove call. |
46 | 61 | * <p> |
47 | | - * Called on both server and client. |
| 62 | + * Called on client then server. At this point, both client and server |
| 63 | + * blocks are in sync at new positions. It is safe to send packets |
| 64 | + * with position references. |
48 | 65 | * |
49 | | - * @param w The world. |
50 | | - * @param pos The position of the block to move. |
| 66 | + * @param w The world. |
| 67 | + * @param pos The position of the block after movement. |
51 | 68 | */ |
52 | 69 | void postMove(Level w, BlockPos pos); |
53 | 70 | } |
0 commit comments