Files
ChunkAPI/src/main/java/com/falsepattern/chunk/api/ChunkDataManager.java
T

62 lines
1.9 KiB
Java
Raw Normal View History

2023-03-09 21:44:17 +01:00
package com.falsepattern.chunk.api;
2023-03-28 23:58:39 +02:00
import org.jetbrains.annotations.NotNull;
2023-03-09 21:44:17 +01:00
import net.minecraft.nbt.NBTTagCompound;
2023-03-28 23:58:39 +02:00
import java.nio.ByteBuffer;
2023-03-09 21:44:17 +01:00
/**
* Singleton instances that can manage custom in chunks.
2023-03-29 00:26:15 +02:00
* <p>
* Implementations should be stateless and thread-safe.
* @implNote For performance reasons, you should store any data in the chunk itself using a mixin. The type T is the type
2023-03-28 23:58:39 +02:00
* of the interface that you are mixing into the chunk.
2023-03-09 21:44:17 +01:00
*/
2023-03-28 23:58:39 +02:00
public interface ChunkDataManager<T> {
/**
* @return The domain of this manager. Usually the modid of the mod that owns this manager.
*/
String domain();
2023-03-09 21:44:17 +01:00
/**
2023-03-28 23:58:39 +02:00
* @return The id of this manager. Usually the name of the manager. Unique per domain.
2023-03-09 21:44:17 +01:00
*/
String id();
2023-03-28 23:58:39 +02:00
2023-03-09 21:44:17 +01:00
/**
2023-03-28 23:58:39 +02:00
* @implNote This is used to determine the size of the packet compression/decompression buffer.
* @return The maximum amount of bytes your data can take up in a packet.
2023-03-09 21:44:17 +01:00
*/
2023-03-28 23:58:39 +02:00
int maxPacketSize();
2023-03-09 21:44:17 +01:00
/**
2023-03-28 23:58:39 +02:00
* Serializes your data into a packet.
*
* @param chunk The chunk to serialize.
2023-03-09 21:44:17 +01:00
*/
2023-03-28 23:58:39 +02:00
void writeToBuffer(T chunk, int ebsMask, boolean forceUpdate, ByteBuffer data);
2023-03-09 21:44:17 +01:00
/**
2023-03-28 23:58:39 +02:00
* Deserializes your data from a packet.
* Mutates this object.
*
* @param chunk The chunk to deserialize.
2023-03-09 21:44:17 +01:00
* @param buffer The packet buffer to read from.
*/
2023-03-28 23:58:39 +02:00
void readFromBuffer(T chunk, int ebsMask, boolean forceUpdate, ByteBuffer buffer);
2023-03-09 21:44:17 +01:00
/**
* Serializes your data into an NBT tag. This is used when saving the chunk to disk.
* @param tag The tag to write to.
*/
2023-03-28 23:58:39 +02:00
void writeToNBT(T chunk, @NotNull NBTTagCompound tag);
2023-03-09 21:44:17 +01:00
/**
* Deserializes your data from an NBT tag. This is used when loading the chunk from disk.
2023-03-28 23:58:39 +02:00
* Mutates this object.
2023-03-09 21:44:17 +01:00
* @param tag The tag to read from.
*/
2023-03-28 23:58:39 +02:00
void readFromNBT(T chunk, @NotNull NBTTagCompound tag);
2023-03-09 21:44:17 +01:00
}