mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 04:27:59 +01:00
Clean up the code a little bit
This commit is contained in:
parent
f70ec0996c
commit
b538174933
3 changed files with 17 additions and 25 deletions
|
@ -35,7 +35,7 @@ public class MsgPonyData {
|
|||
buffer.writeEnumConstant(data.tailLength());
|
||||
buffer.writeEnumConstant(data.tailShape());
|
||||
buffer.writeEnumConstant(data.gender());
|
||||
new MsgSize(data.size()).toBuffer(buffer);
|
||||
write(data.size(), buffer);
|
||||
buffer.writeInt(data.glowColor());
|
||||
buffer.writeBoolean(data.noSkin());
|
||||
buffer.writeVarInt(data.priority());
|
||||
|
@ -43,6 +43,16 @@ public class MsgPonyData {
|
|||
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 (
|
||||
int ordinal,
|
||||
String name,
|
||||
|
@ -51,23 +61,8 @@ public class MsgPonyData {
|
|||
float eyeHeightFactor,
|
||||
float eyeDistanceFactor,
|
||||
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) {
|
||||
this(buffer.readInt(), buffer.readString(32767), 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);
|
||||
this(buffer.readInt(), buffer.readString(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,14 +30,6 @@ public record Flags<T extends Enum<T> & TValue<T>> (
|
|||
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) {
|
||||
buffer.writeCollection(values, (buf, value) -> buf.writeInt(value.ordinal()));
|
||||
buffer.writeInt(colorCode);
|
||||
|
|
|
@ -41,4 +41,9 @@ public interface Size extends TValue<Size> {
|
|||
* A scale factor used to alter the camera's distance.
|
||||
*/
|
||||
float eyeDistanceFactor();
|
||||
|
||||
/**
|
||||
* The trigger pixel colour corresponding to this size.
|
||||
*/
|
||||
int colorCode();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue