- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.2k
Additional MovementBehaviour API options #9353
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
base: mc1.21.1/dev
Are you sure you want to change the base?
Additional MovementBehaviour API options #9353
Conversation
- 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, 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! | 
| * A {@link MovementBehaviour} which allows actors to | ||
| * define custom assembly and disassembly behaviours. | ||
| */ | ||
| public interface ListeningMovementBehaviour extends MovementBehaviour { | 
There was a problem hiding this comment.
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 | 
There was a problem hiding this comment.
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 | 
There was a problem hiding this comment.
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) {} | 
There was a problem hiding this comment.
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) {} | 
There was a problem hiding this comment.
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 { | 
There was a problem hiding this comment.
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.
This PR contains small addition to the
Contraptionand associatedMovementBehaviourAPI that allows implementations to have simultaneous access to both the BlockEntity and theAbstractContraptionEntityin specific contexts where such a thing could be useful.Added
ContraptionHandoffContainerandContraptionHandoffContextrecord to store references to the state, position, and BlockEntityAdded
ListeningMovementBehavioursubinterface that has two extra methods:onAddedToContraptionandonRemovedFromContraptionAdded a list to
Contraptionthat storesContraptionHandoffContainerinstances 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
ContraptionEventand its accompanying concreteAssembleandDisassembleevents, which are invoked by theContraptionandAbstractContraptionEntityrespectively.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