Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.10.2] CreativeTab Sort using Class reference instead of Item Instance


Recommended Posts

So I have my code set up such that (following diesieben07's tutorial here) I have the ordering list setup, and it works just fine, but I have to use individual Item references in order to get all of my blocks in the ordering list.  My question is, since a good number of them are instances of just a few classes, is it possible to send a reference to the class into the sorter instead of having to list every one by itself?

For example:

Spoiler

List<Item> order = Arrays.asList(Item.getItemFromBlock(PCBlocks.glowClothAcid), Item.getItemFromBlock(PCBlocks.glowClothCryonite),
	Item.getItemFromBlock(PCBlocks.glowClothNeptunium), Item.getItemFromBlock(PCBlocks.glowClothNetherflow),
	Item.getItemFromBlock(PCBlocks.glowClothObsidium), Item.getItemFromBlock(PCBlocks.glowClothPlutonium),
	Item.getItemFromBlock(PCBlocks.glowClothRadionite), Item.getItemFromBlock(PCBlocks.glowClothUranium),
	Item.getItemFromBlock(PCBlocks.oreLead), Item.getItemFromBlock(PCBlocks.oreNeptunium), Item.getItemFromBlock(PCBlocks.oreObsidium),
	Item.getItemFromBlock(PCBlocks.orePlutonium), Item.getItemFromBlock(PCBlocks.oreRadionite), Item.getItemFromBlock(PCBlocks.oreUranium),
	Item.getItemFromBlock(PCBlocks.frozenCryonite), Item.getItemFromBlock(PCBlocks.reinforcedGlass),
	/*Item.getItemFromBlock(PCBlocks.acidTnt),*/ Item.getItemFromBlock(PCBlocks.acidBarrier),
	PCItems.GOOP, PCItems.INGOTS, PCItems.VIALS /*PCItems.causticBoat,
	PCItems.battery, PCItems.beamSplitter, PCItems.energyCell*/, PCItems.THERMOPELLET,
	PCItems.ACID_GUN/*, PCItems.cryoblaster, PCItems.lasershotgun, PCItems.lasergun, PCItems.lasergunsplit, PCItems.plasmagun, PCItems.plasmagunsplit, PCItems.railgun,
	PCItems.acidGrenade, PCItems.hazmatBoots, PCItems.hazmatHood, PCItems.hazmatJacket, PCItems.hazmatPants, PCItems.plasmaLeather*/);

tabSorter = Ordering.explicit(order).onResultOf(new Function<ItemStack, Item>() {
	@Override
	public Item apply(ItemStack input)
	{
		return input.getItem();
	}
});

 

All of those glowcloths listed first.  It would cut down my code by 7 references if I could just use the BlockGlowCloth class as the sorting element instead of all these instances.  I initially moved away from the metadata block process because it seemed unnecessary anymore.  Is having them be subitems on an ItemBlock the only option I have?

Link to post
Share on other sites

No, because those references are to instantiated objects. You have no way of passing a class to anything and get back that instance. You simply can't do it.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

whipped this up on the fly, have no idea if this will work, and I don't like the way it works (the getting class part), but try it out anyways:

//put this into your creativetab instance
@Override
public void displayAllRelevantItem(NonNullList<ItemStack> itemsToDisplay){
	List<Item> l = StreamSupport.stream(Item.REGISTRY.spliterator(), false).filter(yourPredicate())
      .collect(Collectors.<Item>toList());
  	
  	l.sort( (Item i, Item j) ->
           i.getClass().getSuperclass().getName().compareTo(j.getClass().getSuperclass().getName() ));
  		
  	l.forEach( i -> i.getSubItems(i, this, itemsToDisplay));
}

private Predicate<Item> yourPredicate(){
	return i -> i != null && i.getCreativeTab() == this;
}

Even if this does work, I don't think I will cause of the .getClass.getSuperclass.getName() part, you still should try to avoid using it; the getting class name parts is usually a very bad idea. You could try making your own comparitor, and try to work something out from there. Not sure it this helps, but better than nothing, and hopefully it sparks your imagination towards a very creative means to an end. Good luck.

Edited by draganz
Link to post
Share on other sites

Here's another idea that you could use, if this is that important to you: (1) you get a list of all of your items. This could be done via the Item.REGESTRY method I provided in my above example, or you just making your own static list, then having your items register themselves to said list upon initialization. (2) have an enum, with specific sorting types (see provided example). (3) Have your item classes return a specific (or a default) enum type. (4) upon the creative gui sorting through all of your stuff to display via the desplayAllRelevantItem method, you have your items to display sort based on the enum ordinal. Example below (my not be functional, but should give the general idea):

//////////in your creative tab instance///////////
@Override
public void displayAllRelevantItem(NonNullList<ItemStack> itemsToDisplay){
	ModItemes.YOUR_ITEMS.stream().filter(yourPredicate()).forEach(i -> i.getSubItems(i, this, itemsToDisplay)); 
}

private Predicate<Item> yourPredicate(){
	return i -> i != null && i.getCreativeTab() == this;
}
/////////////Your Item Registry Location///////////
public class ModItems{
  //NOTE:For this class, in your  mods preinitialization stage, you should call the init() method
  
  
  public static final List<ItemBase> YOUR_ITEMS = new ArrayList();
  
  /*Register your static final Items here. Since they are static, they to will have the ability to say use 
  ModItems.YOUR_ITEMS.add(this) in their constructers in order to self initializes themselves to the list, order 
  you state them desiding in what order*/
  
  public static void init(){
    YOUR_ITEMS.sort( (ItemBase i, ItemBase j) -> i.getSortOrder() - j.getSortOrder() );
  }
}
/////////ItemBase class, is used as a starting point for all your items////////////
public abstract class ItemBase extends Item{
  
  private final SortEnum SORT_ORDER;//have this initialized in a constructer
  
  ///....various code you would otherwise put here
  public int getSortOrder(){
    return SORT_ORDER.ordinal;
  }
}
/////the enum
public enum SortEnum{
  APPLE,ORANGES,PLUMS;/*it doesn't matter what values these are, just the integer (ordinal) value they provide. 
  Depending of if you have (itemOne - itemTwo) or (itemTwo - itemOne) will alter the order that these are sorted by. 
  Beyond that, it will be the order of initialization, then should meta types come into play, they the getSubItems 
  method will determine.*/
}

 

Edited by draganz
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • protected static final DimensionType NETHER_TYPE = new DimensionType(OptionalLong.of(18000L), false, true, true, false, 8.0D, false, true, false, true, false, 128, FuzzedBiomeMagnifier.INSTANCE, BlockTags.INFINIBURN_NETHER.getName(), THE_NETHER_ID, 0.1F); This code in DimensionType class. I found that 8.0D its what i need but i dosent know how to change this or override nether_type. If mod with same functionality exist you can give me url (i need it for my mod pack).
    • Please post your server log, it should give a clue what's going on.
    • It looks like you may be trying to reply to someone's support post, you instead you created a new one.
    • compactstorage-1.16.5-5.1b17.jarcarryon-1.16.5-1.15.5.15.jarAdHooks-1.16.4-6.1.5.0-build.0124.jarXaerosWorldMap_1.14.1_Forge_1.16.5.jarXaeros_Minimap_21.10.0.3_Forge_1.16.5.jartrashcans-1.0.10-mc1.16.5.jarSuperTools-1.2_1.16.5.jarSpartanShields-1.16.5-2.1.2.jarrandomite-1.16.4-1.0.1.jaroverloadedarmorbar-5.1.0.jaroresplusmod_1.16.5,0.1.0.jarturtle_armor-1.3.4.jartoyguns-0.1-1.16.4.jartoughnessbar-6.1.jartorchmaster-2.3.7.jarToast-Control-1.16.4-4.3.1.jartitanium-1.16.5-3.2.8.4-10.jarthermal_expansion-1.16.4-1.2.0.jartheoneprobe-1.16-3.1.4.jarthedragonlib-1.16.3-1.1.0.jarswingthroughgrass-1.16.4-1.5.3.jarsuper+armor-5.0.4(EN).jarStorageDrawers-1.16.3-8.2.2.jarsteveGolemMod_1.3.0.jarSteelArmory.jarSoulBound-1.1.3-1.16.5.jarSimplyBetter.jarSimple guns reworked 1.16.5 v1.4.jarsilent-lib-1.16.3-4.9.6.jarRunelic-1.16.5-7.0.1.jarrftoolsbase-1.16-2.0.10.jarReAuth-1.16-Forge-3.9.3.jarrandompatches-2.4.4-forge.jarprecious_armor-1.16.5.jarPlacebo-1.16.4-4.5.0.jarPatchouli-1.16.4-51.jaroverloadedarmorbar-5.1.0.jarOreExcavation-1.8.157.jarOp Armor Plus 1.16.5 0.6.jarobserverlib-1.16.5-1.5.3.jarobfuscate-0.6.2-1.16.3.jarnetheritehorsearmor-1.7.jarNeat 1.7-27.jarNaturesCompass-1.16.5-1.9.0.jarMouseTweaks-2.14-mc1.16.2.jarMorpheus-1.16.5-4.2.70.jarMoreOresArmorsAndTools 1.2.5.jarMoreArmor-1-4-0.jarMekanismTools-1.16.5-10.0.21.448.jarMekanismGenerators-1.16.5-10.0.21.448.jarmcjtylib-1.16-5.0.19.jarMantle-1.16.5-1.6.103.jarMachineBoy's ArmorTool v1.2b1.jarJustEnoughResources-1.16.5-0.12.1.121.jarJEITweaker-1.16.5-1.0.1.28.jarjei-1.16.5-7.7.0.106.jarJ0T0S0 Weapons 1.0.0.jarironchest-1.16.4-11.2.10.jarillagersweararmor-1.0.4.jariChunUtil-1.16.5-10.4.1.jarhitscan-1.0.1.jarHandyGuns2.0.jargunswithoutroses-1.16.5-1.0.9.jarGuns'N'Glory-2.0.jarGuns and Rifes.jarftb-backups-2.1.1.6.jarForgeEndertech-1.16.4-7.1.0.0-build.0075.jarFluxNetworks-1.16.5-6.1.7.12.jarFastWorkbench-1.16.4-4.5.1.jarFastLeafDecay-v25.jarFastFurnace-1.16.4-4.4.0.jarfabric-api-0.35.0+1.16.jarExtraArmor-1.12.1-1.16.5.jarEnderStorage-1.16.4-2.7.1.166-universal.jarEnchantmentDescriptions-1.16.5-7.0.8.jarEnameledArmor-1.16.2-1.0.0.8.jaremeraldtoolsandarmor1.16.x.jarEmeraldArmorAndTools.jarelevatorid-1.16.5-1.7.13.jarDiceMC-TieredArmor-1.16.5-1.1a.jarDefaultOptions_1.16.5-12.2.1.jarDecraftHorseArmor-1.16.5-r1.jarDarkUtilities-1.16.5-8.0.10.jarCyclopsCore-1.16.5-1.11.7.jarCurious Armor Stands-1.16.5-2.1.1.jarcurios-forge-1.16.5-4.0.5.2.jarCucumber-1.16.4-4.1.10.jarCTM-MC1.16.1-1.1.2.6.jarCraftingTweaks_1.16.5-12.2.1.jarCraftableChainmail-1.16.5-1.1.0.jarcraftable_chainmail_1.16.5.jarOresAboveDiamonds-1.16.4-v6.3.3.jarCraftable Saddle and Horse Armors.jarCosmeticArmorReworked-1.16.5-v3a.jarCookingForBlockheads_1.16.5-9.3.2.jarControlling-7.0.0.23.jarcomforts-forge-1.16.5-4.0.0.4.jarColtCosmeticArmorMod-1.2.5.jarCodeChickenLib-1.16.4-3.5.1.408-universal.jarClumps-6.0.0.25.jarcitadel-1.7.1-1.16.5.jarchiselsandbits-0.3.4-RELEASE.jarcarryon-1.16.5-1.15.5.15.jarbuildinggadgets-1.16.5-3.8.0.jarBookshelf-1.16.5-10.1.11.jarBomb and guns.jarBlockArmor-1.16.5-2.6.2.jarBetterMineshafts-Forge-1.16.4-2.0.4.jarBetterHorseArmor-1.16.3-1.0.1.1.jarBetterAdvancements-1.16.5-0.1.0.108.jarBedrock Armor 1.16.5-1.0.2.jarAutoRegLib-1.6-49.jararmor-visibility-2.0.1-forge.jarArmorUp-1.0.5-BETA.jarArmorUnlocked-1.16.3-1.0.1.jararmorunder-mc1.16.5-2.0b11.jararmor-stand-editor-1.1.0.jarArmorPoser-1.16.5-1.0.1.jararmorpointspp-1.16.5-2.0.0.jararmorhotswap-1.16-1.8.jarArmoredElytra-1.0.8.jararmorcurve-2.3.jarAquaculture-1.16.5-2.1.19.jarAppleSkin-mc1.16.2-forge-1.0.14.jarApotheosis-1.16.4-4.6.1.jarAncientGuns_3.2_1.16.4.jarAkashicTome-1.4-16.jar1.7.4.1-1.16.5ATOp.jar[1.16.5] BobLib-0.2.0.jar[1.16.5] Armor Status HUD-1.4.0.jarEmerald armor and tools 1.15.16 v3.jarYungsApi-1.16.4-Forge-6.jaryeni modum.jarxnet-1.16-3.0.13.jarwolveswitharmor-1.1.0-1.16.2.jarWaystones_1.16.5-7.6.2.jarvisiblearmorslots-2.0-1.16.5.jarNeat 1.7-27.jarNaturesCompass-1.16.5-1.9.0.jarMoreOresInONE-1.2_1.16.5.jarmcw-windows-1.0.3-mc1.16.5.jarmcw-bridges-1.0.5-mc1.16.5-4.jarlongfallboots-1.6.0a.jarJustEnoughResources-1.16.5-0.12.1.121.jarjei-1.16.5-7.7.0.106.jarForgeEndertech-1.16.4-7.1.0.0-build.0075.jarextcaves-2.4.jarcurios-forge-1.16.5-4.0.5.2.jarcorpse-1.16.5-1.0.5.jarAdHooks-1.16.4-6.1.5.0-build.0124.jar
    • Dude, then try to click the down arrow near "Open" then select   Java(TM) Platform SE binary then it should work or if it doesn't work then it means you don't have Java or you computer is broken.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.