User Tools

Site Tools


tutorial:blockentity

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tutorial:blockentity [2019/07/22 17:37]
fudge override -> implement, remove superfluous information
tutorial:blockentity [2019/07/22 17:38] (current)
fudge typo
Line 85: Line 85:
 Once you have implemented the ''​toTag''​ and ''​fromTag''​ methods, you simply need to ensure that they are called at the right time. Whenever your ''​BlockEntity''​ data changes and needs to be saved, call ''​markDirty()''​. This will force the ''​toTag''​ method to be called when the world is next saved by marking the chunk which your block is in as dirty. As a general rule of thumb, simply call ''​markDirty()''​ whenever you change any custom variable in your ''​BlockEntity''​ class. Once you have implemented the ''​toTag''​ and ''​fromTag''​ methods, you simply need to ensure that they are called at the right time. Whenever your ''​BlockEntity''​ data changes and needs to be saved, call ''​markDirty()''​. This will force the ''​toTag''​ method to be called when the world is next saved by marking the chunk which your block is in as dirty. As a general rule of thumb, simply call ''​markDirty()''​ whenever you change any custom variable in your ''​BlockEntity''​ class.
  
-If you need to sync some of your ''​BlockEntity''​ data to the client, for purposes such as rendering, you should implement ''​BlockEntityClientSerializablle''​ from the Fabric API. This class provides the ''​fromClientTag''​ and ''​toClientTag''​ methods, which work much the same as the previously discussed ''​fromTag''​ and ''​toTag''​ methods, except that they are used specifically for sending to and receiving data on the client. ​+If you need to sync some of your ''​BlockEntity''​ data to the client, for purposes such as rendering, you should implement ''​BlockEntityClientSerializable''​ from the Fabric API. This class provides the ''​fromClientTag''​ and ''​toClientTag''​ methods, which work much the same as the previously discussed ''​fromTag''​ and ''​toTag''​ methods, except that they are used specifically for sending to and receiving data on the client. ​
  
 ===== Overview ===== ===== Overview =====
  
 You should now have your very own ''​BlockEntity'',​ which you can expand in various ways to suit your needs. You registered a ''​BlockEntityType'',​ and used it to connect your ''​Block''​ and ''​BlockEntity''​ classes together. Then, you implemented ''​BlockEntityProvider''​ in your ''​Block''​ class, and used the interface to provide an instance of your new ''​BlockEntity''​. Finally, you learned how to save data to your ''​BlockEntity'',​ and how to retrieve for use later. You should now have your very own ''​BlockEntity'',​ which you can expand in various ways to suit your needs. You registered a ''​BlockEntityType'',​ and used it to connect your ''​Block''​ and ''​BlockEntity''​ classes together. Then, you implemented ''​BlockEntityProvider''​ in your ''​Block''​ class, and used the interface to provide an instance of your new ''​BlockEntity''​. Finally, you learned how to save data to your ''​BlockEntity'',​ and how to retrieve for use later.
tutorial/blockentity.txt ยท Last modified: 2019/07/22 17:38 by fudge