Skip to content

Commit

Permalink
Version 1.1.10
Browse files Browse the repository at this point in the history
* Restructured a lot
* Updated mappings
+ Added config
  • Loading branch information
Siphalor committed May 19, 2019
1 parent 0ac553e commit 14de245
Show file tree
Hide file tree
Showing 29 changed files with 261 additions and 156 deletions.
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@ sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

archivesBaseName = project.archives_base_name
version = project.mod_version
version = project.mod_version + "+" + project.minecraft_version
group = project.maven_group

minecraft {
}

repositories {
mavenLocal()
maven {
name "jitpack"
url "https://jitpack.io"
}
maven {
name "curseforge"
url "https://minecraft.curseforge.com/api/maven"
}
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand All @@ -25,6 +37,13 @@ dependencies {
include "net.fabricmc.fabric-api:fabric-resource-loader:+"

modCompile "net.fabricmc.fabric-api:fabric-item-groups:+"
modCompile "io.github.prospector.modmenu:ModMenu:+"

modCompile "com.github.siphalor:tweed-api:${project.tweed_version}"
include "com.github.siphalor:tweed-api:${project.tweed_version}"

include "cloth-config:ClothConfig:${project.clothconfig_version}"
modCompile "cloth-config:ClothConfig:${project.clothconfig_version}"
}

processResources {
Expand Down
8 changes: 6 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.14.2 Pre-Release 2
yarn_build=+
yarn_build=2
loader_version=0.4.7+build.147

# Mod Properties
mod_id = mousewheelie
mod_version = 1.1.9+1.14.1
mod_version = 1.1.10
maven_group = de.siphalor
archives_base_name = mousewheelie

# Dependencies
tweed_version = 2.1.0-beta.3
clothconfig_version = 0.2.1.14
81 changes: 0 additions & 81 deletions src/main/java/de/siphalor/mousewheelie/Core.java
Original file line number Diff line number Diff line change
@@ -1,86 +1,5 @@
package de.siphalor.mousewheelie;

import net.minecraft.client.MinecraftClient;
import net.minecraft.container.SlotActionType;
import net.minecraft.network.Packet;

import java.util.ArrayDeque;

public class Core {
public static final String MOD_ID = "mousewheelie";
public static int scrollFactor = -1;

public static ArrayDeque<InteractionEvent> interactionEventQueue = new ArrayDeque<>();
public static boolean sending = false;

public static void push(InteractionEvent interactionEvent) {
interactionEventQueue.add(interactionEvent);
if(!sending)
triggerSend();
}

public static void pushClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction) {
ClickEvent clickEvent = new ClickEvent(containerSyncId, slotId, buttonId, slotAction);
push(clickEvent);
}

public static void triggerSend() {
if(interactionEventQueue.size() > 0) {
while(interactionEventQueue.pop().send()) {
if(interactionEventQueue.isEmpty()) {
sending = false;
break;
}
}
} else
sending = false;
}

public static void stopSending() {
sending = false;
interactionEventQueue.clear();
}

public interface InteractionEvent {
/**
* Sends the interaction to the server
* @return a boolean determining whether to continue sending packets
*/
boolean send();
}

public static class ClickEvent implements InteractionEvent {
private int containerSyncId;
private int slotId;
private int buttonId;
private SlotActionType slotAction;

public ClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction) {
this.containerSyncId = containerSyncId;
this.slotId = slotId;
this.buttonId = buttonId;
this.slotAction = slotAction;
}

@Override
public boolean send() {
sending = true;
MinecraftClient.getInstance().interactionManager.method_2906(containerSyncId, slotId, buttonId, slotAction, MinecraftClient.getInstance().player);
return false;
}
}

public static class PacketEvent implements InteractionEvent {
private Packet packet;

public PacketEvent(Packet packet) {
this.packet = packet;
}

@Override
public boolean send() {
MinecraftClient.getInstance().getNetworkHandler().sendPacket(packet);
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package de.siphalor.mousewheelie.client;

import de.siphalor.mousewheelie.Core;
import de.siphalor.tweed.client.TweedClothBridge;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier;

public class ClientFabricCore implements ClientModInitializer {
public class ClientCore implements ClientModInitializer {
public static final String KEY_BINDING_CATEGORY = "key.categories." + Core.MOD_ID;
public static final FabricKeyBinding SORT_KEY_BINDING = FabricKeyBinding.Builder.create(new Identifier(Core.MOD_ID, "sort_inventory"), InputUtil.Type.KEYSYM, -1, KEY_BINDING_CATEGORY).build();
// TODO
public static final FabricKeyBinding FILL_INVENTORY_KEY_BINDING = FabricKeyBinding.Builder.create(new Identifier(Core.MOD_ID, "fill_inventory"), InputUtil.Type.KEYSYM, 71, KEY_BINDING_CATEGORY).build();

public static TweedClothBridge tweedClothBridge;

@Override
public void onInitializeClient() {
KeyBindingRegistry.INSTANCE.addCategory(KEY_BINDING_CATEGORY);
KeyBindingRegistry.INSTANCE.register(SORT_KEY_BINDING);

Config.initialize();

tweedClothBridge = new TweedClothBridge(Config.configFile);
}
}
38 changes: 38 additions & 0 deletions src/main/java/de/siphalor/mousewheelie/client/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.siphalor.mousewheelie.client;

import de.siphalor.mousewheelie.Core;
import de.siphalor.mousewheelie.client.util.SortMode;
import de.siphalor.tweed.config.ConfigCategory;
import de.siphalor.tweed.config.ConfigEnvironment;
import de.siphalor.tweed.config.ConfigFile;
import de.siphalor.tweed.config.TweedRegistry;
import de.siphalor.tweed.config.entry.EnumEntry;
import de.siphalor.tweed.config.entry.FloatEntry;

@SuppressWarnings("unchecked")
public class Config {
public static ConfigFile configFile = TweedRegistry.registerConfigFile(Core.MOD_ID);

public static ConfigCategory sortCategory = configFile.register("sort", new ConfigCategory())
.setComment("Change sort modes. Existing sort modes are ALPHABET, RAW_ID and QUANTITY");
public static EnumEntry<SortMode> primarySort = (EnumEntry<SortMode>) sortCategory.register("primary-sort", new EnumEntry<>(SortMode.RAW_ID))
.setEnvironment(ConfigEnvironment.CLIENT)
.setComment("Sets the sort mode for sorting via middle mouse click.")
;
public static EnumEntry<SortMode> shiftSort = (EnumEntry<SortMode>) sortCategory.register("shift-sort", new EnumEntry<>(SortMode.QUANTITY))
.setEnvironment(ConfigEnvironment.CLIENT)
.setComment("Sets the sort mode for sorting via shift + middle mouse click.");
public static EnumEntry<SortMode> controlSort = (EnumEntry<SortMode>) sortCategory.register("control-sort", new EnumEntry<>(SortMode.ALPHABET))
.setEnvironment(ConfigEnvironment.CLIENT)
.setComment("Sets the sort mode for sorting via control + middle mouse click.");
;

public static ConfigCategory generalCategory = configFile.register("general", new ConfigCategory());
public static FloatEntry scrollFactor = generalCategory.register("scroll-factor", new FloatEntry(-1.0F))
.setComment("Set the scroll factor for item scrolling." + System.lineSeparator() +
"To invert the scrolling use negative numbers");

public static void initialize() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package de.siphalor.mousewheelie.client;

import net.minecraft.client.MinecraftClient;
import net.minecraft.container.SlotActionType;
import net.minecraft.network.Packet;

import java.util.ArrayDeque;

public class InteractionManager {
public static ArrayDeque<InteractionEvent> interactionEventQueue = new ArrayDeque<>();
public static boolean sending = false;

public static void push(InteractionEvent interactionEvent) {
interactionEventQueue.add(interactionEvent);
if(!sending)
triggerSend();
}

public static void pushClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction) {
ClickEvent clickEvent = new ClickEvent(containerSyncId, slotId, buttonId, slotAction);
push(clickEvent);
}

public static void triggerSend() {
if(interactionEventQueue.size() > 0) {
while(interactionEventQueue.pop().send()) {
if(interactionEventQueue.isEmpty()) {
sending = false;
break;
}
}
} else
sending = false;
}

public static void stopSending() {
sending = false;
interactionEventQueue.clear();
}

public interface InteractionEvent {
/**
* Sends the interaction to the server
* @return a boolean determining whether to continue sending packets
*/
boolean send();
}

public static class ClickEvent implements InteractionEvent {
private int containerSyncId;
private int slotId;
private int buttonId;
private SlotActionType slotAction;

public ClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction) {
this.containerSyncId = containerSyncId;
this.slotId = slotId;
this.buttonId = buttonId;
this.slotAction = slotAction;
}

@Override
public boolean send() {
sending = true;
MinecraftClient.getInstance().interactionManager.method_2906(containerSyncId, slotId, buttonId, slotAction, MinecraftClient.getInstance().player);
return false;
}
}

public static class PacketEvent implements InteractionEvent {
private Packet packet;

public PacketEvent(Packet packet) {
this.packet = packet;
}

@Override
public boolean send() {
MinecraftClient.getInstance().getNetworkHandler().sendPacket(packet);
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.siphalor.mousewheelie.client;

import de.siphalor.mousewheelie.Core;
import io.github.prospector.modmenu.api.ModMenuApi;
import net.minecraft.client.gui.screen.Screen;

import java.util.function.Function;

public class ModMenuEntryPoint implements ModMenuApi {
@Override
public String getModId() {
return Core.MOD_ID;
}

@Override
public Function<Screen, ? extends Screen> getConfigScreenFactory() {
return screen -> ClientCore.tweedClothBridge.buildScreen();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package de.siphalor.mousewheelie.client.mixin;

import de.siphalor.mousewheelie.Core;
import de.siphalor.mousewheelie.client.ClientFabricCore;
import de.siphalor.mousewheelie.util.IContainerScreen;
import de.siphalor.mousewheelie.util.ISlot;
import de.siphalor.mousewheelie.util.InventorySorter;
import de.siphalor.mousewheelie.util.SortMode;
import de.siphalor.mousewheelie.client.ClientCore;
import de.siphalor.mousewheelie.client.Config;
import de.siphalor.mousewheelie.client.InteractionManager;
import de.siphalor.mousewheelie.client.util.IContainerScreen;
import de.siphalor.mousewheelie.client.util.ISlot;
import de.siphalor.mousewheelie.client.util.InventorySorter;
import de.siphalor.mousewheelie.client.util.SortMode;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
Expand Down Expand Up @@ -58,21 +59,21 @@ public void onKeyPressed(int key, int scanCode, int int_3, CallbackInfoReturnabl
putBack = true;
if(!focusedSlot.getStack().isEmpty()) {
swapStack = focusedSlot.getStack().copy();
Core.pushClickEvent(container.syncId, focusedSlot.id, 0, SlotActionType.PICKUP);
InteractionManager.pushClickEvent(container.syncId, focusedSlot.id, 0, SlotActionType.PICKUP);
} else if(offHandStack.isEmpty()) {
return;
}
}
Core.pushClickEvent(container.syncId, swapSlot.id, 0, SlotActionType.PICKUP);
Core.push(new Core.PacketEvent(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.DOWN)));
Core.pushClickEvent(container.syncId, swapSlot.id, 0, SlotActionType.PICKUP);
InteractionManager.pushClickEvent(container.syncId, swapSlot.id, 0, SlotActionType.PICKUP);
InteractionManager.push(new InteractionManager.PacketEvent(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.DOWN)));
InteractionManager.pushClickEvent(container.syncId, swapSlot.id, 0, SlotActionType.PICKUP);
if(putBack) {
Core.pushClickEvent(container.syncId, focusedSlot.id, 0, SlotActionType.PICKUP);
InteractionManager.pushClickEvent(container.syncId, focusedSlot.id, 0, SlotActionType.PICKUP);
}
ItemStack finalSwapStack = swapStack;
boolean finalPutBack = putBack;
// Fix the display up since swapping items doesn't have a confirm packet so we have to trigger the click event too quick afterwards
Core.push(() -> {
InteractionManager.push(() -> {
playerInventory.offHand.set(0, finalSwapStack);
if(finalPutBack) {
focusedSlot.setStack(offHandStack);
Expand All @@ -84,7 +85,7 @@ public void onKeyPressed(int key, int scanCode, int int_3, CallbackInfoReturnabl
return true;
});
} else if(FabricLoader.getInstance().isModLoaded("fabric")) {
if(ClientFabricCore.SORT_KEY_BINDING.matchesKey(key, scanCode)) {
if(ClientCore.SORT_KEY_BINDING.matchesKey(key, scanCode)) {
mouseWheelie_triggerSort();
}
}
Expand Down Expand Up @@ -116,7 +117,7 @@ public boolean mouseWheelie_onMouseScroll(double mouseX, double mouseY, double s
return false;
ItemStack hoveredStack = hoveredSlot.getStack();
boolean changeInventory;
boolean moveUp = scrollAmount * Core.scrollFactor < 0;
boolean moveUp = scrollAmount * Config.scrollFactor.value < 0;
BiFunction<Slot, Slot, Boolean> slotsInSameScope;
//noinspection ConstantConditions
if((Screen) this instanceof InventoryScreen) {
Expand Down Expand Up @@ -189,11 +190,11 @@ private boolean mouseWheelie_triggerSort() {
InventorySorter sorter = new InventorySorter(container, focusedSlot);
SortMode sortMode;
if(hasShiftDown()) {
sortMode = SortMode.QUANTITY;
sortMode = Config.shiftSort.value;
} else if(hasControlDown()) {
sortMode = SortMode.RAWID;
sortMode = Config.controlSort.value;
} else {
sortMode = SortMode.ALPHABET;
sortMode = Config.primarySort.value;
}
sorter.sort(sortMode);
return true;
Expand Down
Loading

0 comments on commit 14de245

Please sign in to comment.