@AutoLoad public class BlockDataHandler extends java.lang.Object
BlockDataHandler handles custom data being stored for a specific BlockPos.
Custom data is identified by a String identifier, and a way to convert from and into a ByteBuf using
registerBlockData(String, Function, Function).
Custom data is then stored and retrieved using setData(String, IBlockAccess, BlockPos, Object),
getData(String, IBlockAccess, BlockPos) and removeData(String, IBlockAccess, BlockPos) with the corresponding
identifier.
| Modifier and Type | Class and Description |
|---|---|
static class |
BlockDataHandler.HandlerInfo<T>
Internal container for custom data identifier and conversion from/to
ByteBuf. |
| Modifier and Type | Method and Description |
|---|---|
static BlockDataHandler |
get() |
static <T> T |
getData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos)
Gets the custom data stored at the
BlockPos for the specified identifier. |
java.util.Map<java.lang.String,BlockDataHandler.HandlerInfo<?>> |
getHandlerInfos() |
void |
onChunkWatched(net.minecraftforge.event.world.ChunkWatchEvent.Watch event)
Server only.
|
void |
onDataLoad(net.minecraftforge.event.world.ChunkDataEvent.Load event)
Saves the data in NBT for the
Chunk. |
void |
onDataSave(net.minecraftforge.event.world.ChunkDataEvent.Save event)
On data save.
|
void |
onDataUnload(net.minecraftforge.event.world.ChunkEvent.Unload event)
Unloads the data for the
Chunk. |
static <T> void |
registerBlockData(java.lang.String identifier,
com.google.common.base.Function<io.netty.buffer.ByteBuf,T> fromBytes,
com.google.common.base.Function<T,io.netty.buffer.ByteBuf> toBytes)
Registers a custom block data with the specified identifier.
|
static <T> void |
removeData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos)
Removes the custom data stored at the
BlockPos for the specified identifier. |
static <T> void |
removeData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos,
boolean sendToClients)
Removes the custom data stored at the
BlockPos for the specified identifier and eventually sends it to clients watching the
chunk. |
static <T> void |
setData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos,
T data)
Sets the custom data to be stored at the
BlockPos for the specified identifier. |
static <T> void |
setData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos,
T data,
boolean sendToClients)
Sets the custom data to be stored at the
BlockPos for the specified identifier and eventually sends the data to the clients
watching the chunk. |
public java.util.Map<java.lang.String,BlockDataHandler.HandlerInfo<?>> getHandlerInfos()
public void onDataLoad(net.minecraftforge.event.world.ChunkDataEvent.Load event)
Chunk.Chunk is marked as unloaded.event - the eventpublic void onDataSave(net.minecraftforge.event.world.ChunkDataEvent.Save event)
event - the eventpublic void onDataUnload(net.minecraftforge.event.world.ChunkEvent.Unload event)
Chunk.event - the eventpublic void onChunkWatched(net.minecraftforge.event.world.ChunkWatchEvent.Watch event)
event - the eventpublic static <T> void registerBlockData(java.lang.String identifier,
com.google.common.base.Function<io.netty.buffer.ByteBuf,T> fromBytes,
com.google.common.base.Function<T,io.netty.buffer.ByteBuf> toBytes)
T - the generic typeidentifier - the identifierfromBytes - the from bytestoBytes - the to bytespublic static <T> T getData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos)
BlockPos for the specified identifier.T - the generic typeidentifier - the identifierworld - the worldpos - the pospublic static <T> void setData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos,
T data)
BlockPos for the specified identifier.T - the generic typeidentifier - the identifierworld - the worldpos - the posdata - the datapublic static <T> void setData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos,
T data,
boolean sendToClients)
BlockPos for the specified identifier and eventually sends the data to the clients
watching the chunk.T - the generic typeidentifier - the identifierworld - the worldpos - the posdata - the datasendToClients - the send to clientspublic static <T> void removeData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos)
BlockPos for the specified identifier.T - the generic typeidentifier - the identifierworld - the worldpos - the pospublic static <T> void removeData(java.lang.String identifier,
net.minecraft.world.IBlockAccess world,
net.minecraft.util.math.BlockPos pos,
boolean sendToClients)
BlockPos for the specified identifier and eventually sends it to clients watching the
chunk.T - the generic typeidentifier - the identifierworld - the worldpos - the possendToClients - the send to clientspublic static BlockDataHandler get()