package info.u_team.u_team_core.api.sync;

import java.util.function.*;

import net.minecraft.network.PacketBuffer;

public abstract class BufferReferenceHolder {
	
	private PacketBuffer lastKnownValue;
	
	public abstract PacketBuffer get();
	
	public abstract void set(PacketBuffer buffer);
	
	public boolean isDirty() {
		final PacketBuffer buffer = get();
		final boolean dirty = !buffer.equals(lastKnownValue);
		lastKnownValue = buffer;
		return dirty;
	}
	
	public static final BufferReferenceHolder create(Supplier<PacketBuffer> get, Consumer<PacketBuffer> set) {
		return new BufferReferenceHolder() {
			
			@Override
			public PacketBuffer get() {
				return get.get();
			}
			
			@Override
			public void set(PacketBuffer buffer) {
				set.accept(buffer);
			}
		};
	}
	
}

@@ -66,16 +66,49 @@
 ion.*;%0A%0A
+import io.netty.buffer.Unpooled;%0A
 import n
@@ -142,16 +142,16 @@
 Buffer;%0A
-
 %0Apublic 
@@ -538,16 +538,22 @@
 r create
+Holder
 (Supplie
@@ -772,24 +772,24 @@
 r buffer) %7B%0A
-
 %09%09%09%09set.acce
@@ -815,10 +815,1099 @@
 %7D;%0A%09%7D%0A%09%0A
+%09public static final BufferReferenceHolder createIntHolder(IntSupplier get, IntConsumer set) %7B%0A%09%09return new BufferReferenceHolder() %7B%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public PacketBuffer get() %7B%0A%09%09%09%09return new PacketBuffer(Unpooled.copyInt(get.getAsInt()));%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public void set(PacketBuffer buffer) %7B%0A%09%09%09%09set.accept(buffer.readInt());%0A%09%09%09%7D%0A%09%09%7D;%0A%09%7D%0A%09%0A%09public static final BufferReferenceHolder createShortHolder(Supplier%3CShort%3E get, Consumer%3CShort%3E set) %7B%0A%09%09return new BufferReferenceHolder() %7B%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public PacketBuffer get() %7B%0A%09%09%09%09return new PacketBuffer(Unpooled.copyShort(get.get()));%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public void set(PacketBuffer buffer) %7B%0A%09%09%09%09set.accept(buffer.readShort());%0A%09%09%09%7D%0A%09%09%7D;%0A%09%7D%0A%09%0A%09public static final BufferReferenceHolder createLongHolder(LongSupplier get, LongConsumer set) %7B%0A%09%09return new BufferReferenceHolder() %7B%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public PacketBuffer get() %7B%0A%09%09%09%09return new PacketBuffer(Unpooled.copyLong(get.getAsLong()));%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public void set(PacketBuffer buffer) %7B%0A%09%09%09%09set.accept(buffer.readLong());%0A%09%09%09%7D%0A%09%09%7D;%0A%09%7D%0A%09%0A
 %7D%0A

Add some well used holders (int, long, short)