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:
@@ -62,9 +62,7 @@ public class CosmeticBackpackType extends Cosmetic {
|
|||||||
entityManager.teleport(loc);
|
entityManager.teleport(loc);
|
||||||
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||||
|
|
||||||
HMCCPacketManager.sendEntitySpawnPacket(entityLocation, firstArmorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
|
HMCCPacketManager.spawnInvisibleArmorstand(firstArmorStandId, entityLocation, UUID.randomUUID(), outsideViewers);
|
||||||
HMCCPacketManager.sendArmorstandMetadata(firstArmorStandId, outsideViewers);
|
|
||||||
|
|
||||||
if (user.getPlayer() != null) {
|
if (user.getPlayer() != null) {
|
||||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE);
|
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE);
|
||||||
if (scaleAttribute != null) {
|
if (scaleAttribute != null) {
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ public class UserBackpackManager {
|
|||||||
getEntityManager().setIds(List.of(invisibleArmorStand));
|
getEntityManager().setIds(List.of(invisibleArmorStand));
|
||||||
getEntityManager().teleport(user.getEntity().getLocation());
|
getEntityManager().teleport(user.getEntity().getLocation());
|
||||||
List<Player> outsideViewers = getEntityManager().getViewers();
|
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) {
|
if (user.getPlayer() != null) {
|
||||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE);
|
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE);
|
||||||
@@ -81,8 +81,7 @@ public class UserBackpackManager {
|
|||||||
if (cosmeticBackpackType.isFirstPersonCompadible()) {
|
if (cosmeticBackpackType.isFirstPersonCompadible()) {
|
||||||
for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) {
|
for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) {
|
||||||
int entityId = ServerUtils.getNextEntityId();
|
int entityId = ServerUtils.getNextEntityId();
|
||||||
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID());
|
HMCCPacketManager.spawnCloudAndHandleEffect(entityId, user.getEntity().getLocation(), UUID.randomUUID(), HMCCPacketManager.getViewers(user.getEntity().getLocation()));
|
||||||
HMCCPacketManager.sendCloudEffect(entityId, HMCCPacketManager.getViewers(user.getEntity().getLocation()));
|
|
||||||
this.particleCloud.add(entityId);
|
this.particleCloud.add(entityId);
|
||||||
}
|
}
|
||||||
// Copied code from updating the backpack
|
// Copied code from updating the backpack
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.util.*;
|
|||||||
|
|
||||||
public class HMCCPacketManager extends PacketManager {
|
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);
|
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(
|
public static void sendEntitySpawnPacket(
|
||||||
@@ -83,15 +84,6 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
equipmentSlotUpdate(entityId, HMCCInventoryUtils.getEquipmentSlot(cosmeticSlot), user.getUserCosmeticItem(cosmeticSlot), sendTo);
|
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(
|
public static void sendInvisibilityPacket(
|
||||||
int entityId,
|
int entityId,
|
||||||
List<Player> sendTo
|
List<Player> sendTo
|
||||||
@@ -99,14 +91,50 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, Map.of(0, (byte) 0x20), sendTo);
|
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,
|
int entityId,
|
||||||
List<Player> sendTo
|
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);
|
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, dataValues, sendTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static byte getMask() {
|
||||||
|
return (byte) (Settings.isBackpackPreventDarkness() ? 0x21 : 0x20);
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendRotationPacket(
|
public static void sendRotationPacket(
|
||||||
int entityId,
|
int entityId,
|
||||||
Location location,
|
Location location,
|
||||||
|
|||||||
Reference in New Issue
Block a user