use of com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject in project LaBoulangerieMmo by LaBoulangerie.
the class MarkedBlocksManager method sendShulker.
private void sendShulker(Player player, Block block, Integer id, UUID uuid) {
// https://github.com/libraryaddict/LibsDisguises/blob/master/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java
PacketContainer spawnShulker = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
StructureModifier<Object> mods = spawnShulker.getModifier();
// Entity ID
mods.write(0, id).write(1, // entity UUID
uuid).write(2, // 75 = shulker
75).write(3, // Pos X, Y, Z
block.getX() + 0.5).write(4, block.getY()).write(5, block.getZ() + 0.5).write(6, // Velocity X, Y, Z
(short) 0).write(7, (short) 0).write(8, (short) 0).write(9, // yaw
(byte) 0).write(10, // pitch
(byte) 0).write(11, // yaw
(byte) 0);
PacketContainer shulkerMetadata = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
StructureModifier<Object> metadataMods = shulkerMetadata.getModifier();
metadataMods.write(0, id);
WrappedDataWatcher watcher = new WrappedDataWatcher();
// 0x20
watcher.setObject(new WrappedDataWatcherObject(0, Registry.get(Byte.class)), (byte) (0x20 | 0x40));
// invisible
// 0x40
// glowing
shulkerMetadata.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, spawnShulker);
ProtocolLibrary.getProtocolManager().sendServerPacket(player, shulkerMetadata);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
use of com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject in project InteractionVisualizer by LOOHP.
the class WatchableCollection method getWatchableCollection.
public static WrappedDataWatcher getWatchableCollection(ItemFrame frame, WrappedDataWatcher watcher) {
if (watcher == null) {
watcher = new WrappedDataWatcher();
}
watcher.setObject(new WrappedDataWatcherObject(4, booleanSerializer), frame.isSilent());
switch(metaversion) {
case 0:
case 1:
watcher.setObject(new WrappedDataWatcherObject(6, itemSerializer), frame.getItem());
watcher.setObject(new WrappedDataWatcherObject(7, intSerializer), frame.getFrameRotation());
break;
case 2:
case 3:
watcher.setObject(new WrappedDataWatcherObject(7, itemSerializer), frame.getItem());
watcher.setObject(new WrappedDataWatcherObject(8, intSerializer), frame.getFrameRotation());
break;
case 4:
watcher.setObject(new WrappedDataWatcherObject(8, itemSerializer), frame.getItem());
watcher.setObject(new WrappedDataWatcherObject(9, intSerializer), frame.getFrameRotation());
break;
}
return watcher;
}
use of com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject in project InteractionVisualizer by LOOHP.
the class WatchableCollection method getWatchableCollection.
public static WrappedDataWatcher getWatchableCollection(ArmorStand stand, WrappedDataWatcher watcher) {
if (watcher == null) {
watcher = new WrappedDataWatcher();
}
byte bitmask = (byte) 0;
bitmask = !stand.isVisible() ? (byte) (bitmask | 0x20) : bitmask;
watcher.setObject(new WrappedDataWatcherObject(0, byteSerializer), bitmask);
switch(metaversion) {
case 0:
if (stand.getCustomName() != null && !PlainTextComponentSerializer.plainText().serialize(stand.getCustomName()).equals("")) {
watcher.setObject(new WrappedDataWatcherObject(2, stringSerializer), LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(stand.getCustomName(), InteractionVisualizer.language)));
} else {
watcher.setObject(new WrappedDataWatcherObject(2, stringSerializer), "");
}
break;
case 1:
case 2:
case 3:
case 4:
watcher.setObject(new WrappedDataWatcherObject(2, optChatSerializer), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(stand.getCustomName())).getHandle()));
break;
}
watcher.setObject(new WrappedDataWatcherObject(3, booleanSerializer), stand.isCustomNameVisible());
watcher.setObject(new WrappedDataWatcherObject(4, booleanSerializer), stand.isSilent());
watcher.setObject(new WrappedDataWatcherObject(5, booleanSerializer), !stand.hasGravity());
byte standbitmask = (byte) 0;
standbitmask = stand.isSmall() ? (byte) (standbitmask | 0x01) : standbitmask;
standbitmask = stand.hasArms() ? (byte) (standbitmask | 0x04) : standbitmask;
standbitmask = !stand.hasBasePlate() ? (byte) (standbitmask | 0x08) : standbitmask;
standbitmask = stand.isMarker() ? (byte) (standbitmask | 0x10) : standbitmask;
switch(metaversion) {
case 0:
case 1:
watcher.setObject(new WrappedDataWatcherObject(11, byteSerializer), standbitmask);
break;
case 2:
watcher.setObject(new WrappedDataWatcherObject(13, byteSerializer), standbitmask);
break;
case 3:
watcher.setObject(new WrappedDataWatcherObject(14, byteSerializer), standbitmask);
break;
case 4:
watcher.setObject(new WrappedDataWatcherObject(15, byteSerializer), standbitmask);
break;
}
Vector3F headrotation = new Vector3F();
headrotation.setX((float) Math.toDegrees(stand.getHeadPose().getX()));
headrotation.setY((float) Math.toDegrees(stand.getHeadPose().getY()));
headrotation.setZ((float) Math.toDegrees(stand.getHeadPose().getZ()));
switch(metaversion) {
case 0:
case 1:
watcher.setObject(new WrappedDataWatcherObject(12, vectorSerializer), headrotation);
break;
case 2:
watcher.setObject(new WrappedDataWatcherObject(14, vectorSerializer), headrotation);
break;
case 3:
watcher.setObject(new WrappedDataWatcherObject(15, vectorSerializer), headrotation);
break;
case 4:
watcher.setObject(new WrappedDataWatcherObject(16, vectorSerializer), headrotation);
break;
}
Vector3F rightarmrotation = new Vector3F();
rightarmrotation.setX((float) Math.toDegrees(stand.getRightArmPose().getX()));
rightarmrotation.setY((float) Math.toDegrees(stand.getRightArmPose().getY()));
rightarmrotation.setZ((float) Math.toDegrees(stand.getRightArmPose().getZ()));
switch(metaversion) {
case 0:
case 1:
watcher.setObject(new WrappedDataWatcherObject(15, vectorSerializer), rightarmrotation);
break;
case 2:
watcher.setObject(new WrappedDataWatcherObject(17, vectorSerializer), rightarmrotation);
break;
case 3:
watcher.setObject(new WrappedDataWatcherObject(18, vectorSerializer), rightarmrotation);
break;
case 4:
watcher.setObject(new WrappedDataWatcherObject(19, vectorSerializer), rightarmrotation);
break;
}
return watcher;
}
use of com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject in project InteractionVisualizer by LOOHP.
the class WatchableCollection method createCustomNameWatchableCollection.
public static WrappedDataWatcher createCustomNameWatchableCollection(Component name, WrappedDataWatcher watcher) {
if (watcher == null) {
watcher = new WrappedDataWatcher();
}
boolean visible;
try {
visible = name != null && !PlainTextComponentSerializer.plainText().serialize(name).equals("");
} catch (Exception e) {
visible = false;
}
switch(metaversion) {
case 0:
if (visible) {
watcher.setObject(new WrappedDataWatcherObject(2, stringSerializer), LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(name, InteractionVisualizer.language)));
} else {
watcher.setObject(new WrappedDataWatcherObject(2, stringSerializer), "");
}
break;
case 1:
case 2:
case 3:
case 4:
watcher.setObject(new WrappedDataWatcherObject(2, optChatSerializer), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(name)).getHandle()));
break;
}
watcher.setObject(new WrappedDataWatcherObject(3, booleanSerializer), visible);
return watcher;
}
use of com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject in project InteractionVisualizer by LOOHP.
the class WatchableCollection method getWatchableCollection.
public static WrappedDataWatcher getWatchableCollection(Item item, WrappedDataWatcher watcher) {
if (watcher == null) {
watcher = new WrappedDataWatcher();
}
byte bitmask = (byte) 0;
bitmask = item.isGlowing() ? (byte) (bitmask | 0x40) : bitmask;
watcher.setObject(new WrappedDataWatcherObject(0, byteSerializer), bitmask);
switch(metaversion) {
case 0:
if (item.getCustomName() != null && !PlainTextComponentSerializer.plainText().serialize(item.getCustomName()).equals("")) {
watcher.setObject(new WrappedDataWatcherObject(2, stringSerializer), LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(item.getCustomName(), InteractionVisualizer.language)));
} else {
watcher.setObject(new WrappedDataWatcherObject(2, stringSerializer), "");
}
break;
case 1:
case 2:
case 3:
case 4:
watcher.setObject(new WrappedDataWatcherObject(2, optChatSerializer), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(item.getCustomName())).getHandle()));
break;
}
watcher.setObject(new WrappedDataWatcherObject(3, booleanSerializer), item.isCustomNameVisible());
watcher.setObject(new WrappedDataWatcherObject(5, booleanSerializer), !item.hasGravity());
switch(metaversion) {
case 0:
case 1:
watcher.setObject(new WrappedDataWatcherObject(6, itemSerializer), item.getItemStack());
break;
case 2:
case 3:
watcher.setObject(new WrappedDataWatcherObject(7, itemSerializer), item.getItemStack());
break;
case 4:
watcher.setObject(new WrappedDataWatcherObject(8, itemSerializer), item.getItemStack());
break;
}
return watcher;
}
Aggregations