Skip to content

Commit

Permalink
Merging Mousetweaks (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: Caedis <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 8, 2025
1 parent 3772f4f commit 743f707
Show file tree
Hide file tree
Showing 124 changed files with 4,667 additions and 1,952 deletions.
29 changes: 16 additions & 13 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,29 @@
* For more details, see https://docs.gradle.org/8.4/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
api("com.github.GTNewHorizons:ModularUI2:2.1.16-1.7.10:dev")
api("com.github.GTNewHorizons:ModularUI2:2.2.0-1.7.10:dev")
api("com.github.GTNewHorizons:ModularUI:1.2.17:dev")
api("com.github.GTNewHorizons:GTNHLib:0.6.0:dev")


// api("com.github.GTNewHorizons:AdventureBackpack2:1.2.4-GTNH:dev")
compileOnly("com.github.GTNewHorizons:AdventureBackpack2:1.2.4-GTNH:dev")
compileOnly("com.github.GTNewHorizons:Minecraft-Backpack-Mod:2.4.3-GTNH:dev")
compileOnly("com.github.GTNewHorizons:Galacticraft:3.2.8-GTNH:dev")
compileOnly("com.github.GTNewHorizons:EnderIO:2.8.22:dev")
compileOnly("com.github.GTNewHorizons:ironchest:6.0.87:dev")
compileOnly("com.github.GTNewHorizons:Minecraft-Backpack-Mod:2.5.0-GTNH:dev")
compileOnly("com.github.GTNewHorizons:Galacticraft:3.3.1-GTNH:dev")
compileOnly("com.github.GTNewHorizons:EnderIO:2.9.2:dev")
compileOnly("com.github.GTNewHorizons:ironchest:6.1.0:dev")
compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.8.4-GTNH:dev")
compileOnly("com.github.GTNewHorizons:CookingForBlockheads:1.3.8-GTNH:dev")
compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.0:dev")
compileOnly("com.github.GTNewHorizons:Draconic-Evolution:1.3.14-GTNH:dev")
compileOnly("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-503-GTNH:dev")
compileOnly("com.github.GTNewHorizons:EnderStorage:1.6.4:dev")
compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.12.14-GTNH:dev")
devOnlyNonPublishable("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.15:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:Botania:1.12.1-GTNH:dev")
compileOnly("com.github.GTNewHorizons:CookingForBlockheads:1.4.0-GTNH:dev")
compileOnly("com.github.GTNewHorizons:ForestryMC:4.10.1:dev")
compileOnly("com.github.GTNewHorizons:Draconic-Evolution:1.4.1-GTNH:dev")
compileOnly("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-518-GTNH:dev")
compileOnly("com.github.GTNewHorizons:EnderStorage:1.7.0:dev")
compileOnly("com.github.GTNewHorizons:TinkersConstruct:1.13.3-GTNH:dev")
compileOnly("com.github.GTNewHorizons:CodeChickenCore:1.4.0:dev")
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.7.13-GTNH:dev")
devOnlyNonPublishable("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.54:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:Botania:1.12.3-GTNH:dev")



compileOnly rfg.deobf('curse.maven:projecte-226410:2340786')
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ curseForgeRelations =
# Uncomment this to disable Spotless checks.
# This should only be uncommented to keep it easier to sync with upstream/other forks.
# That is, if there is no other active fork/upstream, NEVER change this.
disableSpotless = true
# disableSpotless = true

# Uncomment this to disable Checkstyle checks (currently wildcard import check).
# disableCheckstyle = true
Expand Down
107 changes: 57 additions & 50 deletions src/main/java/com/cleanroommc/bogosorter/BogoSortAPI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
package com.cleanroommc.bogosorter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Function;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;

import appeng.container.slot.AppEngSlot;
import com.cleanroommc.bogosorter.api.IBogoSortAPI;
import com.cleanroommc.bogosorter.api.ICustomInsertable;
import com.cleanroommc.bogosorter.api.IPosSetter;
Expand All @@ -18,44 +39,26 @@
import com.cleanroommc.modularui.utils.item.PlayerInvWrapper;
import com.cleanroommc.modularui.utils.item.PlayerMainInvWrapper;
import com.cleanroommc.modularui.utils.item.SlotItemHandler;

import appeng.container.slot.AppEngSlot;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Function;

public class BogoSortAPI implements IBogoSortAPI {

public static final BogoSortAPI INSTANCE = new BogoSortAPI();
public static final SortRule<ItemStack> EMPTY_ITEM_SORT_RULE = new SortRule<ItemStack>("empty", (o1, o2) -> 0) {

@Override
public boolean isEmpty() {
return true;
}
};
public static final NbtSortRule EMPTY_NBT_SORT_RULE = new NbtSortRule("empty", null, (o1, o2) -> 0) {

@Override
public boolean isEmpty() {
return true;
Expand All @@ -64,10 +67,10 @@ public boolean isEmpty() {

public static final Function<Slot, ISlot> DEFAULT_SLOT_GETTER = slot -> (ISlot) slot;

private static final ICustomInsertable DEFAULT_INSERTABLE = (container, slots, stack, emptyOnly) -> ShortcutHandler.insertToSlots(slots, stack, emptyOnly);
private static final ICustomInsertable DEFAULT_INSERTABLE = (container, slots, stack, emptyOnly) -> ShortcutHandler
.insertToSlots(slots, stack, emptyOnly);

private BogoSortAPI() {
}
private BogoSortAPI() {}

private final Map<Class<?>, BiConsumer<Container, ISortingContextBuilder>> COMPAT_MAP = new Object2ObjectOpenHashMap<>();
private final Map<Class<?>, IPosSetter> playerButtonPos = new Object2ObjectOpenHashMap<>();
Expand Down Expand Up @@ -139,7 +142,8 @@ public void registerItemSortingRule(String key, Comparator<ItemStack> itemCompar
}

@ApiStatus.Internal
public void registerClientItemSortingRule(String key, Comparator<ItemStack> comparator, Comparator<ItemSortContainer> serverComparator) {
public void registerClientItemSortingRule(String key, Comparator<ItemStack> comparator,
Comparator<ItemSortContainer> serverComparator) {
validateKey(key);
ClientItemSortRule sortRule = new ClientItemSortRule(key, comparator, serverComparator);
itemSortRules.put(key, sortRule);
Expand All @@ -166,7 +170,8 @@ public void registerNbtSortingRule(String key, String tagPath, int expectedType)
}

@Override
public <T> void registerNbtSortingRule(String key, String tagPath, int expectedType, Comparator<T> comparator, Function<NBTBase, T> converter) {
public <T> void registerNbtSortingRule(String key, String tagPath, int expectedType, Comparator<T> comparator,
Function<NBTBase, T> converter) {
validateKey(key);
NbtSortRule sortRule = new NbtSortRule(key, tagPath, expectedType, comparator, converter);
nbtSortRules.put(key, sortRule);
Expand All @@ -176,7 +181,7 @@ public <T> void registerNbtSortingRule(String key, String tagPath, int expectedT

public <T extends Container> BiConsumer<T, ISortingContextBuilder> getBuilder(Container container) {
BiConsumer<Container, ISortingContextBuilder> builder = COMPAT_MAP.get(container.getClass());
return builder==null ? null:(BiConsumer<T, ISortingContextBuilder>) builder;
return builder == null ? null : (BiConsumer<T, ISortingContextBuilder>) builder;
}

public IPosSetter getPlayerButtonPos(Container container) {
Expand All @@ -198,10 +203,10 @@ public List<SortRule<ItemStack>> getItemSortRuleList() {

public SortRule<ItemStack> getItemSortRule(String key) {
SortRule<ItemStack> sortRule = this.itemSortRules.get(key);
if (sortRule==null && this.remappedSortRules.containsKey(key)) {
if (sortRule == null && this.remappedSortRules.containsKey(key)) {
sortRule = this.itemSortRules.get(this.remappedSortRules.get(key));
}
return sortRule==null ? EMPTY_ITEM_SORT_RULE:sortRule;
return sortRule == null ? EMPTY_ITEM_SORT_RULE : sortRule;
}

public SortRule<ItemStack> getItemSortRule(int syncId) {
Expand All @@ -214,10 +219,10 @@ public NbtSortRule getNbtSortRule(int syncId) {

public NbtSortRule getNbtSortRule(String key) {
NbtSortRule sortRule = this.nbtSortRules.get(key);
if (sortRule==null && this.remappedSortRules.containsKey(key)) {
if (sortRule == null && this.remappedSortRules.containsKey(key)) {
sortRule = this.nbtSortRules.get(this.remappedSortRules.get(key));
}
return sortRule==null ? EMPTY_NBT_SORT_RULE:sortRule;
return sortRule == null ? EMPTY_NBT_SORT_RULE : sortRule;
}

@SideOnly(Side.CLIENT)
Expand All @@ -235,7 +240,8 @@ public boolean sortSlotGroup(Slot slot) {
@NotNull
@Override
public ISlot getSlot(@NotNull Slot slot) {
return this.slotGetterMap.getOrDefault(slot.getClass(), DEFAULT_SLOT_GETTER).apply(slot);
return this.slotGetterMap.getOrDefault(slot.getClass(), DEFAULT_SLOT_GETTER)
.apply(slot);
}

@Override
Expand All @@ -251,7 +257,8 @@ public static ISlot getSlot(@NotNull Container container, int index) {

@NotNull
public ICustomInsertable getInsertable(@NotNull Container container, boolean player) {
return player ? DEFAULT_INSERTABLE:this.customInsertableMap.getOrDefault(container.getClass(), DEFAULT_INSERTABLE);
return player ? DEFAULT_INSERTABLE
: this.customInsertableMap.getOrDefault(container.getClass(), DEFAULT_INSERTABLE);
}

public static ItemStack insert(Container container, List<ISlot> slots, ItemStack stack) {
Expand All @@ -268,7 +275,8 @@ public static ItemStack insert(Container container, List<ISlot> slots, ItemStack

public static ItemStack insert(Container container, List<ISlot> slots, ItemStack stack, boolean emptyOnly) {
if (slots.isEmpty()) return stack;
return INSTANCE.getInsertable(container, isPlayerSlot(slots.get(0))).insert(container, slots, stack, emptyOnly);
return INSTANCE.getInsertable(container, isPlayerSlot(slots.get(0)))
.insert(container, slots, stack, emptyOnly);
}

public static boolean isValidSortable(Container container) {
Expand All @@ -280,10 +288,12 @@ public static boolean isPlayerSlot(Slot slot) {
}

public static boolean isPlayerSlot(ISlot slot) {
if (slot==null) return false;
if (slot.bogo$getInventory() instanceof InventoryPlayer ||
(slot instanceof SlotItemHandler && isPlayerInventory((IInventory) ((SlotItemHandler) slot).getItemHandler()))
|| (Mods.Ae2.isLoaded() && slot instanceof AppEngSlot && isPlayerInventory(((AppEngSlot) slot).inventory))) {
if (slot == null) return false;
if (slot.bogo$getInventory() instanceof InventoryPlayer
|| (slot instanceof SlotItemHandler
&& isPlayerInventory((IInventory) ((SlotItemHandler) slot).getItemHandler()))
|| (Mods.Ae2.isLoaded() && slot instanceof AppEngSlot
&& isPlayerInventory(((AppEngSlot) slot).inventory))) {
return slot.bogo$getSlotIndex() >= 0 && slot.bogo$getSlotIndex() < 36;
}
return false;
Expand All @@ -302,12 +312,10 @@ public int hashCode(ItemStack o) {

@Override
public boolean equals(ItemStack a, ItemStack b) {
if (a==b) return true;
if (a==null || b==null) return false;
return (a == null && b == null) ||
(a.getItem()==b.getItem() &&
a.getItemDamage()==b.getItemDamage() &&
Objects.equals(a.getTagCompound(), b.getTagCompound()));
if (a == b) return true;
if (a == null || b == null) return false;
return (a == null && b == null) || (a.getItem() == b.getItem() && a.getItemDamage() == b.getItemDamage()
&& Objects.equals(a.getTagCompound(), b.getTagCompound()));
}
};

Expand All @@ -320,10 +328,9 @@ public int hashCode(ItemStack o) {

@Override
public boolean equals(ItemStack a, ItemStack b) {
if (a==b) return true;
if (a==null || b==null) return false;
return (a == null && b == null) ||
(a.getItem()==b.getItem() && a.getItemDamage()==b.getItemDamage());
if (a == b) return true;
if (a == null || b == null) return false;
return (a == null && b == null) || (a.getItem() == b.getItem() && a.getItemDamage() == b.getItemDamage());
}
};

Expand Down
51 changes: 29 additions & 22 deletions src/main/java/com/cleanroommc/bogosorter/BogoSorter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package com.cleanroommc.bogosorter;

import static com.cleanroommc.bogosorter.ClientEventHandler.*;

import java.time.LocalDate;
import java.time.Month;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.cleanroommc.bogosorter.common.HotbarSwap;
import com.cleanroommc.bogosorter.common.OreDictHelper;
import com.cleanroommc.bogosorter.common.SortConfigChangeEvent;
Expand All @@ -15,32 +27,22 @@
import com.cleanroommc.bogosorter.common.sort.DefaultRules;
import com.cleanroommc.bogosorter.compat.DefaultCompat;
import com.cleanroommc.bogosorter.compat.loader.IntegrationLoader;

import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.time.LocalDate;
import java.time.Month;

import static com.cleanroommc.bogosorter.ClientEventHandler.*;

@Mod(modid = BogoSorter.ID,
name = BogoSorter.NAME,
version = BogoSorter.VERSION,
dependencies = "required-after:gtnhmixins;" +
"required-after:modularui2;")
@Mod(
modid = BogoSorter.ID,
name = BogoSorter.NAME,
version = BogoSorter.VERSION,
dependencies = "required-after:gtnhmixins;" + "required-after:modularui2;")
public class BogoSorter {

public static final String ID = "bogosorter";
Expand All @@ -50,11 +52,12 @@ public class BogoSorter {
public static final XSTR RND = new XSTR();
public static final Logger LOGGER = LogManager.getLogger();


@Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent event) {
IntegrationLoader.load();
FMLCommonHandler.instance().bus().register(this);
FMLCommonHandler.instance()
.bus()
.register(this);
MinecraftForge.EVENT_BUS.register(this);
NetworkHandler.init();
OreDictHelper.init();
Expand All @@ -65,16 +68,19 @@ public void onPreInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new RefillHandler());
if (NetworkUtils.isDedicatedClient()) {
MinecraftForge.EVENT_BUS.post(new SortConfigChangeEvent());
FMLCommonHandler.instance().bus().register(new ClientEventHandler());
FMLCommonHandler.instance()
.bus()
.register(new ClientEventHandler());
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
MinecraftForge.EVENT_BUS.register(new DropOffButtonHandler());
MinecraftForge.EVENT_BUS.register(new ButtonHandler());
FMLCommonHandler.instance().bus().register(new HotbarSwap());
FMLCommonHandler.instance()
.bus()
.register(new HotbarSwap());
MinecraftForge.EVENT_BUS.register(new HotbarSwap());
}
}


@Mod.EventHandler
public void onPostInit(FMLPostInitializationEvent event) {
if (NetworkUtils.isDedicatedClient()) {
Expand All @@ -95,8 +101,9 @@ public void onPlayerJoin(EntityJoinWorldEvent event) {
PlayerConfig.syncToServer();
}
}

@SubscribeEvent
public void onPlayerLogout(FMLNetworkEvent.ClientDisconnectionFromServerEvent ignored){
public void onPlayerLogout(FMLNetworkEvent.ClientDisconnectionFromServerEvent ignored) {
// save config file on logout
Serializer.saveConfig();
}
Expand Down
Loading

0 comments on commit 743f707

Please sign in to comment.