Difference between revisions of "Block Actions"

From wiki.vg
Jump to navigation Jump to search
(Move 1.12 changes over from pre release page)
 
(10 intermediate revisions by 4 users not shown)
Line 7: Line 7:
 
  |-
 
  |-
 
  | {{Minecraft Wiki|Note Block}}
 
  | {{Minecraft Wiki|Note Block}}
  | 25
+
  | <code>minecraft:note_block</code>
 
  | [[#Note Block|Note Block]]
 
  | [[#Note Block|Note Block]]
 
  |-
 
  |-
 
  | {{Minecraft Wiki|Piston}}
 
  | {{Minecraft Wiki|Piston}}
  | 33
+
  | <code>minecraft:piston</code>
 
  |rowspan="2"| [[#Piston|Piston]]
 
  |rowspan="2"| [[#Piston|Piston]]
 
  |-
 
  |-
 
  | {{Minecraft Wiki|Sticky Piston}}
 
  | {{Minecraft Wiki|Sticky Piston}}
  | 29
+
  | <code>minecraft:sticky_piston</code>
 
  |-
 
  |-
 
  | {{Minecraft Wiki|Chest}}
 
  | {{Minecraft Wiki|Chest}}
  | 54
+
  | <code>minecraft:chest</code>
  |rowspan="2"| [[#Chest|Chest]]
+
  |rowspan="3"| [[#Chest|Chest]]
 
  |-
 
  |-
 
  | {{Minecraft Wiki|Trapped Chest}}
 
  | {{Minecraft Wiki|Trapped Chest}}
  | 146
+
  | <code>minecraft:trapped_chest</code>
 
  |-
 
  |-
 
  | {{Minecraft Wiki|Ender Chest}}
 
  | {{Minecraft Wiki|Ender Chest}}
  | 130
+
  | <code>minecraft:ender_chest</code>
| [[#Ender Chest|Ender Chest]]
 
|-
 
| {{Minecraft Wiki|Beacon}}
 
| 138
 
| [[#Beacon|Beacon]]
 
 
  |-
 
  |-
 
  | {{Minecraft Wiki|Mob Spawner}}
 
  | {{Minecraft Wiki|Mob Spawner}}
  | 52
+
  | <code>minecraft:mob_spawner</code>
 
  | [[#Spawner|Spawner]]
 
  | [[#Spawner|Spawner]]
 
  |-
 
  |-
 
  | {{Minecraft Wiki|End Gateway}}
 
  | {{Minecraft Wiki|End Gateway}}
  | 209
+
  | <code>minecraft:end_gateway</code>
 
  | [[#End Gateway|End Gateway]]
 
  | [[#End Gateway|End Gateway]]
 
  |-
 
  |-
 
  | {{Minecraft Wiki|Shulker Box}}
 
  | {{Minecraft Wiki|Shulker Box}}
  | 219-234
+
  | <code>minecraft:shulker_box</code>
 +
<code>minecraft:''<color>''_shulker_box</code>
 
  | [[#Shulker Box|Shulker Box]]
 
  | [[#Shulker Box|Shulker Box]]
 +
|-
 +
| {{Minecraft Wiki|Bell}}
 +
| <code>minecraft:bell</code>
 +
| [[#Bell|Bell]]
 
  |-
 
  |-
 
  |colspan="2"| Anything else
 
  |colspan="2"| Anything else
Line 51: Line 51:
  
 
Displays a colored note particle and plays the appropriate note sound effect.
 
Displays a colored note particle and plays the appropriate note sound effect.
 +
 +
In 1.13, the parameters are no longer used to determine what effect to use; instead, the information is obtained from the block state.
 +
 +
More information about how the pitch values correspond to notes in real life and how they correspond to pitch scaling on the sound effects can be found in the {{Minecraft Wiki|Note Block}} article on the Minecraft wiki.
  
 
=== Action IDs ===
 
=== Action IDs ===
  
The action ID is used to determine the instrument to play.
+
Ignored, always 0.
  
{| class="wikitable"
+
=== Action Parameters ===
|-
+
 
! Type ID
+
Ignored, always 0.
! Instrument
 
! Material/block
 
! Sound
 
|-
 
| 0
 
| Harp
 
| Any other material
 
| <code>block.note.harp</code>
 
|-
 
| 1
 
| Bass Drum
 
| Stone
 
| <code>block.note.harp</code>
 
|-
 
| 2
 
| Snare Drum
 
| Sand
 
| <code>block.note.snare</code>
 
|-
 
| 3
 
| Clicks/Sticks
 
| Glass
 
| <code>block.note.hat</code>
 
|-
 
| 4
 
| Bass guitar
 
| Wood
 
| <code>block.note.bass</code>
 
|-
 
| 5
 
| Flute
 
| Clay
 
| <code>block.note.flute</code>
 
|-
 
| 6
 
| Bell
 
| Gold block
 
| <code>block.note.bell</code>
 
|-
 
| 7
 
| Guitar
 
| Wool
 
| <code>block.note.guitar</code>
 
|-
 
| 8
 
| Chime
 
| Packed ice
 
| <code>block.note.chime</code>
 
|-
 
| 9
 
| Xylophone
 
| Bone block
 
| <code>block.note.xylophone</code>
 
|}
 
  
Any unknown ID is treated as if it were <code>0</code>.
+
== Piston ==
  
The sound event <code>block.note.pling</code> is unassigned and unused.
+
Controls the state of the piston and affected blocks. Always used on the piston base (either sticky or regular), never on the head.
  
=== Action param ===
+
{{Need Info|The tick logic for moving piston block entities is the roughly the same for both client and server, except that the client will wait an extra 5 ticks before setting the pushed blocks to their new state. Why does this happen? Why does the client even set the new blocks on its own in the first place, if their final state is going to be received by the server anyway? Is it a lag-compensation mechanism?}}
  
The pitch of the note (between 0–24 inclusive where 0 is the lowest and 24 is the highest). More information about how the pitch values correspond to notes in real life and how they correspond to pitch scaling on the sound effects can be found in the {{Minecraft Wiki|Note Block}} article on the Minecraft wiki.
+
Upon receiving this action, the Notchian client is responsible for:
 +
* Calculating if the action is possible, and which blocks will be affected;
 +
* Changing pushed blocks into <code>MOVING_PISTON</code> blocks and their respective moving piston block entities (client-side only);
 +
* Changing the pushed blocks' new block states once the action is finished (action takes 3 ticks, but blocks are set after an extra 5 ticks; client-side only).
  
== Piston ==
+
On the other hand, the server Notchian server is responsible for:
 +
* Calculating if the action is possible, and which blocks will be affected;
 +
* Initiating the actual action through the [[Protocol#Block_Action|Block Action]] packet;
 +
* Playing the piston extend/retract sound;
 +
* Changing pushed blocks into <code>MOVING_PISTON</code> blocks and their respective moving piston block entities (server-side only);
 +
* Immediately sending updates for blocks that would be destroyed by the piston action (through [[Protocol#Block_Update|Block Update]] or [[Protocol#Update_Section_Blocks|Update Section Blocks]]);
 +
* Calculate entity collision mid-push/mid-pull and update their position accordingly;
 +
* Changing the pushed blocks' new block states once the action is finished (after 3 ticks, through [[Protocol#Block_Update|Block Update]] or [[Protocol#Update_Section_Blocks|Update Section Blocks]]).
  
Extends or retracts the piston.  Always used on the piston base (either sticky or regular), never on the head.  Also plays the extending/retracting sound.
 
  
{{Need Info|It's unclear what blocks and tile entities the client needs to create, and which ones the server creates. From a rough glance, it seems like the server changes the piston base block, but the client needs to create the piston head, create the block 36es, and create the piston moving tile entities. As such, the server needs to make the same assumptions as the client, or else ghost blocks may occur.}}
+
{{Warning2|Some important points to be noted about the Notchian implementations are:
 +
* The calculation for blocks to be pushed/destroyed is the same on both server and client, and they rely on that assumption. Attempting to change the logic in one side may lead to de-sync issues.
 +
* Although the server creates <code>MOVING_PISTON</code> blocks and moving piston block entities, they're not sent to the client, and are kept on the server merely to keep track of the action progression (to handle collision, block changes upon completion etc.). The client is responsible for creating such blocks and entities on its side upon receiving [[Protocol#Block_Action|Block Action]] packet.
 +
* <code>MOVING_PISTON</code> blocks and moving piston block entities can be received in a [[Protocol#Chunk_Data_and_Update_Light|Chunk Data]] packet. However, the block entity data is ignored by the client and <code>MOVING_PISTON</code> blocks are set in their default state (empty). This could potentially be intentional, as the piston animation is short (3 ticks long), and the client will subsequently receive updates for the final block states from the server;}}
  
 
=== Action IDs ===
 
=== Action IDs ===
  
'''0''' to extend the piston, '''1''' to retract it.
+
'''0''' to extend the piston, '''1''' to retract it, and '''2''' to cancel an ongoing extension.
  
=== Action param ===
+
In Notchian implementations, action ID '''2''' is defined by when a piston is retracted (e.g.: due to loss of power) mid-extension. The semantics for this action also change based on the type of piston:
 +
* if the piston is a normal one, the action has the same result as a normal retraction;
 +
* if the piston is a sticky one, it will be retracted without pulling any blocks.
  
The direction the piston is facing (which is a metadata field on the piston). This is only used when the piston is retracting to generate the nearest block 36; all other parts appear ignore this parameter and use the piston's actual metadata field.
+
{{Warning|Sending an extension action to an already-extended piston has no effect, but sending retraction actions to an already-retracted piston may cause undesired results, such as the block directly in front of the piston head dissappearing on the client.}}
 +
 
 +
=== Action Parameters ===
 +
 
 +
The direction the piston is facing.
 +
 
 +
Any value can be sent for piston extension, since the direction is infered from the piston's block state, but it must match the actual direction for piston retractions (action ID '''1''' and '''2''').
 +
 
 +
{{Warning|Sending a mismatched direction for piston extension has no effect, but sending a mismatched direction to piston retractions will cause the piston block to assume the new sent direction on the client.}}
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 164: Line 136:
 
=== Action IDs ===
 
=== Action IDs ===
  
There is only one action, with ID '''1'''. It is used to update the number of players who are looking in the chest, which in turn is used to update lid animation.
+
There is only one action, with ID '''1'''. It is used to update the number of players who are looking in the chest, which in turn is used to update lid animation.
 
 
This value seems to be recalculated every 200 ticks, but isn't resent until a player closes/reopens.
 
 
 
=== Action param ===
 
 
 
When the action ID is 1, this is the number of players who have the chest open.  If 0, then the chest is closed; if 1 or more the chest is open.
 
 
 
== Ender chest ==
 
 
 
=== Action IDs ===
 
 
 
There is only one action, with ID '''1'''.  It is used to update the number of players who are looking in the ender chest, which in turn is used to update lid animation.  This is recalculated and resent every 80 ticks (4 seconds), even if the value hasn't changed.
 
 
 
=== Action param ===
 
  
When the action ID is 1, this is the number of players who have the chest open. If 0, then the chest is closed; if 1 or more the chest is open.
+
The Notchian server sends this whenever a player opens or closes the chest, and every 5 ticks (0.25 seconds) while at least one player has the chest open.
  
== Beacon ==
+
=== Action Parameters ===
  
=== Action IDs ===
+
When the action ID is 1, this is the number of players who have the chest open. If 0, then the chest is closed; if 1 or more the chest is open.
 
 
There is only one action, with ID '''1'''.  It is used to tell the client to recalculate the beacon beam. This happens whenever the beacon base receives a block update.  Additionally, whenever a stained glass block or stained glass pane is placed above a beacon that can see the sky.  The client goes through all blocks above the beacon, disabling/enabling the beam if it is covered and recoloring the beam if it passes through glass or stained glass.
 
 
 
Note that the beacon beam is also recomputed every 80 ticks (4 seconds), but no block action occurs when that happens.  The block action allows placing of a beacon and recoloring of the beam to potentially be instant, but does not make all other changes to the beam instant.
 
 
 
=== Action param ===
 
 
 
Ignored.
 
  
 
== Spawner ==
 
== Spawner ==
Line 200: Line 150:
 
There is only one action, with ID '''1''', which resets the delay in the spawner to the minimum spawn delay.
 
There is only one action, with ID '''1''', which resets the delay in the spawner to the minimum spawn delay.
  
=== Action param ===
+
=== Action Parameters ===
  
 
Ignored.
 
Ignored.
  
== End gateway ==
+
== End Gateway ==
  
 
=== Action ID ===
 
=== Action ID ===
  
There is only one action, with ID '''1''', which triggers the {{Minecraft Wiki|End Gateway (block)#Beam|magenta beam}} emitted by the end gateway when an entity passes through it.
+
There is only one action, with ID '''1''', which triggers the {{Minecraft Wiki|End Gateway (block)#Beam|purple beam}} emitted by the end gateway when an entity passes through it.
  
=== Action param ===
+
=== Action Parameters ===
  
 
Ignored.
 
Ignored.
 
[[Category:Minecraft Modern]]
 
  
 
== Shulker Box ==
 
== Shulker Box ==
Line 224: Line 172:
 
There is only one action: 1, which updates the number of players who are looking in the shulker box.
 
There is only one action: 1, which updates the number of players who are looking in the shulker box.
  
=== Action param ===
+
=== Action Parameters ===
  
 
If the action is 1, updates the number of players who have the shulker box open.  If 0, the shulker box enters its closing animation; if 1, the shulker box enters its opening animation.
 
If the action is 1, updates the number of players who have the shulker box open.  If 0, the shulker box enters its closing animation; if 1, the shulker box enters its opening animation.
 +
 +
== Bell ==
 +
 +
Causes the bell to perform the ring animation.  The ring sound is handled in a separate [[Protocol#Sound Effect|Sound Effect]] packet.
 +
 +
=== Action IDs ===
 +
 +
There is only one action: 1, which triggers the bell animation.
 +
 +
=== Action Parameters ===
 +
 +
If the action is 1, this is the direction from which the bell was rung (down=0, up=1, north=2, south=3, west=4, east=5).  If the bell was rung by a player, this is the face of the block they clicked on; otherwise, it is based on the bell's facing state.  After 5 ticks, if there are raiders nearby, the bell resonates and 40 ticks later causes them to glow for 60 ticks.  Whether there are raiders nearby will only be recalculated if 60 ticks have passed since the last recalculation.
 +
 +
[[Category:Protocol Details]]
 +
[[Category:Minecraft Modern]]

Latest revision as of 18:50, 26 February 2024

These block actions are used in the Block Action packet. Depending on the block, different action IDs mean different things:

Block ID Section
Note Block minecraft:note_block Note Block
Piston minecraft:piston Piston
Sticky Piston minecraft:sticky_piston
Chest minecraft:chest Chest
Trapped Chest minecraft:trapped_chest
Ender Chest minecraft:ender_chest
Mob Spawner minecraft:mob_spawner Spawner
End Gateway minecraft:end_gateway End Gateway
Shulker Box minecraft:shulker_box

minecraft:<color>_shulker_box

Shulker Box
Bell minecraft:bell Bell
Anything else Ignored

Note Block

Displays a colored note particle and plays the appropriate note sound effect.

In 1.13, the parameters are no longer used to determine what effect to use; instead, the information is obtained from the block state.

More information about how the pitch values correspond to notes in real life and how they correspond to pitch scaling on the sound effects can be found in the Note Block article on the Minecraft wiki.

Action IDs

Ignored, always 0.

Action Parameters

Ignored, always 0.

Piston

Controls the state of the piston and affected blocks. Always used on the piston base (either sticky or regular), never on the head.

Huh.png The following information needs to be added to this page:
The tick logic for moving piston block entities is the roughly the same for both client and server, except that the client will wait an extra 5 ticks before setting the pushed blocks to their new state. Why does this happen? Why does the client even set the new blocks on its own in the first place, if their final state is going to be received by the server anyway? Is it a lag-compensation mechanism?

Upon receiving this action, the Notchian client is responsible for:

  • Calculating if the action is possible, and which blocks will be affected;
  • Changing pushed blocks into MOVING_PISTON blocks and their respective moving piston block entities (client-side only);
  • Changing the pushed blocks' new block states once the action is finished (action takes 3 ticks, but blocks are set after an extra 5 ticks; client-side only).

On the other hand, the server Notchian server is responsible for:

  • Calculating if the action is possible, and which blocks will be affected;
  • Initiating the actual action through the Block Action packet;
  • Playing the piston extend/retract sound;
  • Changing pushed blocks into MOVING_PISTON blocks and their respective moving piston block entities (server-side only);
  • Immediately sending updates for blocks that would be destroyed by the piston action (through Block Update or Update Section Blocks);
  • Calculate entity collision mid-push/mid-pull and update their position accordingly;
  • Changing the pushed blocks' new block states once the action is finished (after 3 ticks, through Block Update or Update Section Blocks).


Warning.png Some important points to be noted about the Notchian implementations are:

  • The calculation for blocks to be pushed/destroyed is the same on both server and client, and they rely on that assumption. Attempting to change the logic in one side may lead to de-sync issues.
  • Although the server creates MOVING_PISTON blocks and moving piston block entities, they're not sent to the client, and are kept on the server merely to keep track of the action progression (to handle collision, block changes upon completion etc.). The client is responsible for creating such blocks and entities on its side upon receiving Block Action packet.
  • MOVING_PISTON blocks and moving piston block entities can be received in a Chunk Data packet. However, the block entity data is ignored by the client and MOVING_PISTON blocks are set in their default state (empty). This could potentially be intentional, as the piston animation is short (3 ticks long), and the client will subsequently receive updates for the final block states from the server;

Action IDs

0 to extend the piston, 1 to retract it, and 2 to cancel an ongoing extension.

In Notchian implementations, action ID 2 is defined by when a piston is retracted (e.g.: due to loss of power) mid-extension. The semantics for this action also change based on the type of piston:

  • if the piston is a normal one, the action has the same result as a normal retraction;
  • if the piston is a sticky one, it will be retracted without pulling any blocks.

Warning.png Sending an extension action to an already-extended piston has no effect, but sending retraction actions to an already-retracted piston may cause undesired results, such as the block directly in front of the piston head dissappearing on the client.

Action Parameters

The direction the piston is facing.

Any value can be sent for piston extension, since the direction is infered from the piston's block state, but it must match the actual direction for piston retractions (action ID 1 and 2).

Warning.png Sending a mismatched direction for piston extension has no effect, but sending a mismatched direction to piston retractions will cause the piston block to assume the new sent direction on the client.

Direction ID Direction
0 Down
1 Up
2 South
3 West
4 North
5 East

Chest

Action IDs

There is only one action, with ID 1. It is used to update the number of players who are looking in the chest, which in turn is used to update lid animation.

The Notchian server sends this whenever a player opens or closes the chest, and every 5 ticks (0.25 seconds) while at least one player has the chest open.

Action Parameters

When the action ID is 1, this is the number of players who have the chest open. If 0, then the chest is closed; if 1 or more the chest is open.

Spawner

Action ID

There is only one action, with ID 1, which resets the delay in the spawner to the minimum spawn delay.

Action Parameters

Ignored.

End Gateway

Action ID

There is only one action, with ID 1, which triggers the purple beam emitted by the end gateway when an entity passes through it.

Action Parameters

Ignored.

Shulker Box

Animates the shulker box's shell opening.

Action IDs

There is only one action: 1, which updates the number of players who are looking in the shulker box.

Action Parameters

If the action is 1, updates the number of players who have the shulker box open. If 0, the shulker box enters its closing animation; if 1, the shulker box enters its opening animation.

Bell

Causes the bell to perform the ring animation. The ring sound is handled in a separate Sound Effect packet.

Action IDs

There is only one action: 1, which triggers the bell animation.

Action Parameters

If the action is 1, this is the direction from which the bell was rung (down=0, up=1, north=2, south=3, west=4, east=5). If the bell was rung by a player, this is the face of the block they clicked on; otherwise, it is based on the bell's facing state. After 5 ticks, if there are raiders nearby, the bell resonates and 40 ticks later causes them to glow for 60 ticks. Whether there are raiders nearby will only be recalculated if 60 ticks have passed since the last recalculation.