Skip to content

Commit

Permalink
Fix the ghost recipe rendering issue as client receiving crafting fai…
Browse files Browse the repository at this point in the history
…l packets
  • Loading branch information
wendavid552 committed Aug 15, 2024
1 parent cf83cca commit e9f30fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void onClientTick(MinecraftClient mc)

if (Configs.Generic.MASS_CRAFT_RECIPE_BOOK.getBooleanValue() && recipe.lookupVanillaRecipe(mc.world) != null)
{
InventoryUtils.dontUpdateRecipeBook = 10;
InventoryUtils.dontUpdateRecipeBook = 2;
for (int i = 0; i < limit; ++i)
{
// todo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package fi.dy.masa.itemscroller.mixin;

import fi.dy.masa.itemscroller.util.InventoryUtils;
import net.minecraft.client.gui.screen.recipebook.RecipeBookGhostSlots;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.screen.slot.Slot;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(RecipeBookWidget.class)
public class MixinRecipeBookWidget
{
@Shadow @Final protected RecipeBookGhostSlots ghostSlots;

@Inject(method = "slotClicked", at = @At("HEAD"), cancellable = true)
private void onSlotClicked(Slot slot, CallbackInfo ci)
{
Expand All @@ -29,13 +37,15 @@ private void onUpdate(CallbackInfo ci)
}
}

@Inject(method = "drawGhostSlots", at = @At("HEAD"), cancellable = true)
private void onDrawGhostSlots(CallbackInfo ci)
{
if (InventoryUtils.dontUpdateRecipeBook > 0)
{
// Seems to be (intended) bug from Mojang
@Inject(
method = "showGhostRecipe",
at = @At("HEAD"),
cancellable = true
)
private void onShowGhostRecipe(RecipeEntry<?> recipe, List<Slot> slots, CallbackInfo ci) {
if (this.ghostSlots.getRecipe() == recipe) {
ci.cancel();
}
}

}

0 comments on commit e9f30fc

Please sign in to comment.