Java Code Examples for net.minecraft.network.PacketByteBuf#readItemStack()

The following examples show how to use net.minecraft.network.PacketByteBuf#readItemStack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShapedCompressingRecipeSerializer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public T read(Identifier identifier_1, PacketByteBuf packet) {
    int int_1 = packet.readVarInt();
    int int_2 = packet.readVarInt();
    String group = packet.readString(32767);
    DefaultedList<Ingredient> defaultedList_1 = DefaultedList.ofSize(int_1 * int_2, Ingredient.EMPTY);

    for (int int_3 = 0; int_3 < defaultedList_1.size(); ++int_3) {
        defaultedList_1.set(int_3, Ingredient.fromPacket(packet));
    }

    ItemStack itemStack_1 = packet.readItemStack();
    return factory.create(identifier_1, group, int_1, int_2, defaultedList_1, itemStack_1);
}
 
Example 2
Source File: ShapelessCompressingRecipeSerializer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
    public T read(Identifier id, PacketByteBuf packet) {
//            String group = packet.readString(32767);
        int ingredientCount = packet.readVarInt();
        DefaultedList<Ingredient> ingredients = DefaultedList.ofSize(ingredientCount, Ingredient.EMPTY);

        for (int index = 0; index < ingredients.size(); ++index) {
            ingredients.set(index, Ingredient.fromPacket(packet));
        }

        ItemStack result = packet.readItemStack();
        return factory.create(id, /*group, */result, ingredients);
    }
 
Example 3
Source File: FabricationRecipeSerializer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public T read(Identifier id, PacketByteBuf packet) {
    String string_1 = packet.readString(32767);
    Ingredient ingredient_1 = Ingredient.fromPacket(packet);
    ItemStack itemStack_1 = packet.readItemStack();
    return this.recipeFactory.create(id, string_1, ingredient_1, itemStack_1);
}
 
Example 4
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER), cancellable = true)
private void onOnCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2) {
        Identifier channel = packet.getChannel();
        if (Protocol_1_13_2.CUSTOM_PAYLOAD_TRADE_LIST.equals(channel)) {
            PacketByteBuf buf = packet.getData();
            int syncId = buf.readInt();
            TraderOfferList trades = new TraderOfferList();
            int tradeCount = buf.readUnsignedByte();
            for (int i = 0; i < tradeCount; i++) {
                ItemStack buy = buf.readItemStack();
                ItemStack sell = buf.readItemStack();
                boolean hasSecondItem = buf.readBoolean();
                ItemStack secondBuy = hasSecondItem ? buf.readItemStack() : ItemStack.EMPTY;
                boolean locked = buf.readBoolean();
                int tradeUses = buf.readInt();
                int maxTradeUses = buf.readInt();
                TradeOffer trade = new TradeOffer(buy, secondBuy, sell, tradeUses, maxTradeUses, 0, 1);
                if (locked)
                    trade.clearUses();
                trades.add(trade);
            }
            onSetTradeOffers(new SetTradeOffersS2CPacket(syncId, trades, 5, 0, false, false));
            ci.cancel();
        } else if (Protocol_1_13_2.CUSTOM_PAYLOAD_OPEN_BOOK.equals(channel)) {
            OpenWrittenBookS2CPacket openBookPacket = new OpenWrittenBookS2CPacket();
            try {
                openBookPacket.read(packet.getData());
            } catch (IOException e) {
                LOGGER.error("Failed to read open book packet", e);
            }
            onOpenWrittenBook(openBookPacket);
            ci.cancel();
        }
    }
}