Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain blocks and blockstates in more depth #21

Merged
merged 31 commits into from
Nov 25, 2023
Merged
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
40e3d13
explain blocks and blockstates in more depth
IchHabeHunger54 Oct 17, 2023
4c87eac
update headers
IchHabeHunger54 Oct 17, 2023
b81bf08
implement feedback, add reference.md
IchHabeHunger54 Oct 17, 2023
4326538
add reference for methods in Block.java
IchHabeHunger54 Oct 18, 2023
f5ca59b
add interactionpipeline.md
IchHabeHunger54 Oct 18, 2023
2dcc08c
add documentation for methods of BlockBehaviour
IchHabeHunger54 Oct 18, 2023
a5d4da1
add common block pipelines
IchHabeHunger54 Oct 18, 2023
eeb617a
Update docs/blocks/index.md
IchHabeHunger54 Oct 22, 2023
d2b5bd0
Update docs/blocks/index.md
IchHabeHunger54 Oct 22, 2023
93a5b31
Update docs/blocks/index.md
IchHabeHunger54 Oct 22, 2023
fa5b374
remove reference (for PRing to Parchment instead), apply feedback
IchHabeHunger54 Oct 22, 2023
6fff887
Merge remote-tracking branch 'origin/rework/blocks' into rework/blocks
IchHabeHunger54 Oct 22, 2023
1fbcd04
remove faulty link to now-gone reference.md
IchHabeHunger54 Oct 22, 2023
32a3e05
implement feedback
IchHabeHunger54 Oct 24, 2023
17c0098
implement feedback
IchHabeHunger54 Oct 26, 2023
b6741fd
implement more feedback
IchHabeHunger54 Oct 26, 2023
55c37f5
add extra disclaimer about PlayerInteractEvent.LeftClickBlock
IchHabeHunger54 Oct 26, 2023
a3090aa
add highlights to codeblocks
IchHabeHunger54 Oct 26, 2023
27f5fd5
Update docs/blocks/states.md
IchHabeHunger54 Nov 15, 2023
f510e01
shorten interactionpipeline.md
IchHabeHunger54 Nov 15, 2023
fc9e448
Merge remote-tracking branch 'origin/rework/blocks' into rework/blocks
IchHabeHunger54 Nov 15, 2023
d7662bd
fix a grammar mistake in states.md
IchHabeHunger54 Nov 15, 2023
06b95e2
Update docs/blocks/states.md
IchHabeHunger54 Nov 15, 2023
0b9ce65
implement requested feedback
IchHabeHunger54 Nov 20, 2023
58109b5
Merge remote-tracking branch 'origin/rework/blocks' into rework/blocks
IchHabeHunger54 Nov 20, 2023
723dfe2
Update docs/blocks/states.md
IchHabeHunger54 Nov 22, 2023
03822eb
adjust to the new registry system
IchHabeHunger54 Nov 22, 2023
4c1ae30
simplify block breaking a bit
IchHabeHunger54 Nov 22, 2023
b6f860a
Merge remote-tracking branch 'origin/rework/blocks' into rework/blocks
IchHabeHunger54 Nov 22, 2023
6e6d973
Update docs/blocks/index.md
IchHabeHunger54 Nov 22, 2023
a8b4c53
Update docs/blocks/index.md
IchHabeHunger54 Nov 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions docs/blocks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Before we get started, it is important to understand that there is only ever one
Due to this, a block should only ever be instantiated once, and that is during registration. Once the block is registered, you can then use the registered reference as needed. Consider this example (see the [Registration][registration] page if you do not know what you are looking at):

```java
//BLOCKS is a DeferredRegister<Block>
public static final RegistryObject<Block> MY_BLOCK = BLOCKS.register("my_block", () -> new Block(...));
//BLOCKS is a DeferredRegister.Blocks
public static final Supplier<Block> MY_BLOCK = BLOCKS.register("my_block", () -> new Block(...));
IchHabeHunger54 marked this conversation as resolved.
Show resolved Hide resolved
```

After registering the block, all references to the new `my_block` should use this constant. For example, if you want to check if the block at a given position is `my_block`, the code for that would look something like this:
Expand Down Expand Up @@ -54,7 +54,7 @@ For simple blocks which need no special functionality (think cobblestone, wooden
So for example, a simple implementation would look something like this:

```java
public static final RegistryObject<Block> MY_BETTER_BLOCK = BLOCKS.register(
public static final Supplier<Block> MY_BETTER_BLOCK = BLOCKS.register(
IchHabeHunger54 marked this conversation as resolved.
Show resolved Hide resolved
"my_better_block",
() -> new Block(BlockBehaviour.Properties.of()
//highlight-start
Expand Down 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