mirror of
https://github.com/GeyserExtensionists/GeyserUtils.git
synced 2025-12-19 14:59:18 +00:00
Animation
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@@ -23,6 +25,11 @@
|
||||
<version>1.18.28</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware</groupId>
|
||||
<artifactId>kryo</artifactId>
|
||||
<version>5.5.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,26 @@
|
||||
package me.zimzaza4.geyserutils.common.animation;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class Animation {
|
||||
public static final float DEFAULT_BLEND_OUT_TIME = 0.0f;
|
||||
public static final String DEFAULT_STOP_EXPRESSION = "query.any_animation_finished";
|
||||
public static final String DEFAULT_CONTROLLER = "__runtime_controller";
|
||||
public static final String DEFAULT_NEXT_STATE = "default";
|
||||
public static final int DEFAULT_STOP_EXPRESSION_VERSION = 16777216;
|
||||
|
||||
private String animation;
|
||||
@Builder.Default
|
||||
private String nextState = DEFAULT_NEXT_STATE;
|
||||
@Builder.Default
|
||||
private float blendOutTime = DEFAULT_BLEND_OUT_TIME;
|
||||
@Builder.Default
|
||||
private String stopExpression = DEFAULT_STOP_EXPRESSION;
|
||||
@Builder.Default
|
||||
private String controller = DEFAULT_CONTROLLER;
|
||||
@Builder.Default
|
||||
private int stopExpressionVersion = DEFAULT_STOP_EXPRESSION_VERSION;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package me.zimzaza4.geyserutils.common.manager;
|
||||
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import com.esotericsoftware.kryo.io.Input;
|
||||
import com.esotericsoftware.kryo.io.Output;
|
||||
import me.zimzaza4.geyserutils.common.packet.CameraShakeCustomPayloadPacket;
|
||||
import me.zimzaza4.geyserutils.common.packet.CustomPayloadPacket;
|
||||
import me.zimzaza4.geyserutils.common.packet.NpcDialogueFormDataCustomPayloadPacket;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class PacketManager {
|
||||
|
||||
private final Kryo kryo = new Kryo();
|
||||
|
||||
public PacketManager() {
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
kryo.setRegistrationRequired(false);
|
||||
}
|
||||
public void registerPacket(Class<? extends CustomPayloadPacket> clazz) {
|
||||
kryo.register(clazz);
|
||||
}
|
||||
|
||||
public byte[] encodePacket(CustomPayloadPacket packet) {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
try (Output output = new Output()) {
|
||||
kryo.writeObject(output, packet);
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CustomPayloadPacket decodePacket(byte[] bytes) {
|
||||
try (Input input = new Input(bytes)) {
|
||||
return kryo.readObject(input, CustomPayloadPacket.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package me.zimzaza4.geyserutils.common.packet;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.zimzaza4.geyserutils.common.animation.Animation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class AnimateEntityCustomPayloadPacket extends CustomPayloadPacket{
|
||||
private String animation;
|
||||
private String nextState;
|
||||
private String stopExpression;
|
||||
private int stopExpressionVersion;
|
||||
private String controller;
|
||||
private float blendOutTime;
|
||||
private List<Integer> entityJavaIds = new ArrayList<>();
|
||||
|
||||
public void parseFromAnimation(Animation ani) {
|
||||
this.animation = ani.getAnimation();
|
||||
this.nextState = ani.getNextState();
|
||||
this.blendOutTime = ani.getBlendOutTime();
|
||||
this.stopExpression = ani.getStopExpression();
|
||||
this.controller = ani.getController();
|
||||
this.stopExpressionVersion = ani.getStopExpressionVersion();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class CameraShakePacket extends Packet {
|
||||
public class CameraShakeCustomPayloadPacket extends CustomPayloadPacket {
|
||||
|
||||
float intensity;
|
||||
float duration;
|
||||
@@ -2,6 +2,6 @@ package me.zimzaza4.geyserutils.common.packet;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class Packet implements Serializable {
|
||||
public abstract class CustomPayloadPacket implements Serializable {
|
||||
|
||||
}
|
||||
@@ -6,14 +6,13 @@ import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import me.zimzaza4.geyserutils.common.form.element.NpcDialogueButton;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Accessors(fluent = true)
|
||||
@Getter
|
||||
@Setter
|
||||
public class NpcDialogueFormDataPacket extends Packet {
|
||||
public class NpcDialogueFormDataCustomPayloadPacket extends CustomPayloadPacket {
|
||||
|
||||
String formId;
|
||||
String title;
|
||||
@@ -4,12 +4,10 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
public class NpcFormResponsePacket extends Packet {
|
||||
public class NpcFormResponseCustomPayloadPacket extends CustomPayloadPacket {
|
||||
String formId;
|
||||
int buttonId;
|
||||
}
|
||||
@@ -1,30 +1,12 @@
|
||||
package me.zimzaza4.geyserutils.common.util;
|
||||
|
||||
import me.zimzaza4.geyserutils.common.packet.Packet;
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import me.zimzaza4.geyserutils.common.packet.CustomPayloadPacket;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class CustomPayloadPacketUtils {
|
||||
|
||||
public static byte[] encodePacket(Packet packet) {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
try (ObjectOutputStream outputStream = new ObjectOutputStream(byteArrayOutputStream)) {
|
||||
outputStream.writeObject(packet);
|
||||
outputStream.flush();
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Packet decodePacket(byte[] bytes) {
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
||||
try (ObjectInputStream inputStream = new ObjectInputStream(byteArrayInputStream)) {
|
||||
return (Packet) inputStream.readObject();
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user