diff --git a/dependencies.gradle b/dependencies.gradle index 1cebc1c..90cb8f7 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -76,7 +76,7 @@ dependencies { /* -------------------------------- Hard Runtime Only Deps -------------------------------- */ - // Modular UI, needed sometimes for GT Runtime + // Modular UI, needed sometimes for GT Runtime, and for other mods runtimeOnly "curse.maven:modularui-624243:5153413" // Version 2.4.3 /* -------------------------------- Util Runtime Only Deps -------------------------------- */ @@ -158,6 +158,9 @@ dependencies { // Top Addons (from CurseForge) compileOnly rfg.deobf("curse.maven:top-addons-247111:2887479") // Version 1.13.0 + // Inventory BogoSorter (from CurseForge) + compileOnly rfg.deobf("curse.maven:inventory-bogosorter-632327:5162169") // Version 1.4.8 + /* -------------------------------- Soft Deps, Multiple Runtime Declaration -------------------------------- */ if (project.enable_draconic.toBoolean() || project.enable_thermal.toBoolean()) { runtimeOnly "curse.maven:redstone-flux-270789:2920436" // Version 2.1.1.1 @@ -262,6 +265,10 @@ dependencies { runtimeOnly "curse.maven:actually-additions-228404:3117927" // Version r152 } + if (project.enable_bogo.toBoolean()) { + runtimeOnly "curse.maven:inventory-bogosorter-632327:5162169" // Version 1.4.8 + } + if (project.enable_ender_storage.toBoolean()) { // Ender Storage, runtime only, integrated in remappers (from CurseForge) runtimeOnly "curse.maven:ender-storage-245174:2755787" // Version 2.4.6.137 diff --git a/gradle.properties b/gradle.properties index 238677d..6ca1856 100644 --- a/gradle.properties +++ b/gradle.properties @@ -289,6 +289,9 @@ enable_aa = false # If this is set to false, the remappers will not apply there. enable_ender_storage = false +# Whether to enable Inventory BogoSorter in runtime. Fixes duplication glitch with Thermal Satchels. +enable_bogo = false + # Whether to enable Thermal Expansion and its deps in runtime. These are used for the excitation coil textures. # If this is set to false, the top of the excitation coil will have a null texture. enable_thermal = false diff --git a/src/main/java/com/nomiceu/nomilabs/LabsValues.java b/src/main/java/com/nomiceu/nomilabs/LabsValues.java index 653dfbe..3dee179 100644 --- a/src/main/java/com/nomiceu/nomilabs/LabsValues.java +++ b/src/main/java/com/nomiceu/nomilabs/LabsValues.java @@ -43,4 +43,5 @@ public class LabsValues { public static final String TOP_ADDONS_MODID = "topaddons"; public static final String PACK_MODE_MODID = "packmode"; public static final String AE2_STUFF_MODID = "ae2stuff"; + public static final String BOGOSORT_MODID = "bogosorter"; } diff --git a/src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java b/src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java index 12df7c3..b212214 100644 --- a/src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java @@ -46,7 +46,8 @@ public class LabsLateMixin implements ILateMixinLoader { new AbstractMap.SimpleImmutableEntry<>(LabsValues.TOP_MODID, true), new AbstractMap.SimpleImmutableEntry<>(LabsValues.AE2_MODID, true), new AbstractMap.SimpleImmutableEntry<>(LabsValues.ENDER_IO_MODID, true), - new AbstractMap.SimpleImmutableEntry<>(LabsValues.AA_MODID, true)) + new AbstractMap.SimpleImmutableEntry<>(LabsValues.AA_MODID, true), + new AbstractMap.SimpleImmutableEntry<>(LabsValues.BOGOSORT_MODID, true)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); @Override diff --git a/src/main/java/com/nomiceu/nomilabs/groovy/KeyBindingHelper.java b/src/main/java/com/nomiceu/nomilabs/groovy/KeyBindingHelper.java index a88a66c..13c47c5 100644 --- a/src/main/java/com/nomiceu/nomilabs/groovy/KeyBindingHelper.java +++ b/src/main/java/com/nomiceu/nomilabs/groovy/KeyBindingHelper.java @@ -51,6 +51,7 @@ public static void addKeybindOverride(String id, KeyModifier modifier, int keyCo } public static class KeybindOverrideSpecification { + private final String id; private final KeyModifier modifier; private final int keyCode; diff --git a/src/main/java/com/nomiceu/nomilabs/groovy/LabsVirtualizedRegistries.java b/src/main/java/com/nomiceu/nomilabs/groovy/LabsVirtualizedRegistries.java index 6264a44..26eeb1d 100644 --- a/src/main/java/com/nomiceu/nomilabs/groovy/LabsVirtualizedRegistries.java +++ b/src/main/java/com/nomiceu/nomilabs/groovy/LabsVirtualizedRegistries.java @@ -1,14 +1,14 @@ package com.nomiceu.nomilabs.groovy; import static com.nomiceu.nomilabs.groovy.CompositionBuilder.CompositionSpecification; -import static com.nomiceu.nomilabs.util.LabsGroovyHelper.LABS_GROOVY_RUNNING; import static com.nomiceu.nomilabs.groovy.KeyBindingHelper.KeybindOverrideSpecification; +import static com.nomiceu.nomilabs.util.LabsGroovyHelper.LABS_GROOVY_RUNNING; import java.util.*; import net.minecraft.item.ItemStack; - import net.minecraftforge.client.settings.KeyModifier; + import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.Nullable; @@ -124,9 +124,10 @@ public static class KeybindOverridesManager extends VirtualizedRegistry KeyBindingHelper.addKeybindOverride(spec.getId(), spec.getModifier(), spec.getKeyCode())); + restoreFromBackup().forEach( + (spec) -> KeyBindingHelper.addKeybindOverride(spec.getId(), spec.getModifier(), spec.getKeyCode())); } - + public void addOverride(String id, KeyModifier modifier, int keyCode) { if (KeyBindingHelper.invalidID(id)) return; addBackup(KeyBindingHelper.getExisting(id)); @@ -135,6 +136,7 @@ public void addOverride(String id, KeyModifier modifier, int keyCode) { } public static class RecyclingSpecification { + private final ItemMeta itemMeta; private final ItemMaterialInfo info; diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/bogosorter/SortHandlerMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/bogosorter/SortHandlerMixin.java new file mode 100644 index 0000000..e95e3ab --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/bogosorter/SortHandlerMixin.java @@ -0,0 +1,93 @@ +package com.nomiceu.nomilabs.mixin.bogosorter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import org.jetbrains.annotations.UnmodifiableView; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import com.cleanroommc.bogosorter.api.ISlot; +import com.cleanroommc.bogosorter.common.sort.SlotGroup; +import com.cleanroommc.bogosorter.common.sort.SortHandler; + +/** + * Prevents Modification of 'Locked' Slots. + */ +@Mixin(value = SortHandler.class, remap = false) +public class SortHandlerMixin { + + @Shadow + @Final + private EntityPlayer player; + + @Redirect(method = "sortHorizontal", + at = @At(value = "INVOKE", + target = "Lcom/cleanroommc/bogosorter/common/sort/SlotGroup;getSlots()Ljava/util/List;")) + private @UnmodifiableView List checkLockedSlots1(SlotGroup instance) { + return labs$getSlotsLogic(instance); + } + + @Redirect(method = "gatherItems", + at = @At(value = "INVOKE", + target = "Lcom/cleanroommc/bogosorter/common/sort/SlotGroup;getSlots()Ljava/util/List;")) + private @UnmodifiableView List checkLockedSlots2(SlotGroup instance) { + return labs$getSlotsLogic(instance); + } + + @Redirect(method = "clearAllItems", + at = @At(value = "INVOKE", + target = "Lcom/cleanroommc/bogosorter/common/sort/SlotGroup;getSlots()Ljava/util/List;")) + private @UnmodifiableView List checkLockedSlots3(SlotGroup instance) { + return labs$getSlotsLogic(instance); + } + + @Redirect(method = "randomizeItems", + at = @At(value = "INVOKE", + target = "Lcom/cleanroommc/bogosorter/common/sort/SlotGroup;getSlots()Ljava/util/List;")) + private @UnmodifiableView List checkLockedSlots4(SlotGroup instance) { + return labs$getSlotsLogic(instance); + } + + /** + * Sort Bogo is static, so we need to redirect calls of it + */ + @Redirect(method = "sort(Lcom/cleanroommc/bogosorter/common/sort/SlotGroup;Z)V", + at = @At(value = "INVOKE", + target = "Lcom/cleanroommc/bogosorter/common/sort/SortHandler;sortBogo(Lcom/cleanroommc/bogosorter/common/sort/SlotGroup;)V")) + private void newSortBogo(SlotGroup instance) { + List items = new ArrayList<>(); + + for (var slot : labs$getSlotsLogic(instance)) { + ItemStack stack = slot.bogo$getStack(); + items.add(stack); + } + + Collections.shuffle(items); + List slots = labs$getSlotsLogic(instance); + + for (int i = 0; i < slots.size(); i++) { + ISlot slot = slots.get(i); + slot.bogo$putStack(items.get(i)); + } + } + + @Unique + private @UnmodifiableView List labs$getSlotsLogic(SlotGroup instance) { + var slots = instance.getSlots(); + List result = new ArrayList<>(); + + for (var slot : slots) { + if (slot.bogo$canTakeStack(player)) result.add(slot); + } + return result; + } +} diff --git a/src/main/resources/mixins.nomilabs.bogosorter.json b/src/main/resources/mixins.nomilabs.bogosorter.json new file mode 100644 index 0000000..20a5408 --- /dev/null +++ b/src/main/resources/mixins.nomilabs.bogosorter.json @@ -0,0 +1,12 @@ +{ + "package": "com.nomiceu.nomilabs.mixin.bogosorter", + "refmap": "mixins.nomilabs.refmap.json", + "target": "@env(DEFAULT)", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "SortHandlerMixin" + ], + "client": [], + "server": [] +}