com.parzivail.util.data.PacketByteBufHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pswg Show documentation
Show all versions of pswg Show documentation
Explore the galaxy with Galaxies: Parzi's Star Wars Mod!
package com.parzivail.util.data;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import D;
import F;
import I;
import Z;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map.Entry;
import net.minecraft.class_2379;
import net.minecraft.class_243;
import net.minecraft.class_2540;
import net.minecraft.class_2960;
public class PacketByteBufHelper
{
@FunctionalInterface
public interface PacketByteBufWriter
{
void write(class_2540 buf, T value);
}
@FunctionalInterface
public interface PacketByteBufReader
{
T read(class_2540 buf);
}
public static void writeNullable(class_2540 buf, T value, PacketByteBufWriter writer)
{
buf.method_52964(value != null);
if (value != null)
writer.write(buf, value);
}
public static T readNullable(class_2540 buf, PacketByteBufReader reader)
{
var hasValue = buf.readBoolean();
if (!hasValue)
return null;
return reader.read(buf);
}
public static void writeMany(class_2540 buf, Collection value, PacketByteBufWriter writer)
{
buf.method_53002(value.size());
for (T t : value)
writer.write(buf, t);
}
public static ArrayList readMany(class_2540 buf, PacketByteBufReader reader)
{
var n = buf.readInt();
var arr = new ArrayList();
for (var i = 0; i < n; i++)
arr.add(reader.read(buf));
return arr;
}
public static void writeHashMap(class_2540 buf, HashMap map, PacketByteBufWriter keyWriter, PacketByteBufWriter valueWriter)
{
buf.method_53002(map.size());
for (var pair : map.entrySet())
{
keyWriter.write(buf, pair.getKey());
valueWriter.write(buf, pair.getValue());
}
}
public static HashMap readHashMap(class_2540 buf, PacketByteBufReader keyReader, PacketByteBufReader valueReader)
{
var size = buf.readInt();
var map = new HashMap(size);
for (var i = 0; i < size; i++)
{
var k = keyReader.read(buf);
var v = valueReader.read(buf);
map.put(k, v);
}
return map;
}
public static void writeIdentifier(class_2540 buf, class_2960 i)
{
buf.method_10814(i.toString());
}
public static class_2960 readIdentifier(class_2540 buf)
{
return new class_2960(buf.method_19772());
}
public static void writeQuaternion(class_2540 buf, Quaternionf q)
{
buf.method_52941(q.w);
buf.method_52941(q.x);
buf.method_52941(q.y);
buf.method_52941(q.z);
}
public static Quaternionf readQuaternion(class_2540 buf)
{
var qa = buf.readFloat();
var qb = buf.readFloat();
var qc = buf.readFloat();
var qd = buf.readFloat();
return new Quaternionf(qb, qc, qd, qa);
}
public static void writeVec3d(class_2540 buf, class_243 v)
{
buf.method_52940(v.field_1352);
buf.method_52940(v.field_1351);
buf.method_52940(v.field_1350);
}
public static class_243 readVec3d(class_2540 buf)
{
var x = buf.readDouble();
var y = buf.readDouble();
var z = buf.readDouble();
return new class_243(x, y, z);
}
public static class_243 readVec3dAsSingles(class_2540 buf)
{
var x = buf.readFloat();
var y = buf.readFloat();
var z = buf.readFloat();
return new class_243(x, y, z);
}
public static void writeVec3dAsSingles(class_2540 buf, class_243 v)
{
writeVec3f(buf, v.method_46409());
}
public static void writeVec3f(class_2540 buf, Vector3f v)
{
buf.method_52941(v.x);
buf.method_52941(v.y);
buf.method_52941(v.z);
}
public static Vector3f readVec3f(class_2540 buf)
{
var x = buf.readFloat();
var y = buf.readFloat();
var z = buf.readFloat();
return new Vector3f(x, y, z);
}
public static void writeEulerAngle(class_2540 buf, class_2379 e)
{
buf.method_52941(e.method_10256());
buf.method_52941(e.method_10257());
buf.method_52941(e.method_10258());
}
public static class_2379 readEulerAngle(class_2540 buf)
{
var pitch = buf.readFloat();
var yaw = buf.readFloat();
var roll = buf.readFloat();
return new class_2379(pitch, yaw, roll);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy