diff --git a/.giup b/.giup index faa64295..607f0082 100644 --- a/.giup +++ b/.giup @@ -2,7 +2,7 @@ "merge-paths": [ "1.16", "1.16->1.15->1.14", - "1.16->1.17->1.18" + "1.16->1.17->1.18->unstable" ], "commands": [ { diff --git a/gradle.properties b/gradle.properties index 6ad3be35..5a72fe2b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_build=17:v2 loader_version=0.9.0+build.204 # Mod Properties mod_id=mousewheelie -mod_version=1.8.0 +mod_version=1.8.1 mod_release=release mod_mc_version_specifier=1.15.x mod_mc_versions=1.15;1.15.1;1.15.2 diff --git a/src/main/java/de/siphalor/mousewheelie/MWConfig.java b/src/main/java/de/siphalor/mousewheelie/MWConfig.java index c8b9443f..aaf9cef3 100644 --- a/src/main/java/de/siphalor/mousewheelie/MWConfig.java +++ b/src/main/java/de/siphalor/mousewheelie/MWConfig.java @@ -43,6 +43,12 @@ public static class General { ) public int interactionRate = 10; + @AConfigEntry(environment = ConfigEnvironment.UNIVERSAL, comment = "Enables using armor/elytra items to swap them with the currently equipped item.") + public boolean enableQuickArmorSwapping = true; + + @AConfigEntry(comment = "Enables dropping items when pressing alt and clicking on them.") + public boolean enableAltDropping = true; + @AConfigEntry(comment = "Enables right-clicking in recipe books/villager trading to swiftly craft/trade.") public boolean enableQuickCraft = true; diff --git a/src/main/java/de/siphalor/mousewheelie/MouseWheelie.java b/src/main/java/de/siphalor/mousewheelie/MouseWheelie.java index 0471394f..047420a0 100644 --- a/src/main/java/de/siphalor/mousewheelie/MouseWheelie.java +++ b/src/main/java/de/siphalor/mousewheelie/MouseWheelie.java @@ -31,7 +31,7 @@ public class MouseWheelie implements ModInitializer { public void onInitialize() { UseItemCallback.EVENT.register((player, world, hand) -> { ItemStack stack = player.getStackInHand(hand); - if (!world.isClient()) { + if (MWConfig.general.enableQuickArmorSwapping && !world.isClient()) { EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(stack); if (equipmentSlot.getType() == EquipmentSlot.Type.ARMOR) { ItemStack equipmentStack = player.getEquippedStack(equipmentSlot); diff --git a/src/main/java/de/siphalor/mousewheelie/client/inventory/ContainerScreenHelper.java b/src/main/java/de/siphalor/mousewheelie/client/inventory/ContainerScreenHelper.java index df316a66..b4d20075 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/inventory/ContainerScreenHelper.java +++ b/src/main/java/de/siphalor/mousewheelie/client/inventory/ContainerScreenHelper.java @@ -38,7 +38,7 @@ public class ContainerScreenHelper> { protected final T screen; protected final ClickHandler clickHandler; - public static int INVALID_SCOPE = Integer.MAX_VALUE; + public static final int INVALID_SCOPE = Integer.MAX_VALUE; protected ContainerScreenHelper(T screen, ClickHandler clickHandler) { this.screen = screen; @@ -187,7 +187,6 @@ public void dropAllOfAKind(Slot referenceSlot) { } public void dropAllFrom(Slot referenceSlot) { - ItemStack referenceStack = referenceSlot.getStack().copy(); runInScope(getScope(referenceSlot), this::dropStack); } diff --git a/src/main/java/de/siphalor/mousewheelie/client/inventory/SlotRefiller.java b/src/main/java/de/siphalor/mousewheelie/client/inventory/SlotRefiller.java index b51704cb..90bb6138 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/inventory/SlotRefiller.java +++ b/src/main/java/de/siphalor/mousewheelie/client/inventory/SlotRefiller.java @@ -32,9 +32,10 @@ import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket; import net.minecraft.util.DefaultedList; +import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.concurrent.ConcurrentLinkedDeque; -import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Function; @SuppressWarnings("unused") @@ -135,39 +136,7 @@ boolean matches(ItemStack oldStack) { @Override int findMatchingStack(PlayerInventory playerInventory, ItemStack oldStack) { - int currentRank = 0; - ConcurrentLinkedQueue> classes = new ConcurrentLinkedQueue<>(); - Class clazz = oldStack.getItem().getClass(); - while (clazz != Item.class) { - classes.add(clazz); - clazz = clazz.getSuperclass(); - } - int classesSize = classes.size(); - if (classesSize == 0) - return -1; - - int index = -1; - - DefaultedList mainInv = playerInventory.main; - outer: - for (int i = 0; i < mainInv.size(); i++) { - clazz = mainInv.get(i).getItem().getClass(); - while (clazz != Item.class) { - int classRank = classesSize; - for (Iterator> iterator = classes.iterator(); iterator.hasNext(); classRank--) { - if (classRank <= 0) break; - if (classRank <= currentRank) continue outer; - if (clazz.equals(iterator.next())) { - if (classRank >= classesSize) return i; - currentRank = classRank; - index = i; - continue outer; - } - } - clazz = clazz.getSuperclass(); - } - } - return index; + return findBestThroughClassHierarchy(oldStack, playerInventory.main, Item::getClass, Item.class); } } @@ -179,41 +148,52 @@ boolean matches(ItemStack oldStack) { @Override int findMatchingStack(PlayerInventory playerInventory, ItemStack oldStack) { - int currentRank = 0; - ConcurrentLinkedQueue> classes = new ConcurrentLinkedQueue<>(); - Class clazz = ((BlockItem) oldStack.getItem()).getBlock().getClass(); - while (clazz != Block.class) { - classes.add(clazz); - clazz = clazz.getSuperclass(); + return findBestThroughClassHierarchy(oldStack, playerInventory.main, item -> { + if (item instanceof BlockItem) { + return ((BlockItem) item).getBlock().getClass(); + } else { + return null; + } + }, Block.class); + } + } + + private static int findBestThroughClassHierarchy(ItemStack baseStack, DefaultedList inventory, Function> getClass, Class baseClass) { + int currentRank = 0; + Collection> classes = new ArrayList<>(10); + Class clazz = getClass.apply(baseStack.getItem()); + while (clazz != baseClass) { + classes.add(clazz); + clazz = clazz.getSuperclass(); + } + int classesSize = classes.size(); + if (classesSize == 0) + return -1; + + int index = -1; + + outer: + for (int i = 0; i < inventory.size(); i++) { + clazz = getClass.apply(inventory.get(i).getItem()); + if (clazz == null) { + continue; } - int classesSize = classes.size(); - if (classesSize == 0) - return -1; - - int index = -1; - DefaultedList mainInv = playerInventory.main; - - outer: - for (int i = 0; i < mainInv.size(); i++) { - if (!(mainInv.get(i).getItem() instanceof BlockItem)) continue; - clazz = ((BlockItem) mainInv.get(i).getItem()).getBlock().getClass(); - while (clazz != Block.class) { - int classRank = classesSize; - for (Iterator> iterator = classes.iterator(); iterator.hasNext(); classRank--) { - if (classRank <= 0) break; - if (classRank <= currentRank) continue outer; - if (clazz.equals(iterator.next())) { - if (classRank >= classesSize) return i; - currentRank = classRank; - index = i; - continue outer; - } + while (clazz != baseClass) { + int classRank = classesSize; + for (Iterator> iterator = classes.iterator(); iterator.hasNext(); classRank--) { + if (classRank <= 0) break; + if (classRank <= currentRank) continue outer; + if (clazz.equals(iterator.next())) { + if (classRank >= classesSize) return i; + currentRank = classRank; + index = i; + continue outer; } - clazz = clazz.getSuperclass(); } + clazz = clazz.getSuperclass(); } - return index; } + return index; } public static class FoodRule extends Rule { diff --git a/src/main/java/de/siphalor/mousewheelie/client/inventory/ToolPicker.java b/src/main/java/de/siphalor/mousewheelie/client/inventory/ToolPicker.java index d89b16ea..4f31e192 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/inventory/ToolPicker.java +++ b/src/main/java/de/siphalor/mousewheelie/client/inventory/ToolPicker.java @@ -29,7 +29,7 @@ @Environment(EnvType.CLIENT) public class ToolPicker { - PlayerInventory inventory; + final PlayerInventory inventory; static int lastToolPickSlot = -1; @@ -55,7 +55,7 @@ public int findToolFor(BlockState blockState) { } } } - if (bestBreakSpeed == -1) { + if (bestSpeedSlot == -1) { ItemStack stack = inventory.main.get(inventory.selectedSlot); if (stack.isEffectiveOn(blockState) || stack.getMiningSpeed(blockState) > 1.0F) return inventory.selectedSlot; diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/gui/other/MixinRecipeBookWidget.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/gui/other/MixinRecipeBookWidget.java index a6a4f51b..7f77fda7 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/gui/other/MixinRecipeBookWidget.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/gui/other/MixinRecipeBookWidget.java @@ -51,7 +51,8 @@ @Mixin(RecipeBookWidget.class) public abstract class MixinRecipeBookWidget implements IRecipeBookWidget { - @Shadow @Final protected RecipeBookResults recipesArea; + @Shadow @Final + private RecipeBookResults recipesArea; @Shadow private int parentWidth; @@ -77,7 +78,7 @@ public abstract class MixinRecipeBookWidget implements IRecipeBookWidget { @Shadow @Final - protected RecipeFinder recipeFinder; + private RecipeFinder recipeFinder; @Shadow protected CraftingContainer craftingContainer; diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/gui/screen/MixinAbstractContainerScreen.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/gui/screen/MixinAbstractContainerScreen.java index 3ee70cb4..b3cd53ed 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/gui/screen/MixinAbstractContainerScreen.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/gui/screen/MixinAbstractContainerScreen.java @@ -18,7 +18,6 @@ package de.siphalor.mousewheelie.client.mixin.gui.screen; import de.siphalor.mousewheelie.MWConfig; -import de.siphalor.mousewheelie.client.MWClient; import de.siphalor.mousewheelie.client.inventory.ContainerScreenHelper; import de.siphalor.mousewheelie.client.inventory.sort.InventorySorter; import de.siphalor.mousewheelie.client.inventory.sort.SortMode; @@ -36,6 +35,7 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.text.Text; import net.minecraft.util.Lazy; +import org.lwjgl.glfw.GLFW; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -79,7 +79,7 @@ public void onMouseDragged(double x2, double y2, int button, double x1, double y if (button == 0) { Slot hoveredSlot = getSlotAt(x2, y2); if (hoveredSlot != null) { - if (hasAltDown()) { + if (MWConfig.general.enableAltDropping && hasAltDown()) { onMouseClick(hoveredSlot, hoveredSlot.id, 1, SlotActionType.THROW); } else if (hasShiftDown()) { screenHelper.get().sendStack(hoveredSlot); @@ -93,7 +93,7 @@ public void onMouseDragged(double x2, double y2, int button, double x1, double y @Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true) public void onMouseClick(double x, double y, int button, CallbackInfoReturnable callbackInfoReturnable) { if (button == 0) { - if (hasAltDown()) { + if (MWConfig.general.enableAltDropping && hasAltDown()) { Slot hoveredSlot = getSlotAt(x, y); if (hoveredSlot != null) { if (hasControlDown()) { @@ -158,7 +158,9 @@ public ScrollAction mouseWheelie_onMouseScroll(double mouseX, double mouseY, dou public boolean mouseWheelie_triggerSort() { if (focusedSlot == null) return false; - if (playerInventory.player.abilities.creativeMode && MWClient.SORT_KEY_BINDING.isDefault() && (!focusedSlot.getStack().isEmpty() == playerInventory.getCursorStack().isEmpty())) + if (playerInventory.player.abilities.creativeMode + && GLFW.glfwGetMouseButton(minecraft.getWindow().getHandle(), GLFW.GLFW_MOUSE_BUTTON_MIDDLE) != 0 + && (!focusedSlot.getStack().isEmpty() == playerInventory.getCursorStack().isEmpty())) return false; InventorySorter sorter = new InventorySorter((ContainerScreen) (Object) this, focusedSlot); SortMode sortMode; diff --git a/src/main/java/de/siphalor/mousewheelie/client/network/InteractionManager.java b/src/main/java/de/siphalor/mousewheelie/client/network/InteractionManager.java index 187cb993..97a309aa 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/network/InteractionManager.java +++ b/src/main/java/de/siphalor/mousewheelie/client/network/InteractionManager.java @@ -144,10 +144,6 @@ public static class ClickEvent implements InteractionEvent { private final SlotActionType slotAction; public ClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction) { - this(containerSyncId, slotId, buttonId, slotAction, 1); - } - - public ClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction, int awaitedTriggers) { this(containerSyncId, slotId, buttonId, slotAction, TICK_WAITER); } diff --git a/src/main/java/de/siphalor/mousewheelie/client/util/ScrollAction.java b/src/main/java/de/siphalor/mousewheelie/client/util/ScrollAction.java index 3bdfca6b..19033dc8 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/util/ScrollAction.java +++ b/src/main/java/de/siphalor/mousewheelie/client/util/ScrollAction.java @@ -1,37 +1,37 @@ -/* - * Copyright 2021 Siphalor - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. - * See the License for the specific language governing - * permissions and limitations under the License. - */ - -package de.siphalor.mousewheelie.client.util; - -public enum ScrollAction { - PASS(false, false), SUCCESS(true, true), FAILURE(false, true), ABORT(true, false); - boolean cancelCustomActions; - boolean cancelAllActions; - - ScrollAction(boolean cancelCustomActions, boolean cancelAllActions) { - this.cancelCustomActions = cancelCustomActions; - this.cancelAllActions = cancelAllActions; - } - - public boolean cancelsAllActions() { - return cancelAllActions; - } - - public boolean cancelsCustomActions() { - return cancelCustomActions; - } -} +/* + * Copyright 2021 Siphalor + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. + * See the License for the specific language governing + * permissions and limitations under the License. + */ + +package de.siphalor.mousewheelie.client.util; + +public enum ScrollAction { + PASS(false, false), SUCCESS(true, true), FAILURE(false, true), ABORT(true, false); + final boolean cancelCustomActions; + final boolean cancelAllActions; + + ScrollAction(boolean cancelCustomActions, boolean cancelAllActions) { + this.cancelCustomActions = cancelCustomActions; + this.cancelAllActions = cancelAllActions; + } + + public boolean cancelsAllActions() { + return cancelAllActions; + } + + public boolean cancelsCustomActions() { + return cancelCustomActions; + } +} diff --git a/src/main/resources/assets/mousewheelie/lang/en_us.json b/src/main/resources/assets/mousewheelie/lang/en_us.json index 3407c104..55b394ca 100644 --- a/src/main/resources/assets/mousewheelie/lang/en_us.json +++ b/src/main/resources/assets/mousewheelie/lang/en_us.json @@ -14,6 +14,8 @@ "tweed4_tailor_screen.screen.mousewheelie": "Mouse Wheelie Config", "tweed4_tailor_screen.screen.mousewheelie.general": "General", "tweed4_tailor_screen.screen.mousewheelie.general.interaction-rate": "Interaction rate", + "tweed4_tailor_screen.screen.mousewheelie.general.enable-quick-armor-swapping": "Quick Armor Swapping", + "tweed4_tailor_screen.screen.mousewheelie.general.enable-alt-dropping": "Drop with Alt+Click", "tweed4_tailor_screen.screen.mousewheelie.general.enable-quick-craft": "Enable quick crafting", "tweed4_tailor_screen.screen.mousewheelie.general.hotbar-scope": "Treat hotbar separately", "tweed4_tailor_screen.screen.mousewheelie.scrolling": "Scrolling",