Skip to content

Commit ddedb27

Browse files
committed
Update to mc1.21.3
1 parent e58ca17 commit ddedb27

14 files changed

+96
-196
lines changed

common/src/main/java/dev/terminalmc/moremousetweaks/MoreMouseTweaks.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public static void setInteractionManagerTickRate(Config.Options options) {
5959

6060
public static void updateItemTags(Config.Options options) {
6161
options.typeMatchItemCache.clear();
62-
BuiltInRegistries.ITEM.getTags().forEach((pair) -> {
63-
if (options.typeMatchTags.contains(pair.getFirst().location().getPath())) {
64-
pair.getSecond().forEach((itemHolder) ->
65-
options.typeMatchItemCache.add(itemHolder.value()));
62+
BuiltInRegistries.ITEM.getTags().forEach((named) -> {
63+
if (options.typeMatchTags.contains(named.key().location().getPath())) {
64+
named.forEach((itemHolder) -> options.typeMatchItemCache.add(itemHolder.value()));
6665
}
6766
});
6867
}
68+
6969
}

common/src/main/java/dev/terminalmc/moremousetweaks/inventory/screen/ContainerScreenHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import dev.terminalmc.moremousetweaks.util.inject.ISlot;
2222
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
2323
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
24-
import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen;
2524
import net.minecraft.world.entity.player.Inventory;
2625
import net.minecraft.world.inventory.Slot;
2726

@@ -79,7 +78,7 @@ public boolean isExtraSlot(Slot slot) {
7978
*/
8079
public Scope getScope(Slot slot) {
8180
// Screen with only player inventory
82-
if (screen instanceof EffectRenderingInventoryScreen) {
81+
if (screen instanceof AbstractContainerScreen<?>) {
8382
// Player inventory
8483
if (slot.container instanceof Inventory) {
8584
boolean mergeWithHotbar = false;

common/src/main/java/dev/terminalmc/moremousetweaks/mixin/event/ClientPacketListenerMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import net.minecraft.client.multiplayer.ClientPacketListener;
2323
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
2424
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
25-
import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket;
25+
import net.minecraft.network.protocol.game.ClientboundSetCursorItemPacket;
2626
import org.spongepowered.asm.mixin.Mixin;
2727
import org.spongepowered.asm.mixin.injection.At;
2828
import org.spongepowered.asm.mixin.injection.Inject;
@@ -46,10 +46,10 @@ private void afterLogin(ClientboundLoginPacket packet, CallbackInfo ci) {
4646
}
4747

4848
@Inject(
49-
method = "handleSetCarriedItem",
49+
method = "handleSetCursorItem",
5050
at = @At("HEAD")
5151
)
52-
public void beforeHeldItemChange(ClientboundSetCarriedItemPacket packet, CallbackInfo ci) {
52+
public void beforeHeldItemChange(ClientboundSetCursorItemPacket packet, CallbackInfo ci) {
5353
InteractionManager.triggerSend(InteractionManager.TriggerType.HELD_ITEM_CHANGE);
5454
}
5555

common/src/main/java/dev/terminalmc/moremousetweaks/mixin/quick/craft/RecipeBookComponentMixin.java

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package dev.terminalmc.moremousetweaks.mixin.quick.craft;
1919

20-
import dev.terminalmc.moremousetweaks.MoreMouseTweaks;
2120
import dev.terminalmc.moremousetweaks.inventory.helper.InteractionHelper;
2221
import dev.terminalmc.moremousetweaks.network.InteractionManager;
2322
import dev.terminalmc.moremousetweaks.util.InputUtil;
@@ -27,10 +26,11 @@
2726
import net.minecraft.client.gui.screens.recipebook.RecipeBookPage;
2827
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
2928
import net.minecraft.network.protocol.game.ServerboundPlaceRecipePacket;
30-
import net.minecraft.world.entity.player.StackedContents;
29+
import net.minecraft.world.inventory.AbstractCraftingMenu;
30+
import net.minecraft.world.inventory.AbstractFurnaceMenu;
3131
import net.minecraft.world.inventory.RecipeBookMenu;
3232
import net.minecraft.world.inventory.Slot;
33-
import net.minecraft.world.item.crafting.RecipeHolder;
33+
import net.minecraft.world.item.crafting.display.RecipeDisplayId;
3434
import org.spongepowered.asm.mixin.Final;
3535
import org.spongepowered.asm.mixin.Mixin;
3636
import org.spongepowered.asm.mixin.Shadow;
@@ -41,6 +41,8 @@
4141
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
4242
import yalter.mousetweaks.MouseButton;
4343

44+
import java.util.Collection;
45+
import java.util.List;
4446
import java.util.concurrent.atomic.AtomicBoolean;
4547

4648
import static dev.terminalmc.moremousetweaks.config.Config.options;
@@ -81,10 +83,7 @@ public abstract class RecipeBookComponentMixin {
8183

8284
@Shadow
8385
@Final
84-
private StackedContents stackedContents;
85-
86-
@Shadow
87-
protected RecipeBookMenu<?, ?> menu;
86+
protected RecipeBookMenu menu;
8887

8988
/**
9089
* Quick-crafting via RMB click.
@@ -93,7 +92,7 @@ public abstract class RecipeBookComponentMixin {
9392
method = "mouseClicked",
9493
at = @At(
9594
value = "INVOKE",
96-
target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;handlePlaceRecipe(ILnet/minecraft/world/item/crafting/RecipeHolder;Z)V",
95+
target = "Lnet/minecraft/client/gui/screens/recipebook/RecipeBookComponent;isOffsetNextToMainGUI()Z",
9796
shift = Shift.AFTER
9897
)
9998
)
@@ -106,7 +105,7 @@ public void mouseClicked(
106105
if (!options().useQuickCrafting || mouseButton != MouseButton.RIGHT.getValue())
107106
return;
108107

109-
int resultSlotId = menu.getResultSlotIndex();
108+
int resultSlotId = mmt$getResultSlotIndex(menu);
110109
if (Screen.hasShiftDown() && InputUtil.isMatchingSlotsKeyDown()) {
111110
mmt$bulkQuickCraft(resultSlotId, false);
112111
} else {
@@ -150,12 +149,12 @@ public void keyPressed(
150149
if (!clickSuccess)
151150
return;
152151

153-
RecipeHolder<?> recipe = recipeBookPage.getLastClickedRecipe();
152+
RecipeDisplayId recipe = recipeBookPage.getLastClickedRecipe();
154153
RecipeCollection collection = recipeBookPage.getLastClickedRecipeCollection();
155154
if (recipe == null || collection == null)
156155
return;
157156

158-
int resultSlotId = menu.getResultSlotIndex();
157+
int resultSlotId = mmt$getResultSlotIndex(menu);
159158

160159
// Select the recipe
161160
InteractionManager.pushPacketEvent(
@@ -171,7 +170,7 @@ public void keyPressed(
171170
mmt$bulkQuickCraft(resultSlotId, true);
172171
} else {
173172
if (Screen.hasShiftDown()) {
174-
mmt$dropAll(recipe, resultSlotId);
173+
mmt$dropAll(resultSlotId);
175174
} else {
176175
InteractionHelper.drop(menu.containerId, resultSlotId);
177176
}
@@ -189,7 +188,7 @@ public void keyPressed(
189188
*/
190189
@Unique
191190
private void mmt$bulkQuickCraft(int resultSlotId, boolean drop) {
192-
RecipeHolder<?> recipe = recipeBookPage.getLastClickedRecipe();
191+
RecipeDisplayId recipe = recipeBookPage.getLastClickedRecipe();
193192
RecipeCollection collection = recipeBookPage.getLastClickedRecipeCollection();
194193
if (recipe == null || collection == null)
195194
return;
@@ -223,12 +222,12 @@ public void keyPressed(
223222
InteractionManager.clear();
224223
return false;
225224
}
226-
return MoreMouseTweaks.lastUpdatedSlot >= menu.getSize();
225+
return true;
227226
}
228227
);
229228
// Shift-click or drop the result slot
230229
if (drop) {
231-
mmt$dropAll(recipe, resultSlotId);
230+
mmt$dropAll(resultSlotId);
232231
} else {
233232
InteractionHelper.quickMove(menu.containerId, resultSlotId);
234233
}
@@ -265,14 +264,37 @@ public void keyPressed(
265264
}
266265

267266
@Unique
268-
private void mmt$dropAll(RecipeHolder<?> recipe, int resSlot) {
269-
int maxOps = stackedContents.getBiggestCraftableStack(
270-
recipe,
271-
recipe.value().getResultItem(minecraft.level.registryAccess()).getMaxStackSize(),
272-
null
273-
);
267+
private void mmt$dropAll(int resSlot) {
268+
int maxOps = mmt$getBiggestCraftingStackSize();
274269
for (int i = 0; i < maxOps; i++) {
275270
InteractionHelper.drop(menu.containerId, resSlot);
276271
}
277272
}
273+
274+
@Unique
275+
private int mmt$getResultSlotIndex(RecipeBookMenu menu) {
276+
return switch (menu) {
277+
case AbstractCraftingMenu m -> m.getResultSlot().index;
278+
case AbstractFurnaceMenu m -> m.getResultSlot().index;
279+
default -> 0;
280+
};
281+
}
282+
283+
@Unique
284+
public Collection<Slot> mmt$getInputSlots() {
285+
if (menu instanceof AbstractCraftingMenu m) {
286+
return m.getInputGridSlots();
287+
} else {
288+
return List.of();
289+
}
290+
}
291+
292+
@Unique
293+
private int mmt$getBiggestCraftingStackSize() {
294+
int max = 0;
295+
for (Slot slot : mmt$getInputSlots()) {
296+
max = Math.max(max, slot.getItem().getCount());
297+
}
298+
return max;
299+
}
278300
}

common/src/main/java/dev/terminalmc/moremousetweaks/mixin/quick/craft/helper/OverlayRecipeComponentMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package dev.terminalmc.moremousetweaks.mixin.quick.craft.helper;
1919

2020
import net.minecraft.client.gui.screens.recipebook.OverlayRecipeComponent;
21-
import net.minecraft.world.item.crafting.RecipeHolder;
21+
import net.minecraft.world.item.crafting.display.RecipeDisplayId;
2222
import org.spongepowered.asm.mixin.Final;
2323
import org.spongepowered.asm.mixin.Mixin;
2424
import org.spongepowered.asm.mixin.Shadow;
@@ -43,7 +43,7 @@ public class OverlayRecipeComponentMixin {
4343
private List<OverlayRecipeComponent.OverlayRecipeButton> recipeButtons;
4444

4545
@Shadow
46-
private RecipeHolder<?> lastRecipeClicked;
46+
private RecipeDisplayId lastRecipeClicked;
4747

4848
@Inject(
4949
method = "mouseClicked",

common/src/main/java/dev/terminalmc/moremousetweaks/mixin/quick/craft/helper/RecipeBookPageMixin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import net.minecraft.client.gui.screens.recipebook.RecipeBookPage;
2323
import net.minecraft.client.gui.screens.recipebook.RecipeButton;
2424
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
25-
import net.minecraft.world.item.crafting.RecipeHolder;
25+
import net.minecraft.world.item.crafting.display.RecipeDisplayId;
2626
import org.spongepowered.asm.mixin.Mixin;
2727
import org.spongepowered.asm.mixin.Shadow;
2828
import org.spongepowered.asm.mixin.injection.At;
@@ -50,7 +50,7 @@ public abstract class RecipeBookPageMixin implements IRecipeBookResults {
5050
protected abstract void updateButtonsForPage();
5151

5252
@Shadow
53-
private RecipeHolder<?> lastClickedRecipe;
53+
private RecipeDisplayId lastClickedRecipe;
5454

5555
@Shadow
5656
private RecipeCollection lastClickedRecipeCollection;
@@ -92,7 +92,7 @@ public void mouseClicked(
9292
int areaWidth,
9393
int areaHeight,
9494
CallbackInfoReturnable<Boolean> cir,
95-
Iterator<?> iterator,
95+
@Local Iterator<?> iterator,
9696
@Local RecipeButton recipeButton
9797
) {
9898
if (!options().useQuickCrafting || button != MouseButton.RIGHT.getValue())
@@ -101,7 +101,7 @@ public void mouseClicked(
101101
return;
102102

103103
// Quick-craft
104-
lastClickedRecipe = recipeButton.getRecipe();
104+
lastClickedRecipe = recipeButton.getCurrentRecipe();
105105
lastClickedRecipeCollection = recipeButton.getCollection();
106106
}
107107
}

common/src/main/java/dev/terminalmc/moremousetweaks/mixin/scroll/inject/AbstractFurnaceScreenMixin.java

Lines changed: 0 additions & 64 deletions
This file was deleted.

common/src/main/java/dev/terminalmc/moremousetweaks/mixin/scroll/inject/InventoryScreenMixin.java renamed to common/src/main/java/dev/terminalmc/moremousetweaks/mixin/scroll/inject/AbstractRecipeBookScreenMixin.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,29 @@
2020
import dev.terminalmc.moremousetweaks.inventory.util.ScrollAction;
2121
import dev.terminalmc.moremousetweaks.util.inject.IRecipeBookWidget;
2222
import dev.terminalmc.moremousetweaks.util.inject.IScrollableRecipeBook;
23-
import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen;
24-
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
23+
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
24+
import net.minecraft.client.gui.screens.inventory.AbstractRecipeBookScreen;
2525
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
2626
import net.minecraft.network.chat.Component;
2727
import net.minecraft.world.entity.player.Inventory;
2828
import net.minecraft.world.inventory.InventoryMenu;
29+
import net.minecraft.world.inventory.RecipeBookMenu;
2930
import org.spongepowered.asm.mixin.Final;
3031
import org.spongepowered.asm.mixin.Mixin;
3132
import org.spongepowered.asm.mixin.Shadow;
3233

3334
/**
3435
* Recipe book scrolling helper for inventory screens.
3536
*/
36-
@Mixin(InventoryScreen.class)
37-
public abstract class InventoryScreenMixin extends EffectRenderingInventoryScreen<InventoryMenu>
37+
@Mixin(AbstractRecipeBookScreen.class)
38+
public abstract class AbstractRecipeBookScreenMixin extends AbstractContainerScreen<RecipeBookMenu>
3839
implements IScrollableRecipeBook {
3940

4041
@Shadow
4142
@Final
42-
private RecipeBookComponent recipeBookComponent;
43+
private RecipeBookComponent<?> recipeBookComponent;
4344

44-
public InventoryScreenMixin(
45+
public AbstractRecipeBookScreenMixin(
4546
InventoryMenu container,
4647
Inventory playerInventory,
4748
Component text

0 commit comments

Comments
 (0)