atomicscience/src/main/java/atomicscience/PAutoBuilder.java
2022-10-21 19:53:56 +02:00

49 lines
1.4 KiB
Java

package atomicscience;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import universalelectricity.core.vector.Vector3;
public class PAutoBuilder implements IMessage {
public Vector3 pos;
public TAutoBuilder.AutoBuilderType type;
public int radius;
@Override
public void fromBytes(ByteBuf buf) {
try {
NBTTagCompound nbt = CompressedStreamTools.read(
new DataInputStream(new ByteBufInputStream(buf)));
this.pos = Vector3.readFromNBT(nbt.getCompoundTag("pos"));
this.type = TAutoBuilder.AutoBuilderType.get(nbt.getInteger("type"));
this.radius = nbt.getInteger("radius");
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void toBytes(ByteBuf buf) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("pos", this.pos.writeToNBT(new NBTTagCompound()));
nbt.setInteger("type", this.type.ordinal());
nbt.setInteger("radius", this.radius);
try {
CompressedStreamTools.write(
nbt, new DataOutputStream(new ByteBufOutputStream(buf)));
} catch (IOException e) {
e.printStackTrace();
}
}
}