Skip to content

Commit

Permalink
Merge branch '1.17' into 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
Siphalor committed Mar 25, 2022
2 parents 19935ce + 985d825 commit d632a4c
Show file tree
Hide file tree
Showing 50 changed files with 439 additions and 219 deletions.
274 changes: 201 additions & 73 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LICENSE_HEADER
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2021 Siphalor
Copyright 2020-2022 Siphalor

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ dependencies {

modImplementation("com.terraformersmc:modmenu:3.0.0")

include(modApi("de.siphalor.tweed4:tweed4-base-$minecraft_major_version:1.4.2+mc1.18-pre2"))
include(modApi("de.siphalor.tweed4:tweed4-base-$minecraft_major_version:1.4.3+mc1.18-pre2"))
include(modApi("de.siphalor.tweed4:tweed4-annotated-$minecraft_major_version:1.3.0+mc1.18-pre2"))
include(modApi("de.siphalor.tweed4:tweed4-data-$minecraft_major_version:1.2.1+mc1.18-pre2"))
include(modApi("de.siphalor.tweed4:tweed4-data-hjson-$minecraft_major_version:1.1.0+mc1.18-pre2"))
include(modApi("de.siphalor.tweed4:tweed4-tailor-screen-$minecraft_major_version:1.1.0+mc1.18-pre2"))
include(modApi("de.siphalor.tweed4:tweed4-tailor-coat-$minecraft_major_version:1.1.1+mc1.18-pre2"))
include(modApi("de.siphalor.tweed4:tweed4-tailor-coat-$minecraft_major_version:1.1.2+mc1.18-pre2"))
include(modApi("de.siphalor:coat-$minecraft_major_version:$coat_version"))

modImplementation(include("de.siphalor:amecsapi-$minecraft_major_version:${project.amecs_version}")) {
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=2:v2
loader_version=0.12.5
# Mod Properties
mod_id=mousewheelie
mod_version=1.8.5
mod_version=1.8.6
mod_release=release
mod_mc_version_specifier=1.18+
mod_mc_versions=1.18;1.18.1
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/de/siphalor/mousewheelie/MWConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@ public class MWConfig {
public static class General {
@AConfigEntry(
comment = "Sets the interval in milliseconds in which certain packets are fired.\nLower numbers increase the speed but might be rejected by servers.",
constraints = @AConfigConstraint(value = RangeConstraint.class, param = "1..1000")
constraints = @AConfigConstraint(value = RangeConstraint.class, param = "1..")
)
public int interactionRate = 10;

Expand All @@ -55,6 +55,9 @@ public static class General {
@AConfigEntry(comment = "This option will treat the hotbar as a separate scope.\nThis means that pushing the inventory or sorting the main inventory will not affect the hotbar and vice-versa.")
public boolean hotbarScope = true;

@AConfigEntry(comment = "This helps when you regularly move your mouse faster than the game can pick up.\nThis will impact performance though.")
public boolean betterFastDragging = false;

@AConfigListener()
public void onReload() {
InteractionManager.setTickRate(interactionRate);
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
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,11 @@
package de.siphalor.mousewheelie.client.inventory;

import de.siphalor.mousewheelie.MWConfig;
import de.siphalor.mousewheelie.client.network.ClickEventFactory;
import de.siphalor.mousewheelie.client.network.InteractionManager;
import de.siphalor.mousewheelie.client.util.accessors.ISlot;
import it.unimi.dsi.fastutil.ints.IntRBTreeSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -36,21 +40,53 @@
@SuppressWarnings("WeakerAccess")
public class ContainerScreenHelper<T extends HandledScreen<?>> {
protected final T screen;
protected final ClickHandler clickHandler;
protected final ClickEventFactory clickEventFactory;
protected final IntSet lockedSlots = new IntRBTreeSet();

public static final int INVALID_SCOPE = Integer.MAX_VALUE;

protected ContainerScreenHelper(T screen, ClickHandler clickHandler) {
protected ContainerScreenHelper(T screen, ClickEventFactory clickEventFactory) {
this.screen = screen;
this.clickHandler = clickHandler;
this.clickEventFactory = clickEventFactory;
}

@SuppressWarnings("unchecked")
public static <T extends HandledScreen<?>> ContainerScreenHelper<T> of(T screen, ClickHandler clickHandler) {
public static <T extends HandledScreen<?>> ContainerScreenHelper<T> of(T screen, ClickEventFactory clickEventFactory) {
if (screen instanceof CreativeInventoryScreen) {
return (ContainerScreenHelper<T>) new CreativeContainerScreenHelper<>((CreativeInventoryScreen) screen, clickHandler);
return (ContainerScreenHelper<T>) new CreativeContainerScreenHelper<>((CreativeInventoryScreen) screen, clickEventFactory);
}
return new ContainerScreenHelper<>(screen, clickHandler);
return new ContainerScreenHelper<>(screen, clickEventFactory);
}

public InteractionManager.InteractionEvent createClickEvent(Slot slot, int action, SlotActionType actionType) {
if (lockedSlots.contains(slot.id)) {
return null;
}
return clickEventFactory.create(slot, action, actionType);
}

public boolean isSlotLocked(Slot slot) {
return lockedSlots.contains(slot.id);
}

public void lockSlot(Slot slot) {
lockedSlots.add(slot.id);
}

public void unlockSlot(Slot slot) {
lockedSlots.remove(slot.id);
}

private InteractionManager.InteractionEvent unlockAfter(InteractionManager.InteractionEvent event, Slot slot) {
if (event == null) {
return null;
}

return new InteractionManager.CallbackEvent(() -> {
InteractionManager.Waiter waiter = event.send();
unlockSlot(slot);
return waiter;
});
}

public void scroll(Slot referenceSlot, boolean scrollUp) {
Expand Down Expand Up @@ -123,7 +159,7 @@ public int getScope(Slot slot) {
if (slot.inventory instanceof PlayerInventory) {
if (isHotbarSlot(slot)) {
return 0;
} else if (((ISlot) slot).mouseWheelie_getInvSlot() == 40) {
} else if (((ISlot) slot).mouseWheelie_getInvSlot() >= 40) {
return -1;
} else {
return 1;
Expand All @@ -150,14 +186,39 @@ public void runInScope(int scope, Consumer<Slot> slotConsumer) {
}

public void sendSingleItem(Slot slot) {
clickHandler.handleClick(slot, 0, SlotActionType.PICKUP);
clickHandler.handleClick(slot, 1, SlotActionType.PICKUP);
clickHandler.handleClick(slot, 0, SlotActionType.QUICK_MOVE);
clickHandler.handleClick(slot, 0, SlotActionType.PICKUP);
if (lockedSlots.contains(slot.id)) {
return;
}

InteractionManager.push(clickEventFactory.create(slot, 0, SlotActionType.PICKUP));
InteractionManager.push(clickEventFactory.create(slot, 1, SlotActionType.PICKUP));
InteractionManager.push(clickEventFactory.create(slot, 0, SlotActionType.QUICK_MOVE));
InteractionManager.push(clickEventFactory.create(slot, 0, SlotActionType.PICKUP));
}

public void sendSingleItemLocked(Slot slot) {
if (lockedSlots.contains(slot.id)) {
return;
}

lockedSlots.add(slot.id);
InteractionManager.push(clickEventFactory.create(slot, 0, SlotActionType.PICKUP));
InteractionManager.push(clickEventFactory.create(slot, 1, SlotActionType.PICKUP));
InteractionManager.push(clickEventFactory.create(slot, 0, SlotActionType.QUICK_MOVE));
InteractionManager.push(unlockAfter(clickEventFactory.create(slot, 0, SlotActionType.PICKUP), slot));
}

public void sendStack(Slot slot) {
clickHandler.handleClick(slot, 0, SlotActionType.QUICK_MOVE);
InteractionManager.push(createClickEvent(slot, 0, SlotActionType.QUICK_MOVE));
}

public void sendStackLocked(Slot slot) {
if (lockedSlots.contains(slot.id)) {
return;
}

lockedSlots.add(slot.id);
InteractionManager.push(unlockAfter(clickEventFactory.create(slot, 0, SlotActionType.QUICK_MOVE), slot));
}

public void sendAllOfAKind(Slot referenceSlot) {
Expand All @@ -174,7 +235,20 @@ public void sendAllFrom(Slot referenceSlot) {
}

public void dropStack(Slot slot) {
clickHandler.handleClick(slot, 1, SlotActionType.THROW);
if (lockedSlots.contains(slot.id)) {
return;
}

InteractionManager.push(createClickEvent(slot, 1, SlotActionType.THROW));
}

public void dropStackLocked(Slot slot) {
if (lockedSlots.contains(slot.id)) {
return;
}

lockedSlots.add(slot.id);
InteractionManager.push(unlockAfter(clickEventFactory.create(slot, 1, SlotActionType.THROW), slot));
}

public void dropAllOfAKind(Slot referenceSlot) {
Expand All @@ -189,8 +263,4 @@ public void dropAllOfAKind(Slot referenceSlot) {
public void dropAllFrom(Slot referenceSlot) {
runInScope(getScope(referenceSlot), this::dropStack);
}

public interface ClickHandler {
void handleClick(Slot slot, int data, SlotActionType slotActionType);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,8 @@

package de.siphalor.mousewheelie.client.inventory;

import de.siphalor.mousewheelie.client.network.ClickEventFactory;
import de.siphalor.mousewheelie.client.network.InteractionManager;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
Expand All @@ -28,8 +30,8 @@

@Environment(EnvType.CLIENT)
public class CreativeContainerScreenHelper<T extends CreativeInventoryScreen> extends ContainerScreenHelper<T> {
public CreativeContainerScreenHelper(T screen, ClickHandler clickHandler) {
super(screen, clickHandler);
public CreativeContainerScreenHelper(T screen, ClickEventFactory clickEventFactory) {
super(screen, clickEventFactory);
}

@Override
Expand All @@ -42,17 +44,17 @@ public void sendSingleItem(Slot slot) {
if (getScope(testSlot) != scope) {
ItemStack itemStack = testSlot.getStack();
if (ItemStack.canCombine(slot.getStack(), itemStack) && itemStack.getCount() < itemStack.getMaxCount()) {
clickHandler.handleClick(slot, 0, SlotActionType.PICKUP);
clickHandler.handleClick(testSlot, 0, SlotActionType.PICKUP);
InteractionManager.push(clickEventFactory.create(slot, 0, SlotActionType.PICKUP));
InteractionManager.push(clickEventFactory.create(testSlot, 0, SlotActionType.PICKUP));
return;
}
}
}
for (Slot testSlot : screen.getScreenHandler().slots) {
if (getScope(testSlot) != scope) {
if (!testSlot.hasStack()) {
clickHandler.handleClick(slot, 0, SlotActionType.PICKUP);
clickHandler.handleClick(testSlot, 0, SlotActionType.PICKUP);
InteractionManager.push(clickEventFactory.create(slot, 0, SlotActionType.PICKUP));
InteractionManager.push(clickEventFactory.create(testSlot, 0, SlotActionType.PICKUP));
return;
}
}
Expand All @@ -79,19 +81,19 @@ public void sendStack(Slot slot) {
super.sendStack(slot);
} else {
int count = slot.getStack().getMaxCount();
clickHandler.handleClick(slot, 0, SlotActionType.CLONE);
InteractionManager.push(clickEventFactory.create(slot, 0, SlotActionType.CLONE));
for (Slot testSlot : screen.getScreenHandler().slots) {
ItemStack itemStack = testSlot.getStack();
if (itemStack.isEmpty()) {
clickHandler.handleClick(testSlot, 0, SlotActionType.PICKUP);
InteractionManager.push(clickEventFactory.create(testSlot, 0, SlotActionType.PICKUP));
return;
} else if (ItemStack.canCombine(itemStack, slot.getStack()) && itemStack.getCount() < itemStack.getMaxCount()) {
count -= itemStack.getCount();
clickHandler.handleClick(testSlot, 0, SlotActionType.PICKUP);
InteractionManager.push(clickEventFactory.create(testSlot, 0, SlotActionType.PICKUP));
if (count <= 0) return;
}
}
clickHandler.handleClick(getDelSlot(slot.getStack()), 0, SlotActionType.PICKUP);
InteractionManager.push(clickEventFactory.create(getDelSlot(slot.getStack()), 0, SlotActionType.PICKUP));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,8 +48,7 @@ public InventorySorter(HandledScreen<?> containerScreen, Slot originSlot) {

private void collectSlots(Slot originSlot) {
inventorySlots = new ArrayList<>();
ContainerScreenHelper<? extends HandledScreen<?>> screenHelper = ContainerScreenHelper.of(containerScreen, (slot, data, slotActionType) -> {
});
ContainerScreenHelper<? extends HandledScreen<?>> screenHelper = ContainerScreenHelper.of(containerScreen, (slot, data, slotActionType) -> null);
int originScope = screenHelper.getScope(originSlot);
if (originScope == ContainerScreenHelper.INVALID_SCOPE) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Siphalor
* Copyright 2020-2022 Siphalor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit d632a4c

Please sign in to comment.