Skip to content

Commit

Permalink
Fix BogoSorter Sorting 'Locked' Slots
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Aug 11, 2024
1 parent a49b0cf commit 3e5c0ab
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 6 deletions.
9 changes: 8 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------------------- */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/nomiceu/nomilabs/LabsValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
3 changes: 2 additions & 1 deletion src/main/java/com/nomiceu/nomilabs/core/LabsLateMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -124,9 +124,10 @@ public static class KeybindOverridesManager extends VirtualizedRegistry<KeybindO

@Override
public void onReload() {
restoreFromBackup().forEach((spec) -> 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));
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<ISlot> 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<ISlot> 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<ISlot> 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<ISlot> 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<ItemStack> items = new ArrayList<>();

for (var slot : labs$getSlotsLogic(instance)) {
ItemStack stack = slot.bogo$getStack();
items.add(stack);
}

Collections.shuffle(items);
List<ISlot> 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<ISlot> labs$getSlotsLogic(SlotGroup instance) {
var slots = instance.getSlots();
List<ISlot> result = new ArrayList<>();

for (var slot : slots) {
if (slot.bogo$canTakeStack(player)) result.add(slot);
}
return result;
}
}
12 changes: 12 additions & 0 deletions src/main/resources/mixins.nomilabs.bogosorter.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit 3e5c0ab

Please sign in to comment.