mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-18 03:25:09 +00:00
Initial Commit
This commit is contained in:
1 parent
397135f687
commit
0f32dd8620
82 files changed
+10693
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package codechicken.lib.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
|
||||
public interface MCDataInput
|
||||
{
|
||||
public long readLong();
|
||||
public int readInt();
|
||||
public short readShort();
|
||||
public int readUnsignedShort();
|
||||
public byte readByte();
|
||||
public int readUnsignedByte();
|
||||
public double readDouble();
|
||||
public float readFloat();
|
||||
public boolean readBoolean();
|
||||
public char readChar();
|
||||
public byte[] readByteArray(int length);
|
||||
public String readString();
|
||||
public BlockCoord readCoord();
|
||||
public NBTTagCompound readNBTTagCompound();
|
||||
public ItemStack readItemStack();
|
||||
public FluidStack readFluidStack();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package codechicken.lib.data;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class MCDataInputStream extends InputStream
|
||||
{
|
||||
private MCDataInput in;
|
||||
|
||||
public MCDataInputStream(MCDataInput in)
|
||||
{
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read()
|
||||
{
|
||||
return in.readByte()&0xFF;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package codechicken.lib.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
|
||||
public interface MCDataOutput
|
||||
{
|
||||
public MCDataOutput writeLong(long l);
|
||||
public MCDataOutput writeInt(int i);
|
||||
public MCDataOutput writeShort(int s);
|
||||
public MCDataOutput writeByte(int b);
|
||||
public MCDataOutput writeDouble(double d);
|
||||
public MCDataOutput writeFloat(float f);
|
||||
public MCDataOutput writeBoolean(boolean b);
|
||||
public MCDataOutput writeChar(char c);
|
||||
public MCDataOutput writeByteArray(byte[] array);
|
||||
public MCDataOutput writeString(String s);
|
||||
public MCDataOutput writeCoord(int x, int y, int z);
|
||||
public MCDataOutput writeCoord(BlockCoord coord);
|
||||
public MCDataOutput writeNBTTagCompound(NBTTagCompound tag);
|
||||
public MCDataOutput writeItemStack(ItemStack stack);
|
||||
public MCDataOutput writeFluidStack(FluidStack liquid);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package codechicken.lib.data;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class MCDataOutputStream extends OutputStream
|
||||
{
|
||||
private MCDataOutput out;
|
||||
|
||||
public MCDataOutputStream(MCDataOutput out)
|
||||
{
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b)
|
||||
{
|
||||
out.writeByte(b);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package codechicken.lib.data;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
|
||||
public class MCOutputStreamWrapper implements MCDataOutput
|
||||
{
|
||||
public DataOutputStream dataout;
|
||||
|
||||
public MCOutputStreamWrapper(DataOutputStream out)
|
||||
{
|
||||
dataout = out;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeBoolean(boolean b)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataout.writeBoolean(b);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeByte(int b)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataout.writeByte(b);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeShort(int s)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataout.writeShort(s);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeInt(int i)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataout.writeInt(i);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeFloat(float f)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataout.writeFloat(f);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeDouble(double d)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataout.writeDouble(d);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeLong(long l)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataout.writeLong(l);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MCOutputStreamWrapper writeChar(char c)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataout.writeChar(c);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeByteArray(byte[] barray)
|
||||
{
|
||||
try
|
||||
{
|
||||
dataout.write(barray);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeCoord(int x, int y, int z)
|
||||
{
|
||||
writeInt(x);
|
||||
writeInt(y);
|
||||
writeInt(z);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeCoord(BlockCoord coord)
|
||||
{
|
||||
writeInt(coord.x);
|
||||
writeInt(coord.y);
|
||||
writeInt(coord.z);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeString(String s)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(s.length() > 65535)
|
||||
throw new IOException("String length: "+s.length()+"too long.");
|
||||
dataout.writeShort(s.length());
|
||||
dataout.writeChars(s);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeItemStack(ItemStack stack)
|
||||
{
|
||||
writeItemStack(stack, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeItemStack(ItemStack stack, boolean large)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeShort(stack.itemID);
|
||||
if(large)
|
||||
writeInt(stack.stackSize);
|
||||
else
|
||||
writeByte(stack.stackSize);
|
||||
writeShort(stack.getItemDamage());
|
||||
writeNBTTagCompound(stack.stackTagCompound);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeNBTTagCompound(NBTTagCompound compound)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (compound == null)
|
||||
{
|
||||
writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] bytes = CompressedStreamTools.compress(compound);
|
||||
writeShort((short)bytes.length);
|
||||
writeByteArray(bytes);
|
||||
}
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MCOutputStreamWrapper writeFluidStack(FluidStack fluid)
|
||||
{
|
||||
if (fluid == null)
|
||||
{
|
||||
writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeShort(fluid.fluidID);
|
||||
writeInt(fluid.amount);
|
||||
writeNBTTagCompound(fluid.tag);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
package codechicken.lib.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.nbt.NBTTagByteArray;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagFloat;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagLong;
|
||||
import net.minecraft.nbt.NBTTagShort;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
|
||||
public class NBTDataWrapper implements MCDataInput, MCDataOutput
|
||||
{
|
||||
private NBTTagList readList;
|
||||
private int readTag = 0;
|
||||
private NBTTagList writeList;
|
||||
|
||||
public NBTDataWrapper(NBTTagList input)
|
||||
{
|
||||
readList = input;
|
||||
}
|
||||
|
||||
public NBTDataWrapper()
|
||||
{
|
||||
writeList = new NBTTagList();
|
||||
}
|
||||
|
||||
public NBTTagList toTag()
|
||||
{
|
||||
return writeList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeLong(long l)
|
||||
{
|
||||
writeList.appendTag(new NBTTagLong(null, l));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeInt(int i)
|
||||
{
|
||||
writeList.appendTag(new NBTTagInt(null, i));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeShort(int s)
|
||||
{
|
||||
writeList.appendTag(new NBTTagShort(null, (short) s));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeByte(int b)
|
||||
{
|
||||
writeList.appendTag(new NBTTagByte(null, (byte) b));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeDouble(double d)
|
||||
{
|
||||
writeList.appendTag(new NBTTagDouble(null, d));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeFloat(float f)
|
||||
{
|
||||
writeList.appendTag(new NBTTagFloat(null, f));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeBoolean(boolean b)
|
||||
{
|
||||
writeList.appendTag(new NBTTagByte(null, (byte) (b ? 1 : 0)));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeChar(char c)
|
||||
{
|
||||
writeList.appendTag(new NBTTagShort(null, (short)c));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeByteArray(byte[] array)
|
||||
{
|
||||
writeList.appendTag(new NBTTagByteArray(null, array));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeString(String s)
|
||||
{
|
||||
writeList.appendTag(new NBTTagString(null, s));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeCoord(int x, int y, int z)
|
||||
{
|
||||
writeInt(x);
|
||||
writeInt(y);
|
||||
writeInt(z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeCoord(BlockCoord coord)
|
||||
{
|
||||
writeCoord(coord.x, coord.y, coord.z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeNBTTagCompound(NBTTagCompound tag)
|
||||
{
|
||||
writeList.appendTag(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeItemStack(ItemStack stack)
|
||||
{
|
||||
writeList.appendTag(stack.writeToNBT(new NBTTagCompound()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTDataWrapper writeFluidStack(FluidStack liquid)
|
||||
{
|
||||
writeList.appendTag(liquid.writeToNBT(new NBTTagCompound()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong()
|
||||
{
|
||||
return ((NBTTagLong)readTag()).data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt()
|
||||
{
|
||||
return ((NBTTagInt)readTag()).data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort()
|
||||
{
|
||||
return ((NBTTagShort)readTag()).data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedShort()
|
||||
{
|
||||
return ((NBTTagShort)readTag()).data & 0xFFFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte()
|
||||
{
|
||||
return ((NBTTagByte)readTag()).data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedByte()
|
||||
{
|
||||
return ((NBTTagByte)readTag()).data & 0xFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double readDouble()
|
||||
{
|
||||
return ((NBTTagDouble)readTag()).data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float readFloat()
|
||||
{
|
||||
return ((NBTTagFloat)readTag()).data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readBoolean()
|
||||
{
|
||||
return ((NBTTagByte)readTag()).data != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char readChar()
|
||||
{
|
||||
return (char)((NBTTagShort)readTag()).data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readByteArray(int length)
|
||||
{
|
||||
return ((NBTTagByteArray)readTag()).byteArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readString()
|
||||
{
|
||||
return ((NBTTagString)readTag()).data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockCoord readCoord()
|
||||
{
|
||||
return new BlockCoord(readInt(), readInt(), readInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound readNBTTagCompound()
|
||||
{
|
||||
return (NBTTagCompound)readTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack readItemStack()
|
||||
{
|
||||
return ItemStack.loadItemStackFromNBT(readNBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack readFluidStack()
|
||||
{
|
||||
return FluidStack.loadFluidStackFromNBT(readNBTTagCompound());
|
||||
}
|
||||
|
||||
private NBTBase readTag()
|
||||
{
|
||||
return readList.tagAt(readTag++);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user