Skip to content

Commit

Permalink
simplify block breaking a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Nov 22, 2023
1 parent 03822eb commit 4c1ae30
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions docs/blocks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ Block placement logic is called from `BlockItem#useOn` (or some subclass's imple

### Breaking a Block

Breaking a block is a bit more complex, as it requires time. The process can be roughly divided into four stages: "initiating", "mining", "actually breaking" and "finishing".
Breaking a block is a bit more complex, as it requires time. The process can be roughly divided into three stages: "initiating", "mining" and "actually breaking".

- When the left mouse button is clicked, the "initiating" stage is entered.
- Now, the left mouse button needs to be held down, entering the "mining" stage. **This stage's methods are called every tick.**
- If the "continuing" stage is not interrupted (by releasing the left mouse button) and the block is broken, the "actually breaking" stage is entered.
- Under all circumstances, no matter if the block was actually broken or not, the "finishing" stage is entered.

Or for those who prefer pseudocode:

Expand All @@ -126,7 +125,6 @@ while (leftClickIsBeingHeld()) {
break;
}
}
finishingStage();
```

The following subsections further break down these stages into actual method calls.
Expand All @@ -143,8 +141,8 @@ The following subsections further break down these stages into actual method cal
#### The "Mining" Stage

- `PlayerInteractEvent.LeftClickBlock` is fired. If the event is canceled, the pipeline moves to the "finishing" stage.
- Note that when the event is canceled on the client, no packets are sent to the server and thus no logic runs on the server.
- However, canceling this event on the server will still cause client code to run, which can lead to desyncs!
- Note that when the event is canceled on the client, no packets are sent to the server and thus no logic runs on the server.
- However, canceling this event on the server will still cause client code to run, which can lead to desyncs!
- `Block#getDestroyProgress` is called and added to the internal destroy progress counter.
- `Block#getDestroyProgress` returns a float value between 0 and 1, representing how much the destroy progress counter should be increased every tick.
- The progress overlay (cracking texture) is updated accordingly.
Expand All @@ -163,10 +161,6 @@ The following subsections further break down these stages into actual method cal
- Server-only: `IBlockExtension#getExpDrop` is called.
- Server-only: `Block#popExperience` is called with the result of the previous `IBlockExtension#getExpDrop` call, if that call returned a value greater than 0.

#### The "Finishing" Stage

- The internal destroy progress counter is reset.

### Ticking

Ticking is a mechanism that updates (ticks) parts of the game every 1 / 20 seconds, or 50 milliseconds ("one tick"). Blocks provide different ticking methods that are called in different ways.
Expand Down

0 comments on commit 4c1ae30

Please sign in to comment.