Clean up the code a little bit

This commit is contained in:
Sollace 2023-09-28 13:48:52 +01:00
parent f70ec0996c
commit b538174933
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 17 additions and 25 deletions

View file

@ -35,7 +35,7 @@ public class MsgPonyData {
buffer.writeEnumConstant(data.tailLength()); buffer.writeEnumConstant(data.tailLength());
buffer.writeEnumConstant(data.tailShape()); buffer.writeEnumConstant(data.tailShape());
buffer.writeEnumConstant(data.gender()); buffer.writeEnumConstant(data.gender());
new MsgSize(data.size()).toBuffer(buffer); write(data.size(), buffer);
buffer.writeInt(data.glowColor()); buffer.writeInt(data.glowColor());
buffer.writeBoolean(data.noSkin()); buffer.writeBoolean(data.noSkin());
buffer.writeVarInt(data.priority()); buffer.writeVarInt(data.priority());
@ -43,6 +43,16 @@ public class MsgPonyData {
return buffer; return buffer;
} }
private static void write(Size size, PacketByteBuf buffer) {
buffer.writeInt(size.ordinal());
buffer.writeString(size.name());
buffer.writeFloat(size.shadowSize());
buffer.writeFloat(size.scaleFactor());
buffer.writeFloat(size.eyeHeightFactor());
buffer.writeFloat(size.eyeDistanceFactor());
buffer.writeFloat(size.colorCode());
}
private record MsgSize ( private record MsgSize (
int ordinal, int ordinal,
String name, String name,
@ -51,23 +61,8 @@ public class MsgPonyData {
float eyeHeightFactor, float eyeHeightFactor,
float eyeDistanceFactor, float eyeDistanceFactor,
int colorCode) implements Size { int colorCode) implements Size {
MsgSize(Size size) {
this(size.ordinal(), size.name(), size.shadowSize(), size.scaleFactor(), size.eyeHeightFactor(), size.eyeDistanceFactor(), size.colorCode());
}
MsgSize(PacketByteBuf buffer) { MsgSize(PacketByteBuf buffer) {
this(buffer.readInt(), buffer.readString(32767), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readInt()); this(buffer.readInt(), buffer.readString(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readInt());
}
public void toBuffer(PacketByteBuf buffer) {
buffer.writeInt(ordinal);
buffer.writeString(name);
buffer.writeFloat(shadowSize);
buffer.writeFloat(scaleFactor);
buffer.writeFloat(eyeHeightFactor);
buffer.writeFloat(eyeDistanceFactor);
buffer.writeFloat(colorCode);
} }
@Override @Override

View file

@ -30,14 +30,6 @@ public record Flags<T extends Enum<T> & TValue<T>> (
return new Flags<>(def, values, buffer.readInt()); return new Flags<>(def, values, buffer.readInt());
} }
public static <T> List<T> flags(T[] values, boolean[] flags) {
List<T> wears = new ArrayList<>();
for (int i = 0; i < values.length; i++) {
if (flags[i]) wears.add(values[i]);
}
return wears;
}
public void write(PacketByteBuf buffer) { public void write(PacketByteBuf buffer) {
buffer.writeCollection(values, (buf, value) -> buf.writeInt(value.ordinal())); buffer.writeCollection(values, (buf, value) -> buf.writeInt(value.ordinal()));
buffer.writeInt(colorCode); buffer.writeInt(colorCode);

View file

@ -41,4 +41,9 @@ public interface Size extends TValue<Size> {
* A scale factor used to alter the camera's distance. * A scale factor used to alter the camera's distance.
*/ */
float eyeDistanceFactor(); float eyeDistanceFactor();
/**
* The trigger pixel colour corresponding to this size.
*/
int colorCode();
} }