Skip to content

Commit

Permalink
Change book clone ID to be dynamic, rename boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
YHDiamond committed Jul 9, 2024
1 parent 2e34160 commit 9ff6c7d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ public final class ClickPlan {
/**
* The recipe for cloning books requires special handling, this dictates whether that handling should be performed
*/
private final boolean cloneBookRecipe;
private final boolean handleBookCloneRecipe;

public ClickPlan(GeyserSession session, InventoryTranslator translator, Inventory inventory) {
this(session, translator, inventory, false);
}

public ClickPlan(GeyserSession session, InventoryTranslator translator, Inventory inventory, boolean cloneBookRecipe) {
public ClickPlan(GeyserSession session, InventoryTranslator translator, Inventory inventory, boolean handleBookCloneRecipe) {
this.session = session;
this.translator = translator;
this.inventory = inventory;
this.cloneBookRecipe = cloneBookRecipe;
this.handleBookCloneRecipe = handleBookCloneRecipe;

this.simulatedItems = new Int2ObjectOpenHashMap<>(inventory.getSize());
this.changedItems = null;
Expand Down Expand Up @@ -386,7 +386,7 @@ private void reduceCraftingGrid(boolean makeAll) {
for (int i = 0; i < gridSize; i++) {
final int slot = i + 1;
GeyserItemStack item = getItem(slot);
if (!item.isEmpty() && item.asItem() == Items.WRITTEN_BOOK) {
if (!item.isEmpty() && (!handleBookCloneRecipe || item.asItem() == Items.WRITTEN_BOOK)) {
// These changes should be broadcasted to the server
sub(slot, item, crafted);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Setter
private Int2ObjectMap<GeyserStonecutterData> stonecutterRecipes;

/**
* Saves the ID for cloning books through the crafting table, as these need different handling
*/
@Setter
private int bookCloningID;


/**
* Whether to work around 1.13's different behavior in villager trading menus.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public ItemStackResponse translateCraftingRequest(GeyserSession session, Invento
}
craftState = CraftState.RECIPE_ID;

if (((RecipeItemStackRequestAction) action).getRecipeNetworkId() == InventoryUtils.BOOK_CLONING_RECIPE_ID) {
if (((RecipeItemStackRequestAction) action).getRecipeNetworkId() == session.getBookCloningID()) {
// Book copying needs to be handled differently
// The original written book is leftover in the crafting grid
return translateBookCopyCraftingRequest(session, inventory, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ public void translate(GeyserSession session, ClientboundUpdateRecipesPacket pack
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("685a742a-c42e-4a4e-88ea-5eb83fc98e5b"), context.getAndIncrementNetId()));
}
case CRAFTING_SPECIAL_BOOKCLONING -> {
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("d1ca6b84-338e-4f2f-9c6b-76cc8b4bd98d"), context.getAndIncrementNetId()));
int bookCloningID = context.getAndIncrementNetId();
session.setBookCloningID(bookCloningID);
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("d1ca6b84-338e-4f2f-9c6b-76cc8b4bd98d"), bookCloningID));
}
case CRAFTING_SPECIAL_REPAIRITEM -> {
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("00000000-0000-0000-0000-000000000001"), context.getAndIncrementNetId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ public class InventoryUtils {
* each recipe needs a unique network ID (or else in .200 the client crashes).
*/
public static int LAST_RECIPE_NET_ID;
/**
* Book cloning recipe ID; stored separately as its recipe works differently from others.
*/
public static final int BOOK_CLONING_RECIPE_ID = 278;

public static final ItemStack REFRESH_ITEM = new ItemStack(1, 127, new DataComponents(new HashMap<>()));

Expand Down

0 comments on commit 9ff6c7d

Please sign in to comment.