Colossal Chests

Colossal Chests

26M Downloads

Inventory Tweaks sorting support

NovaViper opened this issue ยท 39 comments

commented

Hey, could you possible make the chests be able to be sorted by the Crafting Tweaks/Inventory Tweaks mod?

commented

Oh, I didn't realize that, but whenever I try to use the middle mouse button to sort, it just pulls the items to fill in empty spaces, not sort the actual items by the default settings.

commented

@NovaViper Do you see the invtweaks buttons in the gui? Do those work?

commented

I do and yeah, I've tried those as well. I can get it line up vertically and horizontally, but can't get the items to actual sort by their characteristics based in the default settings

commented

Try reporting to the Inv Tweaks issue tracker.

commented

Just sent the issue to them

commented

@Kobata Does your API provide a way to sort on a custom list of items? If so, I can probably hook that in.

commented

Hey I just got a response back

Kobata commented 2 hours ago.
From a quick look at that mod, since I'm not very familiar with it, it doesn't appear to be very friendly to the way Inventory Tweaks does sorting -- with the scrollbars there's a big mismatch between what the mod probably knows about (all the items) and what it can actually interact with (what's currently visible).
I don't expect sorting to work well with it at all.

So it seems to be something on this mod's side.

commented

I'll throw a more detailed thing here: Inventory Tweaks (for reasons including working on non-modded servers) works by sending click commands more or less as-if you physically clicked the mouse (just really fast), so it can only really work on items that are visible on screen, and as such doesn't work very well for things so large they have to resort to scrolling and only showing parts of the contents at a time.

commented

Ok, in that case it's going to be a wontfix.

@Kobata If you ever would add a custom hook for sorting, let me know ;-)

commented

@rubensworks There kinda is? You can do what AE does and do your own sorting using the ordering in the API.

Note that like the rest of the API that's only available client-side, so if you want it to actually persist and not just be a local 'remapping' it's up to you to do the client-server communication.

commented

@Kobata Oh ok, in that case I misunderstood you.
Could you point me to the location in the API for that?

commented

No, and it's not really about that -- it would know about all the items already if I understand it right (because there's slots) -- but it can't interact with them (because not all of them are visible at the same time)

commented

Hey, you might be able to add a sort of checking method that scans the number of visible slots on the screen and with each time you scroll, have the mod execute the checking method again and then send that data to Inventory Tweaks (In theory that is)

commented

https://github.com/Inventory-Tweaks/inventory-tweaks/blob/develop/src/main/java/invtweaks/api/InvTweaksAPI.java#L70

The sort one below won't do what you want, that's just a way of programatically starting the normal Invtweaks sort.

I'll add an extra note that the comparison may not be suitable for use with Java's built-in sorts -- sometimes it seems to get slightly confused as to whether or not an item belongs before or after another item.

commented

See Inventory-Tweaks/inventory-tweaks#397 about the possible comparison order thing -- I haven't managed to get into putting enough debug in to track it down.

commented

after getting some error while Kobata's Inventory Tweaks mod with your mod, I checked with Kobata and he found some codes that not working well;
`at org.cyclops.colossalchests.inventory.container.ContainerColossalChest.getContainerSelection(ContainerColossalChest.java:306)

at org.cyclops.colossalchests.inventory.container.ContainerColossalChest.invtweaks$slotMap(ContainerColossalChest.java)`

And he found an error (maybe unrelated); "error in the code to delay messages until a world's loaded, that's making the messages keep appearing more than they should?"

Please advice.

commented

@KusanagiRyu If it's a crash, I'll need the full log. And if so, please create a separate issue for that.

I don't think I understand your latest sentence. This mod is not doing anything related to delaying messages.

commented

That second comment was about my error outputs, the log he posted to me had a whole bunch of them without any obvious related exception.

commented

And I'll throw you the link he gave me too: https://drive.google.com/file/d/0BxtS3Obx6GxjMmpadkFReUNYSWc/view?usp=sharing

java.lang.IndexOutOfBoundsException: Index: 9027, Size: 9027
	at java.util.ArrayList.rangeCheck(ArrayList.java:653)
	at java.util.ArrayList.get(ArrayList.java:429)
	at net.minecraft.inventory.Container.func_75139_a(Container.java:113)
	at org.cyclops.colossalchests.inventory.container.ContainerColossalChest.getContainerSelection(ContainerColossalChest.java:306)
	at org.cyclops.colossalchests.inventory.container.ContainerColossalChest.invtweaks$slotMap(ContainerColossalChest.java)
	at invtweaks.InvTweaksObfuscation.getContainerSlotMap(InvTweaksObfuscation.java)
	at invtweaks.container.DirectContainerManager.initSlots(DirectContainerManager.java:37)
	at invtweaks.container.DirectContainerManager.<init>(DirectContainerManager.java:33)
	at invtweaks.InvTweaks.getContainerManager(InvTweaks.java:143)
	at invtweaks.InvTweaks.getCurrentContainerManager(InvTweaks.java:148)
	at invtweaks.container.ContainerSectionManager.<init>(ContainerSectionManager.java:23)
	at invtweaks.InvTweaksGuiSettingsButton.func_146116_c(InvTweaksGuiSettingsButton.java:48)
	at net.minecraft.client.gui.GuiScreen.func_73864_a(GuiScreen.java:452)
	at net.minecraft.client.gui.inventory.GuiContainer.func_73864_a(GuiContainer.java:320)
	at org.cyclops.cyclopscore.client.gui.container.ScrollingGuiContainer.func_73864_a(ScrollingGuiContainer.java:127)
	at net.minecraft.client.gui.GuiScreen.func_146274_d(GuiScreen.java:548)
	at org.cyclops.cyclopscore.client.gui.container.ScrollingGuiContainer.func_146274_d(ScrollingGuiContainer.java:111)
	at net.minecraft.client.gui.GuiScreen.func_146269_k(GuiScreen.java:517)
	at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1700)
	at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1055)
	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:371)
	at net.minecraft.client.main.Main.main(SourceFile:124)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
commented

Seems to be #77.
Could you provide more details there if the latest release (0.5.1) is still causing that crash?

commented

there's no CTD at all... it just give me error message whenever i sort with and of the colossal chests and sorting doesn't work.

Edit: Sorry, that error was for 1.5.0, before you released the latest one. now it CTD whenever i press the sort button. I have created another "Issue" thread, Issue #80 .

commented

i honestly think all of this could be easly solved by creating a custom sorting button inside the chest, trying to make something that is not supposed to work on scrollable inventories isn't really gonna work (sorry @Kobata )
the only things is to make sure that this algorithm doesn't make items disappear at random, maybe comparing the raw number of items from before and after and if it isn't equal it cancels?
(not the slots number because that can change)

commented

So is there going to be some sort of support between these mods (1.10.2)? At the moment when I try to sort things by rows or columns, the chat gets an error message saying "InvTweaks [ERROR] [3] Failed to sort container: null (l101 in HandlerSorting.java)" and as previously said nothing seems to actually "sort", empty slots just get filled when using the default sort. I'd love to see these mods work together even if it would work only when the server also has both of the mods. I'll honestly program the feature myself if you just tell me how exactly it should be done. So my question is, is this going anywhere?

commented

@rubensworks I understand. How about making your own sorting method for the newer versions then since the way InvTweaks is programmed doesn't really work with scrollable containers? I'll be changing versions anyway once the mods I use get updated. I just feel like being able to sort the colossal chests would improve the mod immensely. I think it could be done with @Kobata 's sorting list as a base but then just modify it to change the container's slots directly so it would be like an inbuilt InvTweaks. If you're both up for this collab of a sort I think it would work out pretty well in the end. If you lack manpower I have experience in Java and have always wanted to try out making a mod for Minecraft.

commented

If you lack manpower

That's the problem indeed. I am maintaining quite a few mods at the moment, for which bugfixes have a priority. I don't have a lot of time left for new features and enhancements unfortunately. But if you're up for it, a PR for this would be more than welcome.

commented

@rubensworks Great, I'd love to try it out. I just want @Kobata 's blessing for this as well since what I'm planning is basically a port.

commented

@Santtinen This is not on my roadmap at the moment, so this is not coming any time soon. (Definitely not for 1.10, as 1.12 is the main target now)

But I'm open to PRs.

commented

If you read my comments above, you don't really need to do a 'port' (the full sorting code is massively overkill anyway, a lot of what it does is for handling features that only work on the player inventory) -- just hook the comparison to a fairly standard sort, albeit be careful of the potential bug listed above.

If you do hit that bug information on the specific pair of items would be nice so see why it breaks, though.

commented

@Kobata Well, I didn't mean like a full port. Just the default sort button for the chest since that is the one I believe people use the most. And instead of using the cursor for the sorting, the chest would just get sorted directly (since the server needs to have the mod anyway). That's basically what I'd like to do but since I basically have no idea what I'm doing if you have a better idea, do tell.

commented

There's only one (unified) sort in invtweaks, and it does a lot of stuff you really, really don't care about for this usage (which also makes it impossible to really use a 'normal' sort internally because it means there's nothing even resembling a real ordering when you can tell it to put the same item in two non-adjacent slots in the player inventory).

Like I said, for the specific case of mimicking the chest sort without worrying about the player's, just use a basic standard one, even if you write it yourself instead of using Java's, it'd be way faster than the total mess that is whatever you'd call how invtweaks does it itself.

Also, if you're hooking into invtweaks stuff you must do all comparisons solely client-side (you can sync the final list later or send movement/swap packets during the sort of something) -- the sort order depends on client configuration and the tiny server module doesn't even have a real implementation of everything available.

(e: I went and checked, the comparison function on the server setup will return 'equal' for all items It's total nosense but is just there to prevent it from outright crashing)

commented

@Kobata Alright I see what you mean. Guess I misspoke a little. What I mean is that I would like to use the way InvTweaks does sorting as in the order items should be in the chest. That is the part I wanted to port. It would look the same but work differently. This would mean that the compatibility with InvTweaks could just be removed.

commented

sorting as in the order items should be in the chest

Even this part, while there's a 'comparison function' available as an API function, is fundamentally dependent on client config files, since the first, overriding factor, is derived from the order items appear in this file, which can be edited by the user as well. (Items not included in that file fallback on other ordering, as does items that otherwise match -- see the comparison method)

While you can easily do 'sort based on name/sort based on id' things (and AE2's done that on its own for a while), the actual invtweaks ordering isn't really all that feasible to replicate without just asking what it is for each client.

commented

@Kobata So would it be possible to check the players itemtree.xml, make a new inventory with said changes and then tell the client/server to set it on the chest or would that just get too complicated?

commented

Would it be possible to make the InvTweaks sort button execute some other method than the InvTweaks one when in a colossal chest

Not directly, you'll need to make your own button (and just not use the things that make invtweaks add its own buttons).

commented

I see. A lot of stuff to figure out then. As soon as I'm done with this school year and get rid of this cold I'll start working on this properly. For now, all I can really do is planning.

commented

At that point you're already assuming the player has the file so you might as well just pull in the invtweaks interface and call the compare on that rather than trying to re-implement it (you can always use reflection to avoid a direct dependency at the cost of possibly being a bit slower -- you can get the object off of some FML function to call things on).

You will have to do something to sync if you want it to be visible to other clients though. I'm not sure building a complete inventory and sending that as a whole thing would be the best option though, as that seems rather open to exploitation or sync bugs causing dupes or deleting items. Maybe something like just sending a mapping of slot numbers so the server can rearrange itself?

The AE2 stuff mentioned way above doesn't bother, those sorts are client-only, but that works because of the nature of that mod a bit better than something that's trying to act more like an actual chest, I suppose.

commented

That is pretty much what I want to do, using InvTweaks compare and maybe use the interface and you are correct about the inventory... Hmm... Let's assume we have both Colossal Chests and InvTweaks installed. Would it be possible to make the InvTweaks sort button execute some other method than the InvTweaks one when in a colossal chest (like a sort method in the Colossal Chests mod)?

commented

The current compare function should be obeying the comparator contract. If you run into any troubles though, you may wish to borrow the "TheHuntForTheOffendingItems" functions from https://github.com/mezz/JustEnoughItems/blob/7d6f1062a49e477f72e736c761e287f5861f529f/src/main/java/mezz/jei/ingredients/IngredientListElementFactory.java which will help you find the 2 or 3 items that fail the tests. (Two for reflective property and 3 for transitive.)

GitHub
Item and Recipe viewing mod for Minecraft. Contribute to mezz/JustEnoughItems development by creating an account on GitHub.