This PR fixes a number of bugs relating to charms, including not being able to teleport after server restart, and a (much more minor this time) memory leak. The main change is how the list of entities is stored - it's now stored in the ServerWorld for each dimension.
The new process for implementing a charm is as follows:
Go into ServerWorldMixin and add a Map<UUID, Vec3d> for your new charm type and add it to readCharms and writeCharms so it is saved after server restart.
Add a getter for this map in IServerWorld.
Create a charm entity class by subclassing CharmEntity (renamed from FlyingItemEntity). Override the getItem method which indicates which item stack will be rendered, and the getPositionList method which should return the appropriate position list from IServerWorld.
Create a charm item class. In it, spawn the entity and call updatePosition to set the position and notsetPos (the latter method is internal anyway and should almost never be called).
Whenever you need to search for a charm, use one of the utility methods in CharmHelper, which takes the ServerWorld, charm position list, charm user and charm type as parameters, and optionally a predicate filter if you only want to select charms with certain properties.
This PR fixes a number of bugs relating to charms, including not being able to teleport after server restart, and a (much more minor this time) memory leak. The main change is how the list of entities is stored - it's now stored in the
ServerWorld
for each dimension.The new process for implementing a charm is as follows:
ServerWorldMixin
and add aMap<UUID, Vec3d>
for your new charm type and add it toreadCharms
andwriteCharms
so it is saved after server restart.IServerWorld
.CharmEntity
(renamed fromFlyingItemEntity
). Override thegetItem
method which indicates which item stack will be rendered, and thegetPositionList
method which should return the appropriate position list fromIServerWorld
.updatePosition
to set the position and notsetPos
(the latter method is internal anyway and should almost never be called).CharmHelper
, which takes theServerWorld
, charm position list, charm user and charm type as parameters, and optionally a predicate filter if you only want to select charms with certain properties.