mirror of
https://github.com/GeyserExtensionists/GeyserUtils.git
synced 2025-12-19 15:09:24 +00:00
well
This commit is contained in:
@@ -71,6 +71,18 @@
|
|||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.15.2</version>
|
<version>2.15.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>24.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>24.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.data;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class CameraPreset {
|
||||||
|
private static final Map<String, CameraPreset> PRESETS = new TreeMap<>();
|
||||||
|
|
||||||
|
public static Map<String, CameraPreset> getPresets() {
|
||||||
|
return PRESETS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CameraPreset getPreset(String identifier) {
|
||||||
|
return getPresets().get(identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerCameraPresets(CameraPreset... presets) {
|
||||||
|
for (var preset : presets) {
|
||||||
|
if (PRESETS.containsKey(preset.getIdentifier()))
|
||||||
|
throw new IllegalArgumentException("Camera preset " + preset.getIdentifier() + " already exists!");
|
||||||
|
PRESETS.put(preset.getIdentifier(), preset);
|
||||||
|
}
|
||||||
|
int id = 0;
|
||||||
|
//重新分配id
|
||||||
|
for (var preset : presets) {
|
||||||
|
preset.id = id++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CameraPreset FIRST_PERSON;
|
||||||
|
public static CameraPreset FREE;
|
||||||
|
public static CameraPreset THIRD_PERSON;
|
||||||
|
public static CameraPreset THIRD_PERSON_FRONT;
|
||||||
|
|
||||||
|
public static void load() {
|
||||||
|
FIRST_PERSON = CameraPreset.builder()
|
||||||
|
.identifier("minecraft:first_person")
|
||||||
|
.build();
|
||||||
|
FREE = CameraPreset.builder()
|
||||||
|
.identifier("minecraft:free")
|
||||||
|
.pos(new Pos(0, 0, 0))
|
||||||
|
.rot(new Rot(0, 0))
|
||||||
|
.build();
|
||||||
|
THIRD_PERSON = CameraPreset.builder()
|
||||||
|
.identifier("minecraft:third_person")
|
||||||
|
.build();
|
||||||
|
THIRD_PERSON_FRONT = CameraPreset.builder()
|
||||||
|
.identifier("minecraft:third_person_front")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
registerCameraPresets(FIRST_PERSON, FREE, THIRD_PERSON, THIRD_PERSON_FRONT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String identifier;
|
||||||
|
@Getter
|
||||||
|
private String inheritFrom;
|
||||||
|
@Getter
|
||||||
|
@Nullable
|
||||||
|
private Pos pos;
|
||||||
|
@Getter
|
||||||
|
@Nullable
|
||||||
|
private Rot rot;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
public CameraPreset(String identifier, String inheritFrom, @Nullable Pos pos, @Nullable Rot rot) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
this.inheritFrom = inheritFrom != null ? inheritFrom : "";
|
||||||
|
this.pos = pos;
|
||||||
|
this.rot = rot;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CameraPreset() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.data;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
@Data
|
||||||
|
public class Color {
|
||||||
|
float r;
|
||||||
|
float g;
|
||||||
|
float b;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.data;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
@Data
|
||||||
|
public class Ease {
|
||||||
|
|
||||||
|
float time;
|
||||||
|
int easeType;
|
||||||
|
|
||||||
|
public Ease(float time, EaseType easeType) {
|
||||||
|
this.time = time;
|
||||||
|
this.easeType = easeType.getIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ease easeType(EaseType easeType) {
|
||||||
|
this.easeType = easeType.getIndex();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.data;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum EaseType {
|
||||||
|
LINEAR("linear",0),
|
||||||
|
SPRING("spring",1),
|
||||||
|
EASE_IN_SINE("in_sine",2),
|
||||||
|
EASE_OUT_SINE("out_sine",3),
|
||||||
|
EASE_IN_OUT_SINE("in_out_sine",4),
|
||||||
|
EASE_IN_QUAD("in_quad",5),
|
||||||
|
EASE_OUT_QUAD("out_quad",6),
|
||||||
|
EASE_IN_OUT_QUAD("in_out_quad",7),
|
||||||
|
EASE_IN_CUBIC("in_cubic",8),
|
||||||
|
EASE_OUT_CUBIC("out_cubic",9),
|
||||||
|
EASE_IN_OUT_CUBIC("in_out_cubic",10),
|
||||||
|
EASE_IN_QUART("in_quart",11),
|
||||||
|
EASE_OUT_QUART("out_quart",12),
|
||||||
|
EASE_IN_OUT_QUART("in_out_quart",13),
|
||||||
|
EASE_IN_QUINT("in_quint",14),
|
||||||
|
EASE_OUT_QUINT("out_quint",15),
|
||||||
|
EASE_IN_OUT_QUINT("in_out_quint",16),
|
||||||
|
EASE_IN_EXPO("in_expo",17),
|
||||||
|
EASE_OUT_EXPO("out_expo",18),
|
||||||
|
EASE_IN_OUT_EXPO("in_out_expo",19),
|
||||||
|
EASE_IN_CIRC("in_circ",20),
|
||||||
|
EASE_OUT_CIRC("out_circ",21),
|
||||||
|
EASE_IN_OUT_CIRC("in_out_circ",22),
|
||||||
|
EASE_IN_BACK("in_back",23),
|
||||||
|
EASE_OUT_BACK("out_back",24),
|
||||||
|
EASE_IN_OUT_BACK("in_out_back",25),
|
||||||
|
EASE_IN_ELASTIC("in_elastic",26),
|
||||||
|
EASE_OUT_ELASTIC("out_elastic",27),
|
||||||
|
EASE_IN_OUT_ELASTIC("in_out_elastic",28),
|
||||||
|
EASE_IN_BOUNCE("in_bounce",29),
|
||||||
|
EASE_OUT_BOUNCE("out_bounce",30),
|
||||||
|
EASE_IN_OUT_BOUNCE("in_out_bounce",31);
|
||||||
|
|
||||||
|
|
||||||
|
private final String type;
|
||||||
|
private final int index;
|
||||||
|
EaseType(String type, int index) {
|
||||||
|
this.type = type;
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.data;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
@Data
|
||||||
|
public class Pos {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.data;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
@Data
|
||||||
|
public class Rot {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.data;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
@Data
|
||||||
|
public class Time {
|
||||||
|
float fadeIn;
|
||||||
|
float hold;
|
||||||
|
float fadeOut;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.instruction;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class ClearInstruction implements Instruction {
|
||||||
|
private static final ClearInstruction INSTANCE = new ClearInstruction();
|
||||||
|
private final int clear = 1;
|
||||||
|
|
||||||
|
private ClearInstruction() {}
|
||||||
|
|
||||||
|
public static ClearInstruction instance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.instruction;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.data.Color;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.data.Time;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public class FadeInstruction implements Instruction {
|
||||||
|
@Nullable
|
||||||
|
private Color color;
|
||||||
|
@Nullable
|
||||||
|
private Time time;
|
||||||
|
|
||||||
|
protected FadeInstruction() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.instruction;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public interface Instruction extends Serializable {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.camera.instruction;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.data.CameraPreset;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.data.Ease;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.data.Pos;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.data.Rot;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Getter
|
||||||
|
public class SetInstruction implements Instruction {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Ease ease;
|
||||||
|
@Nullable
|
||||||
|
private Pos pos;
|
||||||
|
@Nullable
|
||||||
|
private Rot rot;
|
||||||
|
@Nullable
|
||||||
|
private Pos facing;
|
||||||
|
private CameraPreset preset;
|
||||||
|
protected SetInstruction() {}
|
||||||
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
package me.zimzaza4.geyserutils.common.manager;
|
package me.zimzaza4.geyserutils.common.manager;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
|
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
|
||||||
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
|
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
|
||||||
import me.zimzaza4.geyserutils.common.packet.CustomPayloadPacket;
|
import me.zimzaza4.geyserutils.common.packet.CustomPayloadPacket;
|
||||||
@@ -18,6 +22,7 @@ public class PacketManager {
|
|||||||
public PacketManager() {
|
public PacketManager() {
|
||||||
objectMapper = new ObjectMapper();
|
objectMapper = new ObjectMapper();
|
||||||
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.EVERYTHING, JsonTypeInfo.As.PROPERTY);
|
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.EVERYTHING, JsonTypeInfo.As.PROPERTY);
|
||||||
|
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.packet;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.instruction.Instruction;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class CameraInstructionCustomPayloadPacket extends CustomPayloadPacket {
|
||||||
|
private Instruction instruction;
|
||||||
|
}
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.geysermc.geyser</groupId>
|
<groupId>org.geysermc.geyser</groupId>
|
||||||
<artifactId>core</artifactId>
|
<artifactId>core</artifactId>
|
||||||
<version>2.1.2-SNAPSHOT</version>
|
<version>2.2.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -6,18 +6,29 @@ import com.github.steveice10.packetlib.Session;
|
|||||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.data.CameraPreset;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.instruction.ClearInstruction;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.instruction.FadeInstruction;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.instruction.SetInstruction;
|
||||||
import me.zimzaza4.geyserutils.common.channel.GeyserUtilsChannels;
|
import me.zimzaza4.geyserutils.common.channel.GeyserUtilsChannels;
|
||||||
import me.zimzaza4.geyserutils.common.form.element.NpcDialogueButton;
|
import me.zimzaza4.geyserutils.common.form.element.NpcDialogueButton;
|
||||||
import me.zimzaza4.geyserutils.common.manager.PacketManager;
|
import me.zimzaza4.geyserutils.common.manager.PacketManager;
|
||||||
import me.zimzaza4.geyserutils.common.packet.*;
|
import me.zimzaza4.geyserutils.common.packet.*;
|
||||||
import me.zimzaza4.geyserutils.common.util.CustomPayloadPacketUtils;
|
import me.zimzaza4.geyserutils.geyser.camera.CameraPresetDefinition;
|
||||||
|
import me.zimzaza4.geyserutils.geyser.camera.Converter;
|
||||||
import me.zimzaza4.geyserutils.geyser.form.NpcDialogueForm;
|
import me.zimzaza4.geyserutils.geyser.form.NpcDialogueForm;
|
||||||
import me.zimzaza4.geyserutils.geyser.form.NpcDialogueForms;
|
import me.zimzaza4.geyserutils.geyser.form.NpcDialogueForms;
|
||||||
import me.zimzaza4.geyserutils.geyser.form.element.Button;
|
import me.zimzaza4.geyserutils.geyser.form.element.Button;
|
||||||
import me.zimzaza4.geyserutils.geyser.translator.NPCFormResponseTranslator;
|
import me.zimzaza4.geyserutils.geyser.translator.NPCFormResponseTranslator;
|
||||||
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.AnimateEntityPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.AnimateEntityPacket;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.packet.CameraInstructionPacket;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.packet.CameraPresetsPacket;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.NpcRequestPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.NpcRequestPacket;
|
||||||
|
import org.cloudburstmc.protocol.common.DefinitionRegistry;
|
||||||
|
import org.cloudburstmc.protocol.common.NamedDefinition;
|
||||||
import org.geysermc.event.subscribe.Subscribe;
|
import org.geysermc.event.subscribe.Subscribe;
|
||||||
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
|
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
|
||||||
import org.geysermc.geyser.api.event.bedrock.SessionJoinEvent;
|
import org.geysermc.geyser.api.event.bedrock.SessionJoinEvent;
|
||||||
import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent;
|
import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent;
|
||||||
@@ -28,20 +39,36 @@ import org.geysermc.geyser.session.GeyserSession;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class GeyserUtils implements Extension {
|
public class GeyserUtils implements Extension {
|
||||||
|
|
||||||
|
|
||||||
|
NbtMap CLEAR_INSTRUCTION_TAG = NbtMap.builder().putByte("clear", Integer.valueOf(1).byteValue()).build();
|
||||||
@Getter
|
@Getter
|
||||||
public static PacketManager packetManager;
|
public static PacketManager packetManager;
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onLoad(GeyserPostInitializeEvent event) {
|
public void onLoad(GeyserPostInitializeEvent event) {
|
||||||
packetManager = new PacketManager();
|
packetManager = new PacketManager();
|
||||||
|
CameraPreset.load();
|
||||||
Registries.BEDROCK_PACKET_TRANSLATORS.register(NpcRequestPacket.class, new NPCFormResponseTranslator());
|
Registries.BEDROCK_PACKET_TRANSLATORS.register(NpcRequestPacket.class, new NPCFormResponseTranslator());
|
||||||
|
|
||||||
|
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> {
|
||||||
|
|
||||||
|
for (GeyserSession session : GeyserImpl.getInstance().onlineConnections()) {
|
||||||
|
sendCameraPresets(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 10, 10, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onSessionJoin(SessionJoinEvent event) {
|
public void onSessionJoin(SessionJoinEvent event) {
|
||||||
if (event.connection() instanceof GeyserSession session) {
|
if (event.connection() instanceof GeyserSession session) {
|
||||||
|
sendCameraPresets(session);
|
||||||
session.getDownstream().getSession().addListener(new SessionAdapter() {
|
session.getDownstream().getSession().addListener(new SessionAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void packetReceived(Session tcpSession, Packet packet) {
|
public void packetReceived(Session tcpSession, Packet packet) {
|
||||||
@@ -111,11 +138,53 @@ public class GeyserUtils implements Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
session.sendUpstreamPacket(animateEntityPacket);
|
session.sendUpstreamPacket(animateEntityPacket);
|
||||||
|
} else if (customPacket instanceof CameraInstructionCustomPayloadPacket cameraInstructionPacket) {
|
||||||
|
CameraInstructionPacket bedrockPacket = new CameraInstructionPacket();
|
||||||
|
if (cameraInstructionPacket.getInstruction() instanceof SetInstruction instruction) {
|
||||||
|
bedrockPacket.setSetInstruction(Converter.serializeSetInstruction(instruction));
|
||||||
|
} else if (cameraInstructionPacket.getInstruction() instanceof FadeInstruction instruction) {
|
||||||
|
bedrockPacket.setFadeInstruction(Converter.serializeFadeInstruction(instruction));
|
||||||
|
} else if (cameraInstructionPacket.getInstruction() instanceof ClearInstruction){
|
||||||
|
bedrockPacket.setClear(true);
|
||||||
|
}
|
||||||
|
session.sendUpstreamPacket(bedrockPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendCameraPresets(GeyserSession session) {
|
||||||
|
if (session.getUpstream().getCodecHelper().getCameraPresetDefinitions() == null) {
|
||||||
|
|
||||||
|
session.getUpstream().getCodecHelper().setCameraPresetDefinitions(new DefinitionRegistry<>() {
|
||||||
|
@Override
|
||||||
|
public NamedDefinition getDefinition(int i) {
|
||||||
|
for (CameraPreset preset : CameraPreset.getPresets().values()) {
|
||||||
|
if (preset.getId() == i) {
|
||||||
|
return new CameraPresetDefinition(preset.getIdentifier(), i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRegistered(NamedDefinition namedDefinition) {
|
||||||
|
return CameraPreset.getPreset(namedDefinition.getIdentifier()) != null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
CameraPresetsPacket pk = new CameraPresetsPacket();
|
||||||
|
for (CameraPreset preset : CameraPreset.getPresets().values()) {
|
||||||
|
pk.getPresets().add(Converter.serializeCameraPreset(preset));
|
||||||
|
}
|
||||||
|
|
||||||
|
session.sendUpstreamPacket(pk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package me.zimzaza4.geyserutils.geyser.camera;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.cloudburstmc.protocol.common.NamedDefinition;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CameraPresetDefinition implements NamedDefinition {
|
||||||
|
private String identifier;
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRuntimeId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CameraPresetDefinition{" +
|
||||||
|
"identifier='" + identifier + '\'' +
|
||||||
|
", id=" + id +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package me.zimzaza4.geyserutils.geyser.camera;
|
||||||
|
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.data.*;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.instruction.FadeInstruction;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.instruction.SetInstruction;
|
||||||
|
import org.cloudburstmc.math.vector.Vector2f;
|
||||||
|
import org.cloudburstmc.math.vector.Vector3f;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.data.camera.CameraAudioListener;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.data.camera.CameraEase;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.data.camera.CameraFadeInstruction;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.data.camera.CameraSetInstruction;
|
||||||
|
import org.cloudburstmc.protocol.common.util.OptionalBoolean;
|
||||||
|
|
||||||
|
public class Converter {
|
||||||
|
|
||||||
|
public static org.cloudburstmc.protocol.bedrock.data.camera.CameraPreset serializeCameraPreset(CameraPreset preset) {
|
||||||
|
org.cloudburstmc.protocol.bedrock.data.camera.CameraPreset cbPreset = new org.cloudburstmc.protocol.bedrock.data.camera.CameraPreset();
|
||||||
|
|
||||||
|
cbPreset.setIdentifier(preset.getIdentifier());
|
||||||
|
|
||||||
|
cbPreset.setParentPreset(preset.getInheritFrom());
|
||||||
|
|
||||||
|
cbPreset.setListener(CameraAudioListener.PLAYER);
|
||||||
|
|
||||||
|
cbPreset.setPlayEffect(OptionalBoolean.of(true));
|
||||||
|
|
||||||
|
if (preset.getPos() != null) {
|
||||||
|
cbPreset.setPos(serializePos(preset.getPos()));
|
||||||
|
}
|
||||||
|
if (preset.getRot() != null) {
|
||||||
|
cbPreset.setPitch(preset.getRot().x());
|
||||||
|
cbPreset.setYaw(preset.getRot().y());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return cbPreset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static java.awt.Color serializeColor(Color color) {
|
||||||
|
return new java.awt.Color(color.r(), color.g(), color.b());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CameraSetInstruction.EaseData serializeEase(Ease ease) {
|
||||||
|
return new CameraSetInstruction.EaseData(CameraEase.values()[ease.easeType()], ease.time());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CameraFadeInstruction.TimeData serializeTime(Time time) {
|
||||||
|
return new CameraFadeInstruction.TimeData(time.fadeIn(), time.hold(), time.fadeOut());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Vector3f serializePos(Pos pos) {
|
||||||
|
return Vector3f.from(pos.x(), pos.y(), pos.z());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector2f serializeRot(Rot rot) {
|
||||||
|
return Vector2f.from(rot.x(), rot.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static CameraFadeInstruction serializeFadeInstruction(FadeInstruction instruction) {
|
||||||
|
CameraFadeInstruction cbInstruction = new CameraFadeInstruction();
|
||||||
|
|
||||||
|
if (instruction.getColor() != null) {
|
||||||
|
cbInstruction.setColor(serializeColor(instruction.getColor()));
|
||||||
|
}
|
||||||
|
if (instruction.getTime() != null) {
|
||||||
|
cbInstruction.setTimeData(serializeTime(instruction.getTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return cbInstruction;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CameraSetInstruction serializeSetInstruction(SetInstruction instruction) {
|
||||||
|
|
||||||
|
CameraSetInstruction cbInstruction = new CameraSetInstruction();
|
||||||
|
|
||||||
|
if (instruction.getEase() != null) {
|
||||||
|
cbInstruction.setEase(serializeEase(instruction.getEase()));
|
||||||
|
}
|
||||||
|
if (instruction.getPos() != null) {
|
||||||
|
cbInstruction.setPos(serializePos(instruction.getPos()));
|
||||||
|
}
|
||||||
|
if (instruction.getRot() != null) {
|
||||||
|
cbInstruction.setRot(serializeRot(instruction.getRot()));
|
||||||
|
}
|
||||||
|
if (instruction.getFacing() != null) {
|
||||||
|
cbInstruction.setFacing(serializePos(instruction.getFacing()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cbInstruction.setDefaultPreset(OptionalBoolean.of(false));
|
||||||
|
cbInstruction.setPreset(new CameraPresetDefinition(instruction.getPreset().getIdentifier(), instruction.getPreset().getId()));
|
||||||
|
return cbInstruction;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -29,7 +29,6 @@ public class NPCFormResponseTranslator extends PacketTranslator<NpcRequestPacket
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(packet);
|
|
||||||
|
|
||||||
Button button = form.dialogueButtons().get(packet.getActionType());
|
Button button = form.dialogueButtons().get(packet.getActionType());
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package me.zimzaza4.geyserutils.spigot.api;
|
package me.zimzaza4.geyserutils.spigot.api;
|
||||||
|
|
||||||
import me.zimzaza4.geyserutils.common.animation.Animation;
|
import me.zimzaza4.geyserutils.common.animation.Animation;
|
||||||
|
import me.zimzaza4.geyserutils.common.camera.instruction.Instruction;
|
||||||
import me.zimzaza4.geyserutils.common.channel.GeyserUtilsChannels;
|
import me.zimzaza4.geyserutils.common.channel.GeyserUtilsChannels;
|
||||||
import me.zimzaza4.geyserutils.common.packet.AnimateEntityCustomPayloadPacket;
|
import me.zimzaza4.geyserutils.common.packet.AnimateEntityCustomPayloadPacket;
|
||||||
|
import me.zimzaza4.geyserutils.common.packet.CameraInstructionCustomPayloadPacket;
|
||||||
import me.zimzaza4.geyserutils.common.packet.CameraShakeCustomPayloadPacket;
|
import me.zimzaza4.geyserutils.common.packet.CameraShakeCustomPayloadPacket;
|
||||||
import me.zimzaza4.geyserutils.common.util.CustomPayloadPacketUtils;
|
import me.zimzaza4.geyserutils.common.util.CustomPayloadPacketUtils;
|
||||||
import me.zimzaza4.geyserutils.spigot.GeyserUtils;
|
import me.zimzaza4.geyserutils.spigot.GeyserUtils;
|
||||||
@@ -35,4 +37,11 @@ public class PlayerUtils {
|
|||||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendCameraInstruction(Player player, Instruction instruction) {
|
||||||
|
CameraInstructionCustomPayloadPacket packet = new CameraInstructionCustomPayloadPacket();
|
||||||
|
packet.setInstruction(instruction);
|
||||||
|
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public class GeyserUtils {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
|
|
||||||
server.getChannelRegistrar().register(MinecraftChannelIdentifier.from(GeyserUtilsChannels.MAIN));
|
server.getChannelRegistrar().register(MinecraftChannelIdentifier.from(GeyserUtilsChannels.MAIN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user