net.minecraft.network.play.client.CPacketCustomPayload Java Examples

The following examples show how to use net.minecraft.network.play.client.CPacketCustomPayload. 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: PayloadSpoofer.java    From ForgeHax with MIT License 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onOutgoingPacket(PacketEvent.Outgoing.Pre event) {
  String channel;
  ByteBuf packetBuffer;
  final Packet packet = event.getPacket();
  
  if (packet instanceof CPacketCustomPayload || packet instanceof FMLProxyPacket) {
    if (packet instanceof CPacketCustomPayload) {
      channel = ((CPacketCustomPayload) packet).getChannelName();
      packetBuffer = ((CPacketCustomPayload) packet).getBufferData();
    } else {
      channel = ((FMLProxyPacket) packet).channel();
      packetBuffer = ((FMLProxyPacket) packet).payload();
    }
    
    if (isBlockedPacket(channel, packetBuffer)) {
      event.setCanceled(true);
    }
  }
}
 
Example #2
Source File: BookBot.java    From ForgeHax with MIT License 6 votes vote down vote up
private void sendBook(ItemStack stack) {
  NBTTagList pages = new NBTTagList(); // page tag list
  
  // copy pages into NBT
  for (int i = 0; i < MAX_PAGES && parser.hasNext(); i++) {
    pages.appendTag(new NBTTagString(parser.next().trim()));
    page++;
  }
  
  // set our client side book
  if (stack.hasTagCompound()) {
    stack.getTagCompound().setTag("pages", pages);
  } else {
    stack.setTagInfo("pages", pages);
  }
  
  // publish the book
  stack.setTagInfo("author", new NBTTagString(getLocalPlayer().getName()));
  stack.setTagInfo(
      "title",
      new NBTTagString(parent.name.get().replaceAll(NUMBER_TOKEN, "" + getBook()).trim()));
  
  PacketBuffer buff = new PacketBuffer(Unpooled.buffer());
  buff.writeItemStack(stack);
  MC.getConnection().sendPacket(new CPacketCustomPayload("MC|BSign", buff));
}
 
Example #3
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 #4
Source File: NoHandShakeModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void sendPacket(EventSendPacket event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        if (event.getPacket() instanceof FMLProxyPacket && !Minecraft.getMinecraft().isSingleplayer()) {
            event.setCanceled(true);
        }
        if (event.getPacket() instanceof CPacketCustomPayload) {
            final CPacketCustomPayload packet = (CPacketCustomPayload) event.getPacket();
            if(packet.getChannelName().equals("MC|Brand")) {
                packet.data = new PacketBuffer(Unpooled.buffer()).writeString("vanilla");
            }
        }
    }
}