Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 88 additions & 1 deletion src/main/java/net/wurstclient/hacks/BookBotHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import java.util.Random;
import java.util.Set;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.server.network.Filterable;
import net.minecraft.world.item.component.WrittenBookContent;
import net.minecraft.network.protocol.game.ServerboundEditBookPacket;
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.wurstclient.Category;
Expand Down Expand Up @@ -78,6 +81,16 @@ private enum RandomType
private final CheckboxSetting sign =
new CheckboxSetting("Sign", "Whether to sign the book.", true);

private final CheckboxSetting dropAfterWrite =
new CheckboxSetting("Drop after write",
"Drops each finished book on the ground right after it's written.",
false);

private final CheckboxSetting autoCraft = new CheckboxSetting("Auto-craft",
"When you run out of book & quills, craft one from a book, a feather"
+ " and an ink sac in your inventory.",
false);

private final TextFieldSetting name = new TextFieldSetting("Name",
"The name you want to give your books.", "I Love Cevapi!");

Expand Down Expand Up @@ -119,6 +132,8 @@ public BookBotHack()
addSetting(randomType);
addSetting(delay);
addSetting(sign);
addSetting(dropAfterWrite);
addSetting(autoCraft);
addSetting(name);
addSetting(appendCount);
addSetting(wordWrap);
Expand Down Expand Up @@ -168,6 +183,9 @@ public void onUpdate()
int slot = findWritableBookSlot();
if(slot == -1)
{
if(autoCraft.isChecked() && tryCraftBookAndQuill())
return;

setEnabled(false);
return;
}
Expand Down Expand Up @@ -287,6 +305,54 @@ private void swapWithMainHand(int slot)
inventoryCooldown = 2;
}

private boolean tryCraftBookAndQuill()
{
if(MC.player == null)
return false;

if(MC.player.containerMenu != MC.player.inventoryMenu)
return false;

if(!MC.player.inventoryMenu.getCarried().isEmpty())
return false;

var im = IMC.getInteractionManager();

for(int gridSlot = 1; gridSlot <= 4; gridSlot++)
if(!MC.player.inventoryMenu.getSlot(gridSlot).getItem().isEmpty())
im.windowClick_QUICK_MOVE(gridSlot);

int bookSlot = InventoryUtils.indexOf(Items.BOOK, 36);
int featherSlot = InventoryUtils.indexOf(Items.FEATHER, 36);
int inkSlot = InventoryUtils.indexOf(Items.INK_SAC, 36);
if(bookSlot == -1 || featherSlot == -1 || inkSlot == -1)
return false;

placeStackInGrid(im, bookSlot, 1);
placeStackInGrid(im, featherSlot, 2);
placeStackInGrid(im, inkSlot, 3);

im.windowClick_PICKUP(0);

int freeSlot = MC.player.getInventory().getFreeSlot();
if(freeSlot != -1)
im.windowClick_PICKUP(InventoryUtils.toNetworkSlot(freeSlot));

for(int gridSlot = 1; gridSlot <= 3; gridSlot++)
im.windowClick_QUICK_MOVE(gridSlot);

inventoryCooldown = 2;
return true;
}

private void placeStackInGrid(
net.wurstclient.mixinterface.IMultiPlayerGameMode im, int inventorySlot,
int gridSlot)
{
im.windowClick_PICKUP(InventoryUtils.toNetworkSlot(inventorySlot));
im.windowClick_PICKUP(gridSlot);
}

private List<String> randomPages(PrimitiveIterator.OfInt chars)
{
ArrayList<String> outPages = new ArrayList<>();
Expand Down Expand Up @@ -422,7 +488,11 @@ private void writeBook(List<String> pages)
MC.player.getInventory().getSelectedSlot(), pages,
sign.isChecked() ? Optional.of(title) : Optional.empty()));

if(!sign.isChecked())
if(dropAfterWrite.isChecked())
{
dropMainHand();

}else if(!sign.isChecked())
{
int selectedSlot = MC.player.getInventory().getSelectedSlot();
unsignedWrittenSlots.add(selectedSlot);
Expand All @@ -439,6 +509,23 @@ private void writeBook(List<String> pages)
bookCount++;
}

private void dropMainHand()
{
if(MC.getConnection() == null)
return;

int selectedSlot = MC.player.getInventory().getSelectedSlot();

MC.getConnection()
.send(new ServerboundPlayerActionPacket(
ServerboundPlayerActionPacket.Action.DROP_ALL_ITEMS,
BlockPos.ZERO, Direction.DOWN));

MC.player.getInventory().setItem(selectedSlot, ItemStack.EMPTY);
unsignedWrittenSlots.remove(selectedSlot);
inventoryCooldown = 2;
}

private void logBookPayloadEstimate(List<String> pages, String title)
{
long totalJavaChars = 0;
Expand Down
Loading