mirror of
https://github.com/GeyserExtensionists/GeyserUtils.git
synced 2025-12-19 15:09:24 +00:00
Added colors, added a bundle packet, added authors and removed practically all annoying debug messages
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package me.zimzaza4.geyserutils.common.packet;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class BundlePacket extends CustomPayloadPacket {
|
||||
|
||||
private List<CustomPayloadPacket> packets = new ArrayList<>();
|
||||
|
||||
public void addPacket(CustomPayloadPacket packet) {
|
||||
this.packets.add(packet);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@@ -17,4 +19,6 @@ public class CustomEntityDataPacket extends CustomPayloadPacket {
|
||||
|
||||
private Float scale;
|
||||
|
||||
private Integer color;
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import me.zimzaza4.geyserutils.geyser.scoreboard.EntityScoreboard;
|
||||
import me.zimzaza4.geyserutils.geyser.translator.NPCFormResponseTranslator;
|
||||
import me.zimzaza4.geyserutils.geyser.util.Converter;
|
||||
import me.zimzaza4.geyserutils.geyser.util.ReflectionUtils;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.cloudburstmc.math.vector.Vector3f;
|
||||
import org.cloudburstmc.nbt.NbtMap;
|
||||
import org.cloudburstmc.nbt.NbtType;
|
||||
@@ -65,6 +66,7 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.Clien
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@@ -72,6 +74,7 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class GeyserUtils implements Extension {
|
||||
@@ -322,7 +325,57 @@ public class GeyserUtils implements Extension {
|
||||
if (packet instanceof ClientboundCustomPayloadPacket payloadPacket) {
|
||||
if (ReflectionUtils.getChannel(payloadPacket).toString().equals(GeyserUtilsChannels.MAIN)) {
|
||||
CustomPayloadPacket customPacket = packetManager.decodePacket(payloadPacket.getData());
|
||||
if (customPacket instanceof CameraShakeCustomPayloadPacket cameraShakePacket) {
|
||||
handleCustomPacket(session, customPacket);
|
||||
}
|
||||
} else if (packet instanceof ClientboundLevelParticlesPacket particlesPacket) {
|
||||
if (particlesPacket.getParticle().getData() instanceof ItemParticleData data) {
|
||||
GeyserItemStack itemStack = GeyserItemStack.from(data.getItemStack());
|
||||
Map<Integer, String> map = particlesMappings.getMappings().get(itemStack.asItem().javaIdentifier());
|
||||
if (map != null) {
|
||||
int id = itemStack.getOrCreateComponents().getOrDefault(DataComponentType.CUSTOM_MODEL_DATA, -1);
|
||||
String particle = map.get(id);
|
||||
if (particle != null) {
|
||||
|
||||
int dimensionId = DimensionUtils.javaToBedrock(session.getDimension());
|
||||
|
||||
SpawnParticleEffectPacket stringPacket = new SpawnParticleEffectPacket();
|
||||
stringPacket.setIdentifier(particle);
|
||||
stringPacket.setDimensionId(dimensionId);
|
||||
stringPacket.setMolangVariablesJson(Optional.empty());
|
||||
session.sendUpstreamPacket(stringPacket);
|
||||
|
||||
if (particlesPacket.getAmount() == 0) {
|
||||
// 0 means don't apply the offset
|
||||
Vector3f position = Vector3f.from(particlesPacket.getX(), particlesPacket.getY(), particlesPacket.getZ());
|
||||
stringPacket.setPosition(position);
|
||||
} else {
|
||||
Random random = ThreadLocalRandom.current();
|
||||
for (int i = 0; i < particlesPacket.getAmount(); i++) {
|
||||
double offsetX = random.nextGaussian() * (double) particlesPacket.getOffsetX();
|
||||
double offsetY = random.nextGaussian() * (double) particlesPacket.getOffsetY();
|
||||
double offsetZ = random.nextGaussian() * (double) particlesPacket.getOffsetZ();
|
||||
Vector3f position = Vector3f.from(particlesPacket.getX() + offsetX, particlesPacket.getY() + offsetY, particlesPacket.getZ() + offsetZ);
|
||||
stringPacket.setPosition(position);
|
||||
}
|
||||
}
|
||||
session.sendUpstreamPacket(stringPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}, 80, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private void handleCustomPacket(GeyserSession session, CustomPayloadPacket customPacket) {
|
||||
if (customPacket instanceof BundlePacket bundlePacket) {
|
||||
bundlePacket.getPackets().forEach(p -> handleCustomPacket(session, p));
|
||||
}
|
||||
|
||||
else if (customPacket instanceof CameraShakeCustomPayloadPacket cameraShakePacket) {
|
||||
session.camera().shakeCamera(cameraShakePacket.getIntensity(), cameraShakePacket.getDuration(), CameraShake.values()[cameraShakePacket.getType()]);
|
||||
} else if (customPacket instanceof NpcDialogueFormDataCustomPayloadPacket formData) {
|
||||
|
||||
@@ -412,28 +465,21 @@ public class GeyserUtils implements Extension {
|
||||
}
|
||||
|
||||
} else if (customPacket instanceof CustomEntityDataPacket customEntityDataPacket) {
|
||||
Entity entity = (session.getEntityCache().getEntityByJavaId(customEntityDataPacket.getEntityId()));
|
||||
Entity entity = session.getEntityCache().getEntityByJavaId(customEntityDataPacket.getEntityId());
|
||||
if (entity != null) {
|
||||
if (customEntityDataPacket.getHeight() != null) entity.setBoundingBoxHeight(customEntityDataPacket.getHeight());
|
||||
if (customEntityDataPacket.getWidth() != null) entity.setBoundingBoxWidth(customEntityDataPacket.getWidth());
|
||||
if (customEntityDataPacket.getScale() != null) entity.getDirtyMetadata().put(EntityDataTypes.SCALE, customEntityDataPacket.getScale());
|
||||
if (customEntityDataPacket.getColor() != null)
|
||||
entity.getDirtyMetadata().put(EntityDataTypes.COLOR, Byte.parseByte(String.valueOf(getColor(customEntityDataPacket.getColor()))));
|
||||
entity.updateBedrockMetadata();
|
||||
}
|
||||
} else if (customPacket instanceof EntityPropertyPacket entityPropertyPacket) {
|
||||
Entity entity = (session.getEntityCache().getEntityByJavaId(entityPropertyPacket.getEntityId()));
|
||||
Entity entity = session.getEntityCache().getEntityByJavaId(entityPropertyPacket.getEntityId());
|
||||
if (entity != null) {
|
||||
if (entityPropertyPacket.getIdentifier() == null
|
||||
|| entityPropertyPacket.getValue() == null) return;
|
||||
|
||||
String def = CUSTOM_ENTITIES.get(session).getIfPresent(entity.getEntityId());
|
||||
if (def == null) return;
|
||||
|
||||
if (!containsProperty(def, entityPropertyPacket.getIdentifier())) {
|
||||
addProperty(def, entityPropertyPacket.getIdentifier(), entityPropertyPacket.getValue().getClass());
|
||||
|
||||
registerProperties(def);
|
||||
}
|
||||
|
||||
if (entity.getPropertyManager() == null) return;
|
||||
entity.getPropertyManager().add(entityPropertyPacket.getIdentifier(),
|
||||
(Boolean) entityPropertyPacket.getValue());
|
||||
@@ -453,7 +499,7 @@ public class GeyserUtils implements Extension {
|
||||
addProperty(def, entityPropertyRegisterPacket.getIdentifier(), entityPropertyRegisterPacket.getType());
|
||||
|
||||
registerProperties(def);
|
||||
logger().info("Defined property: " + entityPropertyRegisterPacket.getIdentifier() + " in registry.");
|
||||
logger().info("DEF PROPERTIES: " + entityPropertyRegisterPacket.getIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,52 +519,6 @@ public class GeyserUtils implements Extension {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (packet instanceof ClientboundLevelParticlesPacket particlesPacket) {
|
||||
if (particlesPacket.getParticle().getData() instanceof ItemParticleData data) {
|
||||
GeyserItemStack itemStack = GeyserItemStack.from(data.getItemStack());
|
||||
Map<Integer, String> map = particlesMappings.getMappings().get(itemStack.asItem().javaIdentifier());
|
||||
if (map != null) {
|
||||
int id = itemStack.getOrCreateComponents().getOrDefault(DataComponentType.CUSTOM_MODEL_DATA, -1);
|
||||
String particle = map.get(id);
|
||||
if (particle != null) {
|
||||
|
||||
int dimensionId = DimensionUtils.javaToBedrock(session.getDimension());
|
||||
|
||||
SpawnParticleEffectPacket stringPacket = new SpawnParticleEffectPacket();
|
||||
stringPacket.setIdentifier(particle);
|
||||
stringPacket.setDimensionId(dimensionId);
|
||||
stringPacket.setMolangVariablesJson(Optional.empty());
|
||||
session.sendUpstreamPacket(stringPacket);
|
||||
|
||||
if (particlesPacket.getAmount() == 0) {
|
||||
// 0 means don't apply the offset
|
||||
Vector3f position = Vector3f.from(particlesPacket.getX(), particlesPacket.getY(), particlesPacket.getZ());
|
||||
stringPacket.setPosition(position);
|
||||
} else {
|
||||
Random random = ThreadLocalRandom.current();
|
||||
for (int i = 0; i < particlesPacket.getAmount(); i++) {
|
||||
double offsetX = random.nextGaussian() * (double) particlesPacket.getOffsetX();
|
||||
double offsetY = random.nextGaussian() * (double) particlesPacket.getOffsetY();
|
||||
double offsetZ = random.nextGaussian() * (double) particlesPacket.getOffsetZ();
|
||||
Vector3f position = Vector3f.from(particlesPacket.getX() + offsetX, particlesPacket.getY() + offsetY, particlesPacket.getZ() + offsetZ);
|
||||
stringPacket.setPosition(position);
|
||||
}
|
||||
}
|
||||
session.sendUpstreamPacket(stringPacket);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}, 80, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private static AnimateEntityPacket getAnimateEntityPacket(AnimateEntityCustomPayloadPacket animateEntityCustomPayloadPacket) {
|
||||
@@ -608,5 +608,30 @@ public class GeyserUtils implements Extension {
|
||||
return EMPTY_CAPE;
|
||||
}
|
||||
|
||||
private static int getColor(int argb) {
|
||||
TextColor color = TextColor.color(argb);
|
||||
List<TextColor> colors = Arrays.asList(
|
||||
TextColor.color(255, 255, 255), // 0: White
|
||||
TextColor.color(255, 170, 0), // 1: Orange -> Gold
|
||||
TextColor.color(255, 85, 255), // 2: Magenta -> Light Purple
|
||||
TextColor.color(85, 85, 255), // 3: Light Blue -> Blue
|
||||
TextColor.color(255, 255, 85), // 4: Yellow
|
||||
TextColor.color(85, 255, 85), // 5: Lime -> Green
|
||||
TextColor.color(255, 85, 85), // 6: Pink -> Red
|
||||
TextColor.color(170, 170, 170), // 7: Gray
|
||||
TextColor.color(85, 85, 85), // 8: Light Gray -> Dark Gray
|
||||
TextColor.color(85, 255, 255), // 9: Cyan -> Aqua
|
||||
TextColor.color(0, 170, 0), // 10: Green > Dark Green
|
||||
TextColor.color(0, 0, 170), // 11: Blue -> Dark Blue
|
||||
TextColor.color(170, 0, 170), // 12: Purple -> Dark Purple
|
||||
TextColor.color(0, 170, 0), // 13: Green -> Dark Green
|
||||
TextColor.color(170, 0, 0), // 14: Red -> Dark Red
|
||||
TextColor.color(0, 0, 0) // 15: Black
|
||||
|
||||
);
|
||||
|
||||
return colors.indexOf(TextColor.nearestColorTo(colors, color));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
package me.zimzaza4.geyserutils.geyser.replace;
|
||||
|
||||
import me.zimzaza4.geyserutils.geyser.GeyserUtils;
|
||||
import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
|
||||
@@ -130,10 +131,7 @@ public class JavaAddEntityTranslatorReplace extends PacketTranslator<Clientbound
|
||||
|
||||
String def = CUSTOM_ENTITIES.get(session).getIfPresent(entity.getEntityId());
|
||||
if (def != null) {
|
||||
System.out.println("CUSTOM ENTITY :" + entity.getEntityId() + " | " + def);
|
||||
|
||||
EntityDefinition newDef = LOADED_ENTITY_DEFINITIONS.getOrDefault(def, entity.getDefinition());
|
||||
System.out.println("CUSTOM DEF : " + newDef);
|
||||
entity.setDefinition(newDef);
|
||||
|
||||
// reinstantiate the entity object to create the propertymanager.
|
||||
|
||||
@@ -3,4 +3,4 @@ id: geyserutils
|
||||
main: me.zimzaza4.geyserutils.geyser.GeyserUtils
|
||||
api: 1.0.0
|
||||
version: 1.0.0
|
||||
authors: [zimzaza4]
|
||||
authors: [zimzaza4, willem.dev]
|
||||
@@ -12,8 +12,10 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
@@ -78,6 +80,14 @@ public class PlayerUtils {
|
||||
|
||||
}
|
||||
|
||||
public static void sendCustomColor(Player player, Entity entity, Color color) {
|
||||
CustomEntityDataPacket packet = new CustomEntityDataPacket();
|
||||
packet.setEntityId(entity.getEntityId());
|
||||
packet.setColor(color.getRGB());
|
||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||
|
||||
}
|
||||
|
||||
public static void setCustomEntity(Player player, int entityId, String def) {
|
||||
CustomEntityPacket packet = new CustomEntityPacket(entityId, def);
|
||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||
@@ -90,7 +100,7 @@ public class PlayerUtils {
|
||||
|
||||
}
|
||||
|
||||
// (yes I'm aware it's "horrible" code, I'm just matching the energy of this plugin), also this aint player packets at all lmao
|
||||
// (yes I'm aware it's "horrible" code), also this aint player packets at all lmao
|
||||
|
||||
public static void registerProperty(Player player, Entity entity, String identifier, Class<?> type) {
|
||||
EntityPropertyRegisterPacket packet = new EntityPropertyRegisterPacket();
|
||||
@@ -108,6 +118,19 @@ public class PlayerUtils {
|
||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||
}
|
||||
|
||||
public static void sendBoolProperties(Player player, Entity entity, Map<String, Boolean> bundle) {
|
||||
BundlePacket packet = new BundlePacket();
|
||||
bundle.forEach((identifier, value) -> {
|
||||
EntityPropertyPacket<Boolean> propertyPacket = new EntityPropertyPacket<>();
|
||||
propertyPacket.setEntityId(entity.getEntityId());
|
||||
propertyPacket.setIdentifier(identifier);
|
||||
propertyPacket.setValue(value);
|
||||
packet.addPacket(propertyPacket);
|
||||
});
|
||||
|
||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||
}
|
||||
|
||||
public static void sendFloatProperty(Player player, Entity entity, String identifier, Float value) {
|
||||
EntityPropertyPacket<Float> packet = new EntityPropertyPacket<>();
|
||||
packet.setEntityId(entity.getEntityId());
|
||||
@@ -116,6 +139,19 @@ public class PlayerUtils {
|
||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||
}
|
||||
|
||||
public static void sendFloatProperties(Player player, Entity entity, Map<String, Float> bundle) {
|
||||
BundlePacket packet = new BundlePacket();
|
||||
bundle.forEach((identifier, value) -> {
|
||||
EntityPropertyPacket<Float> propertyPacket = new EntityPropertyPacket<>();
|
||||
propertyPacket.setEntityId(entity.getEntityId());
|
||||
propertyPacket.setIdentifier(identifier);
|
||||
propertyPacket.setValue(value);
|
||||
packet.addPacket(propertyPacket);
|
||||
});
|
||||
|
||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||
}
|
||||
|
||||
public static void sendIntProperty(Player player, Entity entity, String identifier, Integer value) {
|
||||
EntityPropertyPacket<Integer> packet = new EntityPropertyPacket<>();
|
||||
packet.setEntityId(entity.getEntityId());
|
||||
@@ -123,4 +159,17 @@ public class PlayerUtils {
|
||||
packet.setValue(value);
|
||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||
}
|
||||
|
||||
public static void sendIntProperties(Player player, Entity entity, Map<String, Integer> bundle) {
|
||||
BundlePacket packet = new BundlePacket();
|
||||
bundle.forEach((identifier, value) -> {
|
||||
EntityPropertyPacket<Integer> propertyPacket = new EntityPropertyPacket<>();
|
||||
propertyPacket.setEntityId(entity.getEntityId());
|
||||
propertyPacket.setIdentifier(identifier);
|
||||
propertyPacket.setValue(value);
|
||||
packet.addPacket(propertyPacket);
|
||||
});
|
||||
|
||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
name: GeyserUtils
|
||||
version: '${project.version}'
|
||||
main: me.zimzaza4.geyserutils.spigot.GeyserUtils
|
||||
authors:
|
||||
- zimzaza4
|
||||
- willem.dev
|
||||
Reference in New Issue
Block a user