use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project InteractionVisualizer by LOOHP.
the class V1_16 method createEntityEquipmentPacket.
@Override
public PacketContainer[] createEntityEquipmentPacket(int entityId, List<ValuePairs<EquipmentSlot, ItemStack>> equipments) {
List<Pair<EnumItemSlot, net.minecraft.server.v1_16_R1.ItemStack>> nmsList = new ArrayList<>();
for (ValuePairs<EquipmentSlot, ItemStack> pair : equipments) {
EnumItemSlot nmsSlot;
switch(pair.getFirst()) {
case CHEST:
nmsSlot = EnumItemSlot.CHEST;
break;
case FEET:
nmsSlot = EnumItemSlot.FEET;
break;
case HEAD:
nmsSlot = EnumItemSlot.HEAD;
break;
case LEGS:
nmsSlot = EnumItemSlot.LEGS;
break;
case OFF_HAND:
nmsSlot = EnumItemSlot.OFFHAND;
break;
case HAND:
default:
nmsSlot = EnumItemSlot.MAINHAND;
break;
}
net.minecraft.server.v1_16_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(pair.getSecond());
nmsList.add(new Pair<>(nmsSlot, nmsItem));
}
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsList);
return new PacketContainer[] { PacketContainer.fromPacket(packet) };
}
use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project InteractionVisualizer by LOOHP.
the class V1_16_2 method createEntityEquipmentPacket.
@Override
public PacketContainer[] createEntityEquipmentPacket(int entityId, List<ValuePairs<EquipmentSlot, ItemStack>> equipments) {
List<Pair<EnumItemSlot, net.minecraft.server.v1_16_R2.ItemStack>> nmsList = new ArrayList<>();
for (ValuePairs<EquipmentSlot, ItemStack> pair : equipments) {
EnumItemSlot nmsSlot;
switch(pair.getFirst()) {
case CHEST:
nmsSlot = EnumItemSlot.CHEST;
break;
case FEET:
nmsSlot = EnumItemSlot.FEET;
break;
case HEAD:
nmsSlot = EnumItemSlot.HEAD;
break;
case LEGS:
nmsSlot = EnumItemSlot.LEGS;
break;
case OFF_HAND:
nmsSlot = EnumItemSlot.OFFHAND;
break;
case HAND:
default:
nmsSlot = EnumItemSlot.MAINHAND;
break;
}
net.minecraft.server.v1_16_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(pair.getSecond());
nmsList.add(new Pair<>(nmsSlot, nmsItem));
}
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsList);
return new PacketContainer[] { PacketContainer.fromPacket(packet) };
}
use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project InteractionVisualizer by LOOHP.
the class V1_16_4 method createEntityEquipmentPacket.
@Override
public PacketContainer[] createEntityEquipmentPacket(int entityId, List<ValuePairs<EquipmentSlot, ItemStack>> equipments) {
List<Pair<EnumItemSlot, net.minecraft.server.v1_16_R3.ItemStack>> nmsList = new ArrayList<>();
for (ValuePairs<EquipmentSlot, ItemStack> pair : equipments) {
EnumItemSlot nmsSlot;
switch(pair.getFirst()) {
case CHEST:
nmsSlot = EnumItemSlot.CHEST;
break;
case FEET:
nmsSlot = EnumItemSlot.FEET;
break;
case HEAD:
nmsSlot = EnumItemSlot.HEAD;
break;
case LEGS:
nmsSlot = EnumItemSlot.LEGS;
break;
case OFF_HAND:
nmsSlot = EnumItemSlot.OFFHAND;
break;
case HAND:
default:
nmsSlot = EnumItemSlot.MAINHAND;
break;
}
net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(pair.getSecond());
nmsList.add(new Pair<>(nmsSlot, nmsItem));
}
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsList);
return new PacketContainer[] { PacketContainer.fromPacket(packet) };
}
use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project CokesAddon by Cokes86.
the class v1_15_R1 method injectPlayer.
public void injectPlayer(Player player) {
CraftPlayer player1 = (CraftPlayer) player;
if (!player.isValid())
return;
if (channelHandlers.containsKey(player.getUniqueId())) {
final Pair<CraftPlayer, ChannelOutboundHandlerAdapter> pair = channelHandlers.get(player.getUniqueId());
if (!pair.getLeft().isValid()) {
try {
pair.getLeft().getHandle().playerConnection.networkManager.channel.pipeline().remove(pair.getRight());
} catch (NoSuchElementException ignored) {
}
} else
return;
}
final ChannelOutboundHandlerAdapter handler = new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
if (packet instanceof PacketPlayOutEntityEquipment) {
if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
ReflectionUtil.FieldUtil.setValue(packet, "c", ItemStack.a);
}
} else if (packet instanceof PacketPlayOutEntityMetadata) {
if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
List<Item<?>> items = ReflectionUtil.FieldUtil.getValue(packet, "b");
if (items.size() != 0) {
Item<?> item = items.get(0);
if (BYTE_DATA_WATCHER_OBJECT.equals(item.a())) {
Item<Byte> byteItem = (Item<Byte>) item;
byteItem.a((byte) (byteItem.b() | 1 << 5));
((CraftPlayer) getPlayer()).getHandle().setInvisible(true);
}
}
}
}
super.write(ctx, packet, promise);
}
};
channelHandlers.put(player.getUniqueId(), Pair.of(player1, handler));
player1.getHandle().playerConnection.networkManager.channel.pipeline().addBefore("packet_handler", hashCode() + ":" + player.getName(), handler);
}
use of net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment in project Citizens2 by CitizensDev.
the class EntityHumanNPC method updatePackets.
private void updatePackets(boolean navigating) {
updateCounter++;
boolean itemChanged = false;
for (EnumItemSlot slot : EnumItemSlot.values()) {
ItemStack equipment = getEquipment(slot);
ItemStack cache = equipmentCache.get(slot);
if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
itemChanged = true;
}
equipmentCache.put(slot, equipment);
}
if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
return;
updateCounter = 0;
Location current = getBukkitEntity().getLocation(packetLocationCache);
Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
int i = 0;
for (EnumItemSlot slot : EnumItemSlot.values()) {
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
}
NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Aggregations