-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Restructured a lot * Updated mappings + Added config
- Loading branch information
Showing
29 changed files
with
261 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
9 changes: 8 additions & 1 deletion
9
...mousewheelie/client/ClientFabricCore.java → ...halor/mousewheelie/client/ClientCore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/de/siphalor/mousewheelie/client/InteractionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/de/siphalor/mousewheelie/client/ModMenuEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.