|
12 | 12 | import gregtech.api.items.OreDictNames; |
13 | 13 | import gregtech.api.items.gui.ItemUIFactory; |
14 | 14 | import gregtech.api.items.gui.PlayerInventoryHolder; |
15 | | -import gregtech.api.items.metaitem.stats.IEnchantabilityHelper; |
16 | | -import gregtech.api.items.metaitem.stats.IFoodBehavior; |
17 | | -import gregtech.api.items.metaitem.stats.IItemBehaviour; |
18 | | -import gregtech.api.items.metaitem.stats.IItemCapabilityProvider; |
19 | | -import gregtech.api.items.metaitem.stats.IItemColorProvider; |
20 | | -import gregtech.api.items.metaitem.stats.IItemComponent; |
21 | | -import gregtech.api.items.metaitem.stats.IItemContainerItemProvider; |
22 | | -import gregtech.api.items.metaitem.stats.IItemDurabilityManager; |
23 | | -import gregtech.api.items.metaitem.stats.IItemMaxStackSizeProvider; |
24 | | -import gregtech.api.items.metaitem.stats.IItemNameProvider; |
25 | | -import gregtech.api.items.metaitem.stats.IItemUseManager; |
26 | | -import gregtech.api.items.metaitem.stats.ISubItemHandler; |
27 | | -import gregtech.api.recipes.ingredients.IntCircuitIngredient; |
| 15 | +import gregtech.api.items.metaitem.stats.*; |
28 | 16 | import gregtech.api.unification.OreDictUnifier; |
29 | 17 | import gregtech.api.unification.material.Material; |
30 | 18 | import gregtech.api.unification.ore.OrePrefix; |
@@ -199,18 +187,17 @@ protected String formatModelPath(T metaValueItem) { |
199 | 187 |
|
200 | 188 | protected int getModelIndex(ItemStack itemStack) { |
201 | 189 | T metaValueItem = getItem(itemStack); |
| 190 | + Objects.requireNonNull(metaValueItem); |
202 | 191 |
|
203 | | - // Electric Items |
204 | | - IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null); |
205 | | - if (electricItem != null) { |
206 | | - return (int) Math.min(((electricItem.getCharge() / (electricItem.getMaxCharge() * 1.0)) * 7), 7); |
207 | | - } |
| 192 | + var modelDispatcher = metaValueItem.getItemModelDispatcher(); |
| 193 | + if (modelDispatcher == null) return 0; |
208 | 194 |
|
209 | | - // Integrated (Config) Circuit |
210 | | - if (metaValueItem != null) { |
211 | | - return IntCircuitIngredient.getCircuitConfiguration(itemStack); |
212 | | - } |
213 | | - return 0; |
| 195 | + int maxIndex = metaValueItem.getModelAmount() - 1; |
| 196 | + int index = modelDispatcher.getModelIndex(itemStack, maxIndex); |
| 197 | + Validate.inclusiveBetween(0, maxIndex, index, |
| 198 | + "Model index should be in range from 0 to %d (inclusive), where %d is supplied", maxIndex, index); |
| 199 | + |
| 200 | + return index; |
214 | 201 | } |
215 | 202 |
|
216 | 203 | @SideOnly(Side.CLIENT) |
@@ -787,6 +774,7 @@ public MetaItem<T> getMetaItem() { |
787 | 774 | private IItemColorProvider colorProvider; |
788 | 775 | private IItemDurabilityManager durabilityManager; |
789 | 776 | private IEnchantabilityHelper enchantabilityHelper; |
| 777 | + private IItemModelDispatcher itemModelDispatcher; |
790 | 778 | private EnumRarity rarity; |
791 | 779 |
|
792 | 780 | private int burnValue = 0; |
@@ -927,6 +915,9 @@ protected void addItemComponentsInternal(IItemComponent... stats) { |
927 | 915 | if (itemComponent instanceof IEnchantabilityHelper) { |
928 | 916 | this.enchantabilityHelper = (IEnchantabilityHelper) itemComponent; |
929 | 917 | } |
| 918 | + if (itemComponent instanceof IItemModelDispatcher iItemModelDispatcher) { |
| 919 | + this.itemModelDispatcher = iItemModelDispatcher; |
| 920 | + } |
930 | 921 | this.allStats.add(itemComponent); |
931 | 922 | } |
932 | 923 | } |
@@ -987,6 +978,11 @@ public IEnchantabilityHelper getEnchantabilityHelper() { |
987 | 978 | return enchantabilityHelper; |
988 | 979 | } |
989 | 980 |
|
| 981 | + @Nullable |
| 982 | + public IItemModelDispatcher getItemModelDispatcher() { |
| 983 | + return itemModelDispatcher; |
| 984 | + } |
| 985 | + |
990 | 986 | public int getBurnValue() { |
991 | 987 | return burnValue; |
992 | 988 | } |
|
0 commit comments