@@ -59,19 +59,27 @@ public class DataRegistryImpl {
5959 private static final Map <String , OrderedManager > managersUnordered = new HashMap <>();
6060 private static final SortedSet <OrderedManager > managers = new TreeSet <>();
6161 private static final DualMap <PacketManagerInfo > packetManagers = new DualMap <>();
62+ private static final DualMap <CubicPacketManagerInfo > cubicPacketManagers = new DualMap <>();
6263 private static final DualMap <DataManager .BlockPacketDataManager > blockPacketManagers = new DualMap <>();
6364 private static final DualMap <DataManager .StorageDataManager > NBTManagers = new DualMap <>();
6465 private static final SortedMap <OrderedManager , DataManager .ChunkDataManager > chunkNBTManagers = new TreeMap <>();
6566 private static final SortedMap <OrderedManager , DataManager .SubChunkDataManager > subChunkNBTManagers = new TreeMap <>();
6667 private static final Set <String > disabledManagers = new HashSet <>();
6768 private static int maxPacketSize = 4 ;
69+ private static int maxPacketSizeCubic = 4 ;
6870
6971 @ Data
7072 private static class PacketManagerInfo {
7173 public final int maxPacketSize ;
7274 public final DataManager .PacketDataManager manager ;
7375 }
7476
77+ @ Data
78+ private static class CubicPacketManagerInfo {
79+ public final int maxPacketSize ;
80+ public final DataManager .CubicPacketDataManager manager ;
81+ }
82+
7583 public static void registerDataManager (DataManager manager , int ordering ) throws IllegalStateException , IllegalArgumentException {
7684 if (Loader .instance ().getLoaderState () != LoaderState .INITIALIZATION ) {
7785 throw new IllegalStateException ("ChunkDataManager registration is not allowed at this time! Please register your ChunkDataManager in the init phase." );
@@ -100,6 +108,12 @@ public static void registerDataManager(DataManager manager, int ordering) throws
100108 val blockPacketManager = (DataManager .BlockPacketDataManager ) manager ;
101109 blockPacketManagers .put (ord , blockPacketManager );
102110 }
111+ if (manager instanceof DataManager .CubicPacketDataManager ) {
112+ val cubicPacketManager = (DataManager .CubicPacketDataManager ) manager ;
113+ val maxSize = cubicPacketManager .maxPacketSizeCubic ();
114+ maxPacketSizeCubic += 4 + id .getBytes (StandardCharsets .UTF_8 ).length + 4 + maxSize ;
115+ cubicPacketManagers .put (ord , new CubicPacketManagerInfo (maxSize , cubicPacketManager ));
116+ }
103117 if (manager instanceof DataManager .StorageDataManager ) {
104118 NBTManagers .put (ord , (DataManager .StorageDataManager ) manager );
105119 if (manager instanceof DataManager .ChunkDataManager ) {
@@ -127,6 +141,10 @@ public static void disableDataManager(String domain, String id) {
127141 val removed = packetManagers .remove (ord );
128142 maxPacketSize -= 4 + id .getBytes (StandardCharsets .UTF_8 ).length + 4 + removed .maxPacketSize ;
129143 }
144+ if (cubicPacketManagers .containsKey (ord )) {
145+ val removed = cubicPacketManagers .remove (ord );
146+ maxPacketSizeCubic -= 4 + id .getBytes (StandardCharsets .UTF_8 ).length + 4 + removed .maxPacketSize ;
147+ }
130148 blockPacketManagers .remove (ord );
131149 chunkNBTManagers .remove (ord );
132150 subChunkNBTManagers .remove (ord );
@@ -141,6 +159,10 @@ public static int maxPacketSize() {
141159 return maxPacketSize ;
142160 }
143161
162+ public static int maxPacketSizeCubic () {
163+ return maxPacketSizeCubic ;
164+ }
165+
144166 private static void writeString (ByteBuffer buffer , String string ) {
145167 val bytes = string .getBytes ();
146168 buffer .putInt (bytes .length );
@@ -177,6 +199,29 @@ public static void readFromBuffer(Chunk chunk, int subChunkMask, boolean forceUp
177199 }
178200 }
179201
202+ public static void readFromBufferCubic (Chunk chunk , ExtendedBlockStorage blockStorage , byte [] data ) {
203+ val buf = ByteBuffer .wrap (data );
204+ buf .order (ByteOrder .LITTLE_ENDIAN );
205+ int count = buf .getInt ();
206+ for (int i = 0 ; i < count ; i ++) {
207+ val id = readString (buf );
208+ val length = buf .getInt ();
209+ val managerInfo = cubicPacketManagers .get (id );
210+ if (managerInfo == null ) {
211+ Common .LOG .error ("Received data for unknown CubicPacketDataManager " + id + ". Skipping." );
212+ buf .position (buf .position () + length );
213+ continue ;
214+ }
215+ if (length > managerInfo .maxPacketSize ) {
216+ Common .LOG .error ("Received packet larger than max size for CubicPacketDataManager " + id + "! Continuing anyways, things might break!" );
217+ }
218+ int start = buf .position ();
219+ val slice = createSlice (buf , start , length );
220+ managerInfo .manager .readFromBuffer (chunk , blockStorage , slice );
221+ buf .position (start + length );
222+ }
223+ }
224+
180225 public static int writeToBuffer (Chunk chunk , int subChunkMask , boolean forceUpdate , byte [] data ) {
181226 val buf = ByteBuffer .wrap (data );
182227 buf .order (ByteOrder .LITTLE_ENDIAN );
@@ -195,6 +240,24 @@ public static int writeToBuffer(Chunk chunk, int subChunkMask, boolean forceUpda
195240 return buf .position ();
196241 }
197242
243+ public static int writeToBufferCubic (Chunk chunk , ExtendedBlockStorage blockStorage , byte [] data ) {
244+ val buf = ByteBuffer .wrap (data );
245+ buf .order (ByteOrder .LITTLE_ENDIAN );
246+ buf .putInt (cubicPacketManagers .size ());
247+ for (val pair : cubicPacketManagers .entrySet ()) {
248+ val ord = pair .getKey ();
249+ val managerInfo = pair .getValue ();
250+ writeString (buf , ord .id );
251+ int start = buf .position () + 4 ;
252+ val slice = createSlice (buf , start , managerInfo .maxPacketSize );
253+ managerInfo .manager .writeToBuffer (chunk , blockStorage , slice );
254+ int length = slice .position ();
255+ buf .putInt (length );
256+ buf .position (start + length );
257+ }
258+ return buf .position ();
259+ }
260+
198261 public static void writeBlockToPacket (Chunk chunk , int x , int y , int z , S23PacketBlockChange packet ) {
199262 for (val manager : blockPacketManagers .values ()) {
200263 manager .writeBlockToPacket (chunk , x , y , z , packet );
0 commit comments