mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-25 22:07: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.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
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue