Modding:Advanced Blocks: Difference between revisions
From Vintage Story Wiki
Ninjanomnom (talk | contribs) m (Double checked information and updated version) |
(→The Block Class: Add a link to Modding:Block_Cardinality) |
||
Line 66: | Line 66: | ||
So how do we implement a bouncy block? It's pretty helpful to take a look at the [https://apidocs.vintagestory.at/api/Vintagestory.API.Common.Block.html api documentation] to find a proper way to implement it. | So how do we implement a bouncy block? It's pretty helpful to take a look at the [https://apidocs.vintagestory.at/api/Vintagestory.API.Common.Block.html api documentation] to find a proper way to implement it. | ||
The method <code>void onEntityCollide(IWorldAccessor world, Entity entity, BlockPos pos, BlockFacing facing, bool isImpact)</code> seems to be a good way to implement a bouncy functionality. | The method <code>void onEntityCollide(IWorldAccessor world, Entity entity, BlockPos pos, BlockFacing facing, bool isImpact)</code> seems to be a good way to implement a bouncy functionality. Note that every trampoline block placed in the game will [[Modding:Block_Cardinality|share]] the same instance of <code>TrampolineBlock</code>. Because that object is shared by multiple blocks, it does not have a field for the block position. That's why the event handler includes the <code>pos</code> parameter. | ||
'''When should an entity bounce?''' | '''When should an entity bounce?''' |