Skip to content

Commit

Permalink
Some more fixes to try and squash dupes.
Browse files Browse the repository at this point in the history
Signed-off-by: cpw <cpw+github@weeksfamily.ca>
  • Loading branch information
cpw committed Jun 17, 2024
1 parent f375e1b commit e648458
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/main/java/cpw/mods/inventorysorter/InventoryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.google.common.primitives.*;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.Slot;

import java.lang.reflect.*;
Expand Down Expand Up @@ -214,4 +216,11 @@ void addSlot(final Slot sl) {

}
}

static final ResourceLocation DUMMY_PLAYER_CONTAINER = ResourceLocation.parse("inventorysorter:dummyplayercontainer");

static ResourceLocation lookupContainerTypeName(AbstractContainerMenu container) {
return container instanceof InventoryMenu ? DUMMY_PLAYER_CONTAINER : BuiltInRegistries.MENU.getKey(container.getType());
}

}
3 changes: 1 addition & 2 deletions src/main/java/cpw/mods/inventorysorter/ItemStackHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public int hashCode()
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof ItemStackHolder)) return false;
ItemStackHolder ish = (ItemStackHolder)obj;
if (!(obj instanceof final ItemStackHolder ish)) return false;
return is.getItem() == ish.is.getItem() && ItemStack.isSameItemSameComponents(is, ish.is);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

import net.minecraft.world.inventory.Slot;

import javax.annotation.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -67,8 +65,10 @@ else if (moveAmount > 0)

if (source == null) return;

if (InventorySorter.INSTANCE.isContainerBlacklisted(InventoryHandler.lookupContainerTypeName(context.slotMapping.container))) return; // Blacklist container screen
if (InventorySorter.INSTANCE.isSlotBlacklisted(source)) return; // Blacklist source
if (InventorySorter.INSTANCE.isSlotBlacklisted(context.slot)) return; // Blacklist target

if (!source.mayPickup(context.player)) return;
if (!source.mayPlace(is)) return;
final ItemStack sourceStack = InventoryHandler.INSTANCE.getItemStack(source);
Expand Down Expand Up @@ -137,7 +137,7 @@ else if (ItemStack.isSameItem(itemStack,sourceStack))
InventoryHandler.INSTANCE.moveItemToOtherInventory(context, iscopy, mappingCandidate.begin, mappingCandidate.end+1, moveAmount < 0);
if (iscopy.getCount() == 0)
{
sourceStack.grow(-1);
sourceStack.shrink(1);
source.set(sourceStack);
break;
}
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/cpw/mods/inventorysorter/SortingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
package cpw.mods.inventorysorter;

import com.google.common.collect.*;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.resources.ResourceLocation;
import org.apache.logging.log4j.*;

import javax.annotation.*;
import java.util.function.*;

import net.minecraft.world.inventory.CraftingContainer;
Expand All @@ -39,7 +35,7 @@ public enum SortingHandler implements Consumer<ContainerContext>
{
INSTANCE;
@Override
public void accept(ContainerContext context)
public void accept(@SuppressWarnings("ClassEscapesDefinedScope") ContainerContext context)
{
if (context == null) throw new NullPointerException("WHUT");
// Ignore if we can't find ourselves in the slot set
Expand Down Expand Up @@ -115,7 +111,7 @@ private void distributeInventory(final ContainerContext context, final Multiset<
}
private void compactInventory(final ContainerContext context, final Multiset<ItemStackHolder> itemcounts)
{
final ResourceLocation containerTypeName = lookupContainerTypeName(context.slotMapping.container);
final ResourceLocation containerTypeName = InventoryHandler.lookupContainerTypeName(context.slotMapping.container);
InventorySorter.INSTANCE.lastContainerType = containerTypeName;
if (InventorySorter.INSTANCE.isContainerBlacklisted(containerTypeName)) {
InventorySorter.INSTANCE.debugLog("Container {} blacklisted", ()->new String[] {containerTypeName.toString()});
Expand Down Expand Up @@ -167,9 +163,4 @@ private void compactInventory(final ContainerContext context, final Multiset<Ite
}
}
}

private static final ResourceLocation DUMMY_PLAYER_CONTAINER = ResourceLocation.parse("inventorysorter:dummyplayercontainer");
private ResourceLocation lookupContainerTypeName(AbstractContainerMenu container) {
return container instanceof InventoryMenu ? DUMMY_PLAYER_CONTAINER : BuiltInRegistries.MENU.getKey(container.getType());
}
}

0 comments on commit e648458

Please sign in to comment.