Package info.u_team.u_team_core.api.sync
Class DataHolder
java.lang.Object
info.u_team.u_team_core.api.sync.DataHolder
- Direct Known Subclasses:
MessageHolder
This class holds a data buffer with setter and getter for synchronizing. Furthermore the data holder implemented a
method to check if the data has changed and should be synchronized.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if the data has changed.static final DataHolder
createBooleanHolder
(BooleanSupplier supplier, it.unimi.dsi.fastutil.booleans.BooleanConsumer consumer) static final DataHolder
createByteHolder
(Supplier<Byte> supplier, Consumer<Byte> consumer) static final DataHolder
createDoubleHolder
(Supplier<Double> supplier, Consumer<Double> consumer) static final DataHolder
createFloatHolder
(Supplier<Float> supplier, Consumer<Float> consumer) static final DataHolder
createHolder
(Supplier<net.minecraft.network.FriendlyByteBuf> supplier, Consumer<net.minecraft.network.FriendlyByteBuf> consumer) static final DataHolder
createIntHolder
(IntSupplier supplier, IntConsumer consumer) static final DataHolder
createLongHolder
(LongSupplier supplier, LongConsumer consumer) static final DataHolder
createShortHolder
(Supplier<Short> supplier, Consumer<Short> consumer) abstract net.minecraft.network.FriendlyByteBuf
get()
Should return an instance ofFriendlyByteBuf
that cannot be manipulated after that call.abstract void
set
(net.minecraft.network.FriendlyByteBuf byteBuf) Sets the received instance of theFriendlyByteBuf
.
-
Constructor Details
-
DataHolder
public DataHolder()
-
-
Method Details
-
get
public abstract net.minecraft.network.FriendlyByteBuf get()Should return an instance ofFriendlyByteBuf
that cannot be manipulated after that call. Generally it is a good idea to return a copy of the original data buffer here.- Returns:
- A buffer for synchronizing
-
set
public abstract void set(net.minecraft.network.FriendlyByteBuf byteBuf) Sets the received instance of theFriendlyByteBuf
. From this buffer the data can be read.- Parameters:
byteBuf
- The received buffer
-
checkAndClearUpdateFlag
public boolean checkAndClearUpdateFlag()Checks if the data has changed. Resets the changed bit afterwards. For performance reasons this method should be overwritten if the change check can be implemented directly on the data types. The default methods compared the buffers.- Returns:
- True if data has changed
-
createHolder
public static final DataHolder createHolder(Supplier<net.minecraft.network.FriendlyByteBuf> supplier, Consumer<net.minecraft.network.FriendlyByteBuf> consumer) -
createByteHolder
-
createShortHolder
public static final DataHolder createShortHolder(Supplier<Short> supplier, Consumer<Short> consumer) -
createIntHolder
-
createLongHolder
-
createFloatHolder
public static final DataHolder createFloatHolder(Supplier<Float> supplier, Consumer<Float> consumer) -
createDoubleHolder
public static final DataHolder createDoubleHolder(Supplier<Double> supplier, Consumer<Double> consumer) -
createBooleanHolder
public static final DataHolder createBooleanHolder(BooleanSupplier supplier, it.unimi.dsi.fastutil.booleans.BooleanConsumer consumer)
-