package net.mcft.copy.core.entity;

import java.io.IOException;

import net.mcft.copy.core.util.NbtUtils;
import net.minecraft.nbt.NBTBase;
import net.minecraft.network.PacketBuffer;

public class EntityPropertyPrimitive<T> extends EntityProperty<T> {
	
	public EntityPropertyPrimitive(String name, T value) {
		super(name, value);
	}
	
	@Override
	public NBTBase write() {
		return NbtUtils.createTag(get());
	}
	@Override
	public void write(PacketBuffer buffer) {
		T value = get();
		if (value == null) throw new NullPointerException("value is null");
		else if (value instanceof Byte) buffer.writeByte((Byte)value);
		else if (value instanceof Short) buffer.writeShort((Short)value);
		else if (value instanceof Integer) buffer.writeInt((Integer)value);
		else if (value instanceof Long) buffer.writeLong((Long)value);
		else if (value instanceof Float) buffer.writeFloat((Float)value);
		else if (value instanceof Double) buffer.writeDouble((Double)value);
		else if (value instanceof String) {
			try { buffer.writeStringToBuffer((String)value); }
			catch (IOException ex) { throw new RuntimeException(ex); }
		} else throw new UnsupportedOperationException(value.getClass().getName() + " is not supported.");
	}
	
	@Override
	public void read(NBTBase tag) {
		set(NbtUtils.<T>getTagValue(tag));
	}
	@Override
	public void read(PacketBuffer buffer) {
		T value = get();
		if (value == null) throw new NullPointerException("value is null");
		else if (value instanceof Byte) set((T)(Object)buffer.readByte());
		else if (value instanceof Short) set((T)(Object)buffer.readShort());
		else if (value instanceof Integer) set((T)(Object)buffer.readInt());
		else if (value instanceof Long) set((T)(Object)buffer.readLong());
		else if (value instanceof Float) set((T)(Object)buffer.readFloat());
		else if (value instanceof Double) set((T)(Object)buffer.readDouble());
		else if (value instanceof String) {
			try { set((T)buffer.readStringFromBuffer(128)); }
			catch (IOException ex) { throw new RuntimeException(ex); }
		} else throw new UnsupportedOperationException(value.getClass().getName() + " is not supported.");
	}
	
}

@@ -133,16 +133,53 @@
 BTBase;%0A
+import net.minecraft.nbt.NBTTagByte;%0A
 import n
@@ -406,16 +406,134 @@
 e() %7B%0A%09%09
+T value = get();%0A%09%09if (value instanceof Boolean)%0A%09%09%09return new NBTTagByte((Boolean)value ? (byte)1 : (byte)0);%0A%09%09else 
 return N
@@ -695,32 +695,106 @@
 alue is null%22);%0A
+%09%09else if (value instanceof Boolean) buffer.writeBoolean((Boolean)value);%0A
 %09%09else if (value
@@ -1490,16 +1490,131 @@
 ag) %7B%0A%09%09
+T value = get();%0A%09%09if (value instanceof Boolean)%0A%09%09%09set((T)(Boolean)(NbtUtils.%3CByte%3EgetTagValue(tag) %3E 0));%0A%09%09else 
 set(NbtU
@@ -1776,32 +1776,107 @@
 alue is null%22);%0A
+%09%09else if (value instanceof Boolean) set((T)(Object)buffer.readBoolean());%0A
 %09%09else if (value

Add boolean support to EntityPropertyPrimitive