Search in sources :

Example 6 with Item

use of net.minecraft.server.v1_16_R3.DataWatcher.Item in project CokesAddon by Cokes86.

the class v1_14_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);
}
Also used : Item(net.minecraft.server.v1_14_R1.DataWatcher.Item) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise)

Example 7 with Item

use of net.minecraft.server.v1_16_R3.DataWatcher.Item in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method setItems.

protected void setItems(List<org.bukkit.inventory.ItemStack> items) {
    int index = 0;
    for (org.bukkit.inventory.ItemStack item : items) {
        this.items.set(index++, CraftItemStack.asNMSCopy(item));
    }
    // Want to update the result without having to use a real player
    if (this.resultInventory instanceof InventoryCraftResult) {
        CustomContainerWorkbench container = new CustomContainerWorkbench(0, manager.mockPlayer.getBukkitEntity(), bloc, this, (InventoryCraftResult) resultInventory);
        container.a(this);
        CraftingInventory crafting = (CraftingInventory) container.getBukkitView().getTopInventory();
        Bukkit.getPluginManager().callEvent(new PrepareItemCraftEvent(crafting, container.getBukkitView(), false));
    }
    display.forceUpdate();
}
Also used : CraftingInventory(org.bukkit.inventory.CraftingInventory) PublicCraftingInventory(io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory) PrepareItemCraftEvent(org.bukkit.event.inventory.PrepareItemCraftEvent) InventoryCraftResult(net.minecraft.server.v1_16_R3.InventoryCraftResult)

Example 8 with Item

use of net.minecraft.server.v1_16_R3.DataWatcher.Item in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method setItem.

@Override
public void setItem(int index, ItemStack item) {
    // Instead of updating one container, update all the containers
    // That are looking at the table, basically the viewers
    items.set(index, item);
    for (Container container : containers) {
        container.a(this);
    }
    // Update the armorstand grid
    display.update();
}
Also used : Container(net.minecraft.server.v1_16_R3.Container) SelfContainer(io.github.bananapuncher714.crafters.implementation.v1_16_R3.ContainerManager_v1_16_R3.SelfContainer)

Example 9 with Item

use of net.minecraft.server.v1_16_R3.DataWatcher.Item in project MechanicsMain by WeaponMechanics.

the class NonNullList_1_16_R3 method set.

@Override
public ItemStack set(int index, ItemStack newItem) {
    ItemStack oldItem = get(index);
    Item item = (Item) ReflectionUtil.invokeField(itemField, newItem);
    if (newItem.getCount() == 0 && item != null) {
        newItem.setCount(1);
        consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
        newItem.setCount(0);
    } else if (!ItemStack.matches(oldItem, newItem)) {
        consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
    }
    return super.set(index, newItem);
}
Also used : Item(net.minecraft.server.v1_16_R3.Item) ItemStack(net.minecraft.server.v1_16_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

Example 10 with Item

use of net.minecraft.server.v1_16_R3.DataWatcher.Item in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method updateEntityNameTagForPlayer.

@Override
public void updateEntityNameTagForPlayer(Player player, org.bukkit.entity.Entity entity, String customName, boolean customNameVisible) {
    try {
        List<Item<?>> dataWatchers = new ArrayList<>();
        Optional<IChatBaseComponent> nameComponent = Optional.ofNullable(CraftChatMessage.fromStringOrNull(customName));
        dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.f.a(2), nameComponent));
        dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.i.a(3), customNameVisible));
        PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata();
        field_PacketPlayOutEntityMetadata_a.set(packetPlayOutEntityMetadata, entity.getEntityId());
        field_PacketPlayOutEntityMetadata_b.set(packetPlayOutEntityMetadata, dataWatchers);
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_16_R2.DataWatcher.Item) ArrayList(java.util.ArrayList) PacketPlayOutEntityMetadata(net.minecraft.server.v1_16_R2.PacketPlayOutEntityMetadata) IChatBaseComponent(net.minecraft.server.v1_16_R2.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) DataWatcher(net.minecraft.server.v1_16_R2.DataWatcher)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)10 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)8 ChannelPromise (io.netty.channel.ChannelPromise)8 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)6 ArrayList (java.util.ArrayList)3 ItemStack (net.minecraft.server.v1_16_R3.ItemStack)3 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)3 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)3 ItemStack (org.bukkit.inventory.ItemStack)3 CraftFakePlayerImpl (com.denizenscript.denizen.nms.v1_16.impl.entities.CraftFakePlayerImpl)2 EntityItemProjectileImpl (com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)2 ItemTag (com.denizenscript.denizen.objects.ItemTag)2 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)2 Mechanism (com.denizenscript.denizencore.objects.Mechanism)2 Nullable (javax.annotation.Nullable)2 Item (net.minecraft.server.v1_16_R2.DataWatcher.Item)2 Item (net.minecraft.server.v1_16_R3.DataWatcher.Item)2