9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-19 15:09:19 +00:00

feat: use new Hibiscus Commons methods for packets

This commit is contained in:
Logan
2025-09-06 23:19:31 -05:00
parent 7abfb0edf1
commit 8011dda200
3 changed files with 43 additions and 18 deletions

View File

@@ -62,9 +62,7 @@ public class CosmeticBackpackType extends Cosmetic {
entityManager.teleport(loc);
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
HMCCPacketManager.sendEntitySpawnPacket(entityLocation, firstArmorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
HMCCPacketManager.sendArmorstandMetadata(firstArmorStandId, outsideViewers);
HMCCPacketManager.spawnInvisibleArmorstand(firstArmorStandId, entityLocation, UUID.randomUUID(), outsideViewers);
if (user.getPlayer() != null) {
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE);
if (scaleAttribute != null) {

View File

@@ -55,8 +55,8 @@ public class UserBackpackManager {
getEntityManager().setIds(List.of(invisibleArmorStand));
getEntityManager().teleport(user.getEntity().getLocation());
List<Player> outsideViewers = getEntityManager().getViewers();
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers());
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), outsideViewers);
HMCCPacketManager.spawnInvisibleArmorstand(getFirstArmorStandId(), user.getEntity().getLocation(), UUID.randomUUID(), outsideViewers);
if (user.getPlayer() != null) {
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE);
@@ -81,8 +81,7 @@ public class UserBackpackManager {
if (cosmeticBackpackType.isFirstPersonCompadible()) {
for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) {
int entityId = ServerUtils.getNextEntityId();
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID());
HMCCPacketManager.sendCloudEffect(entityId, HMCCPacketManager.getViewers(user.getEntity().getLocation()));
HMCCPacketManager.spawnCloudAndHandleEffect(entityId, user.getEntity().getLocation(), UUID.randomUUID(), HMCCPacketManager.getViewers(user.getEntity().getLocation()));
this.particleCloud.add(entityId);
}
// Copied code from updating the backpack

View File

@@ -23,6 +23,7 @@ import java.util.*;
public class HMCCPacketManager extends PacketManager {
// The cloud effect map, in case it gets lost: Map<Integer, Number> dataValues = Map.of(0, (byte) 0x20, 8, 0f);
private static final List<CosmeticSlot> EQUIPMENT_SLOTS = List.of(CosmeticSlot.HELMET, CosmeticSlot.CHESTPLATE, CosmeticSlot.LEGGINGS, CosmeticSlot.BOOTS, CosmeticSlot.MAINHAND, CosmeticSlot.OFFHAND);
public static void sendEntitySpawnPacket(
@@ -83,15 +84,6 @@ public class HMCCPacketManager extends PacketManager {
equipmentSlotUpdate(entityId, HMCCInventoryUtils.getEquipmentSlot(cosmeticSlot), user.getUserCosmeticItem(cosmeticSlot), sendTo);
}
public static void sendArmorstandMetadata(
int entityId,
List<Player> sendTo
) {
byte mask = (byte) (Settings.isBackpackPreventDarkness() ? 0x21 : 0x20);
Map<Integer, Number> dataValues = Map.of(0, mask, 15, (byte) 0x10);
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, dataValues, sendTo);
}
public static void sendInvisibilityPacket(
int entityId,
List<Player> sendTo
@@ -99,14 +91,50 @@ public class HMCCPacketManager extends PacketManager {
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, Map.of(0, (byte) 0x20), sendTo);
}
public static void sendCloudEffect(
public static void spawnCloudAndHandleEffect(
int entityId,
Location location,
UUID uuid,
List<Player> sendTo
) {
NMSHandlers.getHandler().getPacketHandler().sendInvisibleParticleCloud(entityId, location, uuid, sendTo);
}
/**
* This handles both spawn + metadata in a bundle packet
* @param entityId
* @param location
* @param uuid
* @param sendTo
*/
public static void spawnInvisibleArmorstand(
int entityId,
Location location,
UUID uuid,
List<Player> sendTo
) {
byte mask = getMask();
NMSHandlers.getHandler().getPacketHandler().sendInvisibleArmorstand(entityId, location, uuid, mask, sendTo);
}
/**
* This is just a normal meta data packet (non-bundled)
* @param entityId
* @param sendTo
*/
public static void sendArmorstandMetadata(
int entityId,
List<Player> sendTo
) {
Map<Integer, Number> dataValues = Map.of(0, (byte) 0x20, 8, 0f);
byte mask = getMask();
Map<Integer, Number> dataValues = Map.of(0, mask, 15, (byte) 0x10);
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, dataValues, sendTo);
}
private static byte getMask() {
return (byte) (Settings.isBackpackPreventDarkness() ? 0x21 : 0x20);
}
public static void sendRotationPacket(
int entityId,
Location location,