Skip to content

Commit

Permalink
Merge branch '1.16' into 1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Siphalor committed Feb 19, 2022
2 parents 13fa3c4 + 6c70508 commit fc60f9b
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .giup
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/siphalor/mousewheelie/MWConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/siphalor/mousewheelie/MouseWheelie.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ContainerScreenHelper<T extends ContainerScreen<?>> {
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;
Expand Down Expand Up @@ -187,7 +187,6 @@ public void dropAllOfAKind(Slot referenceSlot) {
}

public void dropAllFrom(Slot referenceSlot) {
ItemStack referenceStack = referenceSlot.getStack().copy();
runInScope(getScope(referenceSlot), this::dropStack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -135,39 +136,7 @@ boolean matches(ItemStack oldStack) {

@Override
int findMatchingStack(PlayerInventory playerInventory, ItemStack oldStack) {
int currentRank = 0;
ConcurrentLinkedQueue<Class<?>> 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<ItemStack> 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<Class<?>> 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);
}
}

Expand All @@ -179,41 +148,52 @@ boolean matches(ItemStack oldStack) {

@Override
int findMatchingStack(PlayerInventory playerInventory, ItemStack oldStack) {
int currentRank = 0;
ConcurrentLinkedQueue<Class<?>> 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<ItemStack> inventory, Function<Item, Class<?>> getClass, Class<?> baseClass) {
int currentRank = 0;
Collection<Class<?>> 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<ItemStack> 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<Class<?>> 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<Class<?>> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

@Environment(EnvType.CLIENT)
public class ToolPicker {
PlayerInventory inventory;
final PlayerInventory inventory;

static int lastToolPickSlot = -1;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -77,7 +78,7 @@ public abstract class MixinRecipeBookWidget implements IRecipeBookWidget {

@Shadow
@Final
protected RecipeFinder recipeFinder;
private RecipeFinder recipeFinder;

@Shadow
protected CraftingContainer<?> craftingContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<Boolean> callbackInfoReturnable) {
if (button == 0) {
if (hasAltDown()) {
if (MWConfig.general.enableAltDropping && hasAltDown()) {
Slot hoveredSlot = getSlotAt(x, y);
if (hoveredSlot != null) {
if (hasControlDown()) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/mousewheelie/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit fc60f9b

Please sign in to comment.