Skip to content

Conversation

@quattage
Copy link

@quattage quattage commented Oct 12, 2025

This PR contains small addition to the Contraption and associated MovementBehaviour API that allows implementations to have simultaneous access to both the BlockEntity and the AbstractContraptionEntity in specific contexts where such a thing could be useful.

  • Added ContraptionHandoffContainer and ContraptionHandoffContext record to store references to the state, position, and BlockEntity

  • Added ListeningMovementBehaviour subinterface that has two extra methods: onAddedToContraption and onRemovedFromContraption

  • Added a list to Contraption that stores ContraptionHandoffContainer instances and immediately disposes of them once the list is used. This list is always null except for the brief period where the contraption is transitioning between states.

  • Added ContraptionEvent and its accompanying concrete Assemble and Disassemble events, which are invoked by the Contraption and AbstractContraptionEntity respectively.

This API addition is functionally identical to a mixin I wrote that can be found here

And here's a quick example of what I'm currently using the mixin to do:

sauce2.mp4

- New NeoForge events associated with contraption assembly/disassembly
- New MovementBehaviour subinterface adds onAddedTo/onRemovedFrom for tacking additional behaviour-specific logic onto the contraption assembly/disassembly process
@quattage quattage changed the title Actor Extensions Additional MovementBehaviour API options Oct 12, 2025
@VoidLeech VoidLeech added area: api Issue or PR is related to API pr status: wrong target PR is targeting the wrong branch labels Oct 20, 2025
@github-actions
Copy link
Contributor

@quattage, this pull request is targeting the wrong branch. Pull requests should target the branch corresponding to the earliest supported Minecraft version unless the changes are specific to code that only exists for a newer Minecraft version. Please change the target branch, resolve any merge conflicts, and leave a message here so we can continue with the process of reviewing and merging this pull request. Thanks!

@quattage quattage changed the base branch from mc1.21.1/dev to mc1.20.1/dev October 22, 2025 00:03
@quattage quattage changed the base branch from mc1.20.1/dev to mc1.21.1/dev October 22, 2025 00:04
* A {@link MovementBehaviour} which allows actors to
* define custom assembly and disassembly behaviours.
*/
public interface ListeningMovementBehaviour extends MovementBehaviour {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a new interface and not just new methods for MovementBehavior?

* At the time of invocation, any Blocks or BlockEntities that may
* have existed will have already been removed, so the BlockEntity
* instance in the container is stale.
* @param world
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undocumented parameters should be omitted

* Called as an {@link AbstractContraptionEntity} is disassembling.
* This method is called after all blocks have been placed back into the world
* and the contraption entity has been removed.
* @param world
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undocumented parameters should be omitted

* @param contraption caller
* @param ctx {@link ContraptionHandoffContext} containing the now re-instantiated BlockEntity reference
*/
public default void onRemovedFromContraption(LevelAccessor world, AbstractContraptionEntity ace, Contraption contraption, ContraptionHandoffContext ctx) {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant public

* @param contraption
* @param ctx {@link ContraptionHandoffContext} containing a stale BlockEntity reference
*/
public default void onAddedToContraption(LevelAccessor world, AbstractContraptionEntity ace, Contraption contraption, ContraptionHandoffContext ctx) {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant public


import net.neoforged.neoforge.event.entity.EntityEvent;

public abstract class ContraptionEvent extends EntityEvent {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getEntity should be overidden to return an AbstractContraptionEntity.
Please add javadoc too.

@VoidLeech VoidLeech removed the pr status: wrong target PR is targeting the wrong branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: api Issue or PR is related to API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants