Package net.nullved.pmweatherapi.storage
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
A basic
A "Storage" saves and maintains a list of
Any
For your storage to be saved, you must first register it using
For a full implementation example, see
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 Summary
ConstructorsConstructorDescriptionPMWStorage(net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension) The base constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a singleIStorageDatato theIStoragevoidadd(Collection<D> datum) Adds multiple newIStorageDatato theIStoragevoidclean()getAll()getAllWithinRange(net.minecraft.core.BlockPos base, double radius) abstract net.minecraft.resources.ResourceLocationabstract net.minecraft.resources.ResourceLocationgetId()TheResourceLocationID of thisIStorage.getInAdjacentChunks(net.minecraft.world.level.ChunkPos pos) getInChunk(net.minecraft.world.level.ChunkPos pos) abstract net.minecraft.world.level.LevelgetLevel()Gets the level associated with thisIStorage.voidread()Reads the saved data from theLeveland initializes thisIStoragewith the datavoidRemoves a singleIStorageDatafrom theIStoragevoidremove(net.minecraft.core.BlockPos pos) Removes a singleBlockPosfrom theIStoragevoidremoveByData(Collection<D> datum) Removes multipleIStorageDatafrom theIStoragevoidremoveByPos(Collection<net.minecraft.core.BlockPos> pos) Removes multipleBlockPosfrom theIStoragenet.minecraft.nbt.CompoundTagsave(net.minecraft.nbt.CompoundTag tag) Saves the data of thisIStorageto aCompoundTagbooleanshouldRecalculate(net.minecraft.world.level.ChunkPos pos) Determines if the data for the givenChunkPosis older than 30 seconds or does not exist.abstract intversion()The version of thisIStorage.
-
Constructor Details
-
PMWStorage
public PMWStorage(net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension) The base constructor- Parameters:
dimension- The dimension of theIStorage- Since:
- 0.15.3.3
-
-
Method Details
-
clean
public void clean()- Specified by:
cleanin interfaceIStorage<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 thisIStorage. For the client side, it returns theClientLevel. For the server side, it returns aServerLevel.- Specified by:
getLevelin interfaceIStorage<D extends StorageData>- Returns:
- A
Levelinstance - Since:
- 0.15.3.3
-
getId
public abstract net.minecraft.resources.ResourceLocation getId()TheResourceLocationID of thisIStorage. Used primarily for saving to the file atdata/<namespace>_<path>.dat.- Specified by:
getIdin interfaceIStorage<D extends StorageData>- Returns:
- A
ResourceLocation - Since:
- 0.15.3.3
-
version
public abstract int version()The version of thisIStorage. To disable version data from being saved, return-1- Specified by:
versionin interfaceIStorage<D extends StorageData>- Returns:
- The version of the saved data
- Since:
- 0.15.3.3
-
getAll
- Specified by:
getAllin interfaceIStorage<D extends StorageData>- Returns:
- Every saved
IStorageData - Since:
- 0.15.3.3
-
getAllWithinRange
- Specified by:
getAllWithinRangein interfaceIStorage<D extends StorageData>
-
getInChunk
- Specified by:
getInChunkin interfaceIStorage<D extends StorageData>- Parameters:
pos- TheChunkPosto search- Returns:
- A
Setof theIStorageDatain this chunk - Since:
- 0.15.3.3
-
getInAdjacentChunks
- Specified by:
getInAdjacentChunksin interfaceIStorage<D extends StorageData>
-
shouldRecalculate
public boolean shouldRecalculate(net.minecraft.world.level.ChunkPos pos) Determines if the data for the givenChunkPosis older than 30 seconds or does not exist. Intended to be used while listening to aChunkWatchEvent.Sentevent (SeePMWEvents)- Specified by:
shouldRecalculatein interfaceIStorage<D extends StorageData>- Parameters:
pos- TheChunkPosto check- Returns:
- Whether the data should be recalculated or not
- Since:
- 0.15.3.3
-
add
Adds a singleIStorageDatato theIStorage- Specified by:
addin interfaceIStorage<D extends StorageData>- Parameters:
addData- The newIStorageData- Since:
- 0.15.3.3
-
add
Adds multiple newIStorageDatato theIStorage- Specified by:
addin interfaceIStorage<D extends StorageData>- Parameters:
datum- ACollectionof newIStorageData- Since:
- 0.15.3.3
-
remove
public void remove(net.minecraft.core.BlockPos pos) Removes a singleBlockPosfrom theIStorage- Specified by:
removein interfaceIStorage<D extends StorageData>- Parameters:
pos- TheBlockPosto remove- Since:
- 0.15.3.3
-
removeByPos
Removes multipleBlockPosfrom theIStorage- Specified by:
removeByPosin interfaceIStorage<D extends StorageData>- Parameters:
pos- ACollectionofBlockPosto remove- Since:
- 0.15.3.3
-
remove
Removes a singleIStorageDatafrom theIStorage- Specified by:
removein interfaceIStorage<D extends StorageData>- Parameters:
removedData- TheIStorageDatato remove- Since:
- 0.15.3.3
-
removeByData
Removes multipleIStorageDatafrom theIStorage- Specified by:
removeByDatain interfaceIStorage<D extends StorageData>- Parameters:
datum- ACollectionofIStorageDatato remove- Since:
- 0.15.3.3
-
save
public net.minecraft.nbt.CompoundTag save(net.minecraft.nbt.CompoundTag tag) Saves the data of thisIStorageto aCompoundTag- Specified by:
savein interfaceIStorage<D extends StorageData>- Parameters:
tag- The pre-existingCompoundTag- Returns:
- A
CompoundTagwith storage data - Since:
- 0.15.3.3
-
read
public void read()Reads the saved data from theLeveland initializes thisIStoragewith the data- Specified by:
readin interfaceIStorage<D extends StorageData>- Since:
- 0.15.3.3
-