Created Attaching TileEntity Behaviours (markdown)

simibubi 2021-08-25 17:19:54 +02:00
parent c003df5c0a
commit a012f68df2

@ -0,0 +1,16 @@
### TileEntityBehaviourEvent
Event that is fired just before a SmartTileEntity is being deserealized, alternatively just after it was newly placed.
Use it to attach a new TileEntityBehaviour or replace existing ones (with caution)
Example:
```java
forgeEventBus.addGenericListener(FunnelTileEntity.class, (TileEntityBehaviourEvent<FunnelTileEntity> event) -> event
.attach(new FunFunnelBehaviour(event.getTileEntity())));
```
Will attach the new `FunFunnelBehaviour` to any Funnels placed or loaded in
* The attached behaviour will be able to read from the tileentities tag just after it was added. See `TileEntityBehaviour#read()`
* The attached behaviour can initialize fully on its first tick. See `TileEntityBehaviour#initialize()`
* In `TileEntityBehaviour#write()`, data can be placed into the tag before serialization. That way your custom data will persist until your next read()
Within the event context, make sure the tileentity itself is only used to provide the reference for later. Its level, position and data will not be set at this time.