Class PMWStorage<D extends StorageData>

java.lang.Object
net.nullved.pmweatherapi.storage.PMWStorage<D>
All Implemented Interfaces:
IStorage<D>
Direct Known Subclasses:
MetarStorage, RadarStorage, WSRStorage

public abstract class PMWStorage<D extends StorageData> extends Object implements IStorage<D>
A basic IStorage implementation that should cover most, if not all, use-cases.

A "Storage" saves and maintains a list of IStorageData on the Level that can be reloaded on world load. It does this by separating each IStorageData by chunk (more specifically, by ChunkPos)

Any IStorageData can be saved, regardless of type, however, both server and clients must expect the same data structure. For example, RadarStorage is meant to store the positions of RadarBlocks in the world

PMWStorage does not handle syncing radars from the server to the client, instead, implement ISyncServerStorage on a Server Storage and IClientStorage on a Client Storage. To sync using your own method, implement IServerStorage on the Server Storage instead.

For your storage to be saved, you must first register it using PMWStorages.registerStorage(ResourceLocation, Class, Function) on both sides, and PMWClientStorages.registerStorage(ResourceLocation, Class, Function) on the client-side only

For a full implementation example, see RadarStorage, RadarServerStorage, and RadarClientStorage
Since:
0.15.3.3
See Also:
  • Constructor Details

    • PMWStorage

      public PMWStorage(net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension)
      The base constructor
      Parameters:
      dimension - The dimension of the IStorage
      Since:
      0.15.3.3
  • Method Details

    • clean

      public void clean()
      Specified by:
      clean in interface IStorage<D extends StorageData>
    • getExpectedDataType

      public abstract net.minecraft.resources.ResourceLocation getExpectedDataType()
    • getLevel

      public abstract net.minecraft.world.level.Level getLevel()
      Gets the level associated with this IStorage. For the client side, it returns the ClientLevel. For the server side, it returns a ServerLevel.
      Specified by:
      getLevel in interface IStorage<D extends StorageData>
      Returns:
      A Level instance
      Since:
      0.15.3.3
    • getId

      public abstract net.minecraft.resources.ResourceLocation getId()
      The ResourceLocation ID of this IStorage. Used primarily for saving to the file at data/<namespace>_<path>.dat.
      Specified by:
      getId in interface IStorage<D extends StorageData>
      Returns:
      A ResourceLocation
      Since:
      0.15.3.3
    • version

      public abstract int version()
      The version of this IStorage. To disable version data from being saved, return -1
      Specified by:
      version in interface IStorage<D extends StorageData>
      Returns:
      The version of the saved data
      Since:
      0.15.3.3
    • getAll

      public Set<D> getAll()
      Gets a Set of every IStorageData saved in this IStorage, regardless of ChunkPos
      Specified by:
      getAll in interface IStorage<D extends StorageData>
      Returns:
      Every saved IStorageData
      Since:
      0.15.3.3
    • getAllWithinRange

      public Set<D> getAllWithinRange(net.minecraft.core.BlockPos base, double radius)
      Specified by:
      getAllWithinRange in interface IStorage<D extends StorageData>
    • getInChunk

      public Set<D> getInChunk(net.minecraft.world.level.ChunkPos pos)
      Gets the Set of IStorageData for this ChunkPos
      Specified by:
      getInChunk in interface IStorage<D extends StorageData>
      Parameters:
      pos - The ChunkPos to search
      Returns:
      A Set of the IStorageData in this chunk
      Since:
      0.15.3.3
    • getInAdjacentChunks

      public Set<D> getInAdjacentChunks(net.minecraft.world.level.ChunkPos pos)
      Specified by:
      getInAdjacentChunks in interface IStorage<D extends StorageData>
    • shouldRecalculate

      public boolean shouldRecalculate(net.minecraft.world.level.ChunkPos pos)
      Determines if the data for the given ChunkPos is older than 30 seconds or does not exist. Intended to be used while listening to a ChunkWatchEvent.Sent event (See PMWEvents)
      Specified by:
      shouldRecalculate in interface IStorage<D extends StorageData>
      Parameters:
      pos - The ChunkPos to check
      Returns:
      Whether the data should be recalculated or not
      Since:
      0.15.3.3
    • add

      public void add(D addData)
      Adds a single IStorageData to the IStorage
      Specified by:
      add in interface IStorage<D extends StorageData>
      Parameters:
      addData - The new IStorageData
      Since:
      0.15.3.3
    • add

      public void add(Collection<D> datum)
      Adds multiple new IStorageData to the IStorage
      Specified by:
      add in interface IStorage<D extends StorageData>
      Parameters:
      datum - A Collection of new IStorageData
      Since:
      0.15.3.3
    • remove

      public void remove(net.minecraft.core.BlockPos pos)
      Removes a single BlockPos from the IStorage
      Specified by:
      remove in interface IStorage<D extends StorageData>
      Parameters:
      pos - The BlockPos to remove
      Since:
      0.15.3.3
    • removeByPos

      public void removeByPos(Collection<net.minecraft.core.BlockPos> pos)
      Removes multiple BlockPos from the IStorage
      Specified by:
      removeByPos in interface IStorage<D extends StorageData>
      Parameters:
      pos - A Collection of BlockPos to remove
      Since:
      0.15.3.3
    • remove

      public void remove(D removedData)
      Removes a single IStorageData from the IStorage
      Specified by:
      remove in interface IStorage<D extends StorageData>
      Parameters:
      removedData - The IStorageData to remove
      Since:
      0.15.3.3
    • removeByData

      public void removeByData(Collection<D> datum)
      Removes multiple IStorageData from the IStorage
      Specified by:
      removeByData in interface IStorage<D extends StorageData>
      Parameters:
      datum - A Collection of IStorageData to remove
      Since:
      0.15.3.3
    • save

      public net.minecraft.nbt.CompoundTag save(net.minecraft.nbt.CompoundTag tag)
      Saves the data of this IStorage to a CompoundTag
      Specified by:
      save in interface IStorage<D extends StorageData>
      Parameters:
      tag - The pre-existing CompoundTag
      Returns:
      A CompoundTag with storage data
      Since:
      0.15.3.3
    • read

      public void read()
      Reads the saved data from the Level and initializes this IStorage with the data
      Specified by:
      read in interface IStorage<D extends StorageData>
      Since:
      0.15.3.3