That's one heck of a commit you've got there...
I may have got a bit behind with version control. A lot behind, in fact. Maybe I'll go back and split this sometime - then again, I probably won't. But hey, at least it's here!
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
package electroblob.wizardry.registry;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import electroblob.wizardry.item.ItemScroll;
|
||||
import electroblob.wizardry.item.ItemSpellBook;
|
||||
import electroblob.wizardry.spell.Spell;
|
||||
@@ -15,6 +10,10 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class responsible for defining and storing all of wizardry's creative tabs. Also handles sorting of the items.
|
||||
*
|
||||
@@ -23,111 +22,100 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
*/
|
||||
public final class WizardryTabs {
|
||||
|
||||
private static Comparator<ItemStack> itemSorter;
|
||||
private static Comparator<ItemStack> spellItemSorter;
|
||||
private WizardryTabs(){} // No instances!
|
||||
|
||||
// Creative Tabs
|
||||
public static final CreativeTabs WIZARDRY = new CreativeTabs("ebwizardry"){
|
||||
public static final CreativeTabs WIZARDRY = new CreativeTabListed("ebwizardry");
|
||||
public static final CreativeTabs GEAR = new CreativeTabListed("ebwizardrygear");
|
||||
public static final CreativeTabs SPELLS = new CreativeTabSorted("ebwizardryspells",
|
||||
|
||||
(stack1, stack2) -> {
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ItemStack createIcon(){
|
||||
return new ItemStack(WizardryItems.wizard_handbook);
|
||||
}
|
||||
if((stack1.getItem() instanceof ItemSpellBook && stack2.getItem() instanceof ItemSpellBook)
|
||||
|| (stack1.getItem() instanceof ItemScroll && stack2.getItem() instanceof ItemScroll)){
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void displayAllRelevantItems(NonNullList<ItemStack> items){
|
||||
super.displayAllRelevantItems(items);
|
||||
Collections.sort(items, itemSorter);
|
||||
}
|
||||
};
|
||||
Spell spell1 = Spell.byMetadata(stack1.getItemDamage());
|
||||
Spell spell2 = Spell.byMetadata(stack2.getItemDamage());
|
||||
|
||||
return spell1.compareTo(spell2);
|
||||
|
||||
}else if(stack1.getItem() instanceof ItemScroll){
|
||||
return 1;
|
||||
}else if(stack2.getItem() instanceof ItemScroll){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
true);
|
||||
|
||||
public static final CreativeTabs SPELLS = new CreativeTabs("ebwizardryspells"){
|
||||
public static class CreativeTabSorted extends CreativeTabs {
|
||||
|
||||
private ItemStack iconItem;
|
||||
private final Comparator<? super ItemStack> sorter;
|
||||
private final boolean searchable;
|
||||
|
||||
public CreativeTabSorted(String label, Comparator<? super ItemStack> sorter){
|
||||
this(label, sorter, false);
|
||||
}
|
||||
|
||||
public CreativeTabSorted(String label, Comparator<? super ItemStack> sorter, boolean searchable){
|
||||
super(label);
|
||||
this.sorter = sorter;
|
||||
this.searchable = searchable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ItemStack createIcon(){
|
||||
return new ItemStack(WizardryItems.spell_book);
|
||||
return iconItem;
|
||||
}
|
||||
|
||||
public void setIconItem(ItemStack iconItem){
|
||||
this.iconItem = iconItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void displayAllRelevantItems(NonNullList<ItemStack> items){
|
||||
super.displayAllRelevantItems(items);
|
||||
Collections.sort(items, spellItemSorter);
|
||||
items.sort(sorter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSearchBar(){
|
||||
return true;
|
||||
return searchable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getBackgroundImageName(){
|
||||
return "item_search.png";
|
||||
return searchable ? "item_search.png" : super.getBackgroundImageName();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class CreativeTabListed extends CreativeTabSorted {
|
||||
|
||||
/** Initialises the item sorters for the creative tabs. */
|
||||
public static void sort(){
|
||||
public final List<Item> order;
|
||||
|
||||
List<Item> orderedItemList = Arrays.asList(
|
||||
|
||||
Item.getItemFromBlock(WizardryBlocks.arcane_workbench),
|
||||
Item.getItemFromBlock(WizardryBlocks.crystal_ore), Item.getItemFromBlock(WizardryBlocks.crystal_block),
|
||||
Item.getItemFromBlock(WizardryBlocks.crystal_flower),
|
||||
Item.getItemFromBlock(WizardryBlocks.transportation_stone), WizardryItems.magic_crystal,
|
||||
WizardryItems.magic_wand, WizardryItems.apprentice_wand, WizardryItems.advanced_wand,
|
||||
WizardryItems.master_wand, WizardryItems.arcane_tome, WizardryItems.wizard_handbook,
|
||||
WizardryItems.basic_fire_wand, WizardryItems.basic_ice_wand, WizardryItems.basic_lightning_wand,
|
||||
WizardryItems.basic_necromancy_wand, WizardryItems.basic_earth_wand, WizardryItems.basic_sorcery_wand,
|
||||
WizardryItems.basic_healing_wand, WizardryItems.smoke_bomb, WizardryItems.firebomb,
|
||||
WizardryItems.poison_bomb, WizardryItems.blank_scroll, WizardryItems.identification_scroll,
|
||||
WizardryItems.mana_flask, WizardryItems.storage_upgrade, WizardryItems.siphon_upgrade,
|
||||
WizardryItems.condenser_upgrade, WizardryItems.range_upgrade, WizardryItems.duration_upgrade,
|
||||
WizardryItems.cooldown_upgrade, WizardryItems.blast_upgrade, WizardryItems.attunement_upgrade,
|
||||
WizardryItems.magic_silk, WizardryItems.armour_upgrade, WizardryItems.wizard_hat,
|
||||
WizardryItems.wizard_robe, WizardryItems.wizard_leggings, WizardryItems.wizard_boots,
|
||||
WizardryItems.wizard_hat_fire, WizardryItems.wizard_robe_fire, WizardryItems.wizard_leggings_fire,
|
||||
WizardryItems.wizard_boots_fire, WizardryItems.wizard_hat_ice, WizardryItems.wizard_robe_ice,
|
||||
WizardryItems.wizard_leggings_ice, WizardryItems.wizard_boots_ice, WizardryItems.wizard_hat_lightning,
|
||||
WizardryItems.wizard_robe_lightning, WizardryItems.wizard_leggings_lightning,
|
||||
WizardryItems.wizard_boots_lightning, WizardryItems.wizard_hat_necromancy,
|
||||
WizardryItems.wizard_robe_necromancy, WizardryItems.wizard_leggings_necromancy,
|
||||
WizardryItems.wizard_boots_necromancy, WizardryItems.wizard_hat_earth, WizardryItems.wizard_robe_earth,
|
||||
WizardryItems.wizard_leggings_earth, WizardryItems.wizard_boots_earth, WizardryItems.wizard_hat_sorcery,
|
||||
WizardryItems.wizard_robe_sorcery, WizardryItems.wizard_leggings_sorcery,
|
||||
WizardryItems.wizard_boots_sorcery, WizardryItems.wizard_hat_healing, WizardryItems.wizard_robe_healing,
|
||||
WizardryItems.wizard_leggings_healing, WizardryItems.wizard_boots_healing);
|
||||
|
||||
itemSorter = (stack1, stack2) -> {
|
||||
// Neither stack is in the creative tab
|
||||
if(!orderedItemList.contains(stack1.getItem()) && !orderedItemList.contains(stack2.getItem())) return 0;
|
||||
if(!orderedItemList.contains(stack1.getItem())) return 1; // Only stack 2 is in the creative tab
|
||||
if(!orderedItemList.contains(stack2.getItem())) return -1; // Only stack 1 is in the creative tab
|
||||
// Both stacks are in the creative tab
|
||||
return orderedItemList.indexOf(stack1.getItem()) - orderedItemList.indexOf(stack2.getItem());
|
||||
};
|
||||
|
||||
spellItemSorter = (stack1, stack2) -> {
|
||||
|
||||
if((stack1.getItem() instanceof ItemSpellBook && stack2.getItem() instanceof ItemSpellBook)
|
||||
|| (stack1.getItem() instanceof ItemScroll && stack2.getItem() instanceof ItemScroll)){
|
||||
|
||||
Spell spell1 = Spell.get(stack1.getItemDamage());
|
||||
Spell spell2 = Spell.get(stack2.getItemDamage());
|
||||
|
||||
return spell1.compareTo(spell2);
|
||||
|
||||
}else if(stack1.getItem() instanceof ItemScroll){
|
||||
return 1;
|
||||
}else if(stack2.getItem() instanceof ItemScroll){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
public CreativeTabListed(String label){
|
||||
// Can't accomplish this in a single constructor... just a quirk of the java compiler!
|
||||
this(label, new ArrayList<>());
|
||||
}
|
||||
|
||||
// Hey, maybe someone might want to keep a reference to the list, or pass in a different one.
|
||||
public CreativeTabListed(String label, List<Item> order){
|
||||
|
||||
super(label, (stack1, stack2) -> {
|
||||
// Neither stack is in the creative tab
|
||||
if(!order.contains(stack1.getItem()) && !order.contains(stack2.getItem())) return 0;
|
||||
if(!order.contains(stack1.getItem())) return 1; // Only stack 2 is in the creative tab
|
||||
if(!order.contains(stack2.getItem())) return -1; // Only stack 1 is in the creative tab
|
||||
// Both stacks are in the creative tab
|
||||
return order.indexOf(stack1.getItem()) - order.indexOf(stack2.getItem());
|
||||
});
|
||||
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user