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-28 23:58:39 +02:00
|
|
|
* For performance reasons, you should store any data in the chunk itself using a mixin. The type T is the type
|
|
|
|
|
* of the interface that you are mixing into the chunk.
|
2023-03-09 21:44:17 +01:00
|
|
|
* Note: All the methods should be thread-safe and stateless unless otherwise specified.
|
|
|
|
|
*/
|
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
|
|
|
* Used for sorting the managers. Managers with a lower order index are processed first.
|
|
|
|
|
* If unsure, return 0, and let the implementation decide.
|
|
|
|
|
*/
|
|
|
|
|
default int orderIndex() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes your data in a chunk. This is called at the end of the chunk constructor. One less mixin per manager!
|
2023-03-09 21:44:17 +01:00
|
|
|
* @param chunk The chunk to initialize.
|
|
|
|
|
*/
|
2023-03-28 23:58:39 +02:00
|
|
|
void init(T chunk);
|
|
|
|
|
|
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
|
|
|
}
|