Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/gregtech/api/items/metaitem/ElectricStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.List;

public class ElectricStats implements IItemComponent, IItemCapabilityProvider, IItemMaxStackSizeProvider,
IItemBehaviour, ISubItemHandler {
IItemBehaviour, ISubItemHandler, IItemModelDispatcher {

public static final ElectricStats EMPTY = new ElectricStats(0, 0, false, false);

Expand Down Expand Up @@ -217,4 +217,14 @@ public static ElectricStats createRechargeableBattery(long maxCharge, int tier)
public static ElectricStats createBattery(long maxCharge, int tier, boolean rechargeable) {
return new ElectricStats(maxCharge, tier, rechargeable, true);
}

@Override
public int getModelIndex(ItemStack itemStack, int maxIndex) {
IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (electricItem != null) {
return (int) Math.min(((electricItem.getCharge() / (electricItem.getMaxCharge() * 1.0)) * maxIndex),
maxIndex);
}
return 0;
}
}
42 changes: 19 additions & 23 deletions src/main/java/gregtech/api/items/metaitem/MetaItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@
import gregtech.api.items.OreDictNames;
import gregtech.api.items.gui.ItemUIFactory;
import gregtech.api.items.gui.PlayerInventoryHolder;
import gregtech.api.items.metaitem.stats.IEnchantabilityHelper;
import gregtech.api.items.metaitem.stats.IFoodBehavior;
import gregtech.api.items.metaitem.stats.IItemBehaviour;
import gregtech.api.items.metaitem.stats.IItemCapabilityProvider;
import gregtech.api.items.metaitem.stats.IItemColorProvider;
import gregtech.api.items.metaitem.stats.IItemComponent;
import gregtech.api.items.metaitem.stats.IItemContainerItemProvider;
import gregtech.api.items.metaitem.stats.IItemDurabilityManager;
import gregtech.api.items.metaitem.stats.IItemMaxStackSizeProvider;
import gregtech.api.items.metaitem.stats.IItemNameProvider;
import gregtech.api.items.metaitem.stats.IItemUseManager;
import gregtech.api.items.metaitem.stats.ISubItemHandler;
import gregtech.api.recipes.ingredients.IntCircuitIngredient;
import gregtech.api.items.metaitem.stats.*;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.ore.OrePrefix;
Expand Down Expand Up @@ -199,18 +187,17 @@ protected String formatModelPath(T metaValueItem) {

protected int getModelIndex(ItemStack itemStack) {
T metaValueItem = getItem(itemStack);
Objects.requireNonNull(metaValueItem);

// Electric Items
IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (electricItem != null) {
return (int) Math.min(((electricItem.getCharge() / (electricItem.getMaxCharge() * 1.0)) * 7), 7);
}
var modelDispatcher = metaValueItem.getItemModelDispatcher();
if (modelDispatcher == null) return 0;

// Integrated (Config) Circuit
if (metaValueItem != null) {
return IntCircuitIngredient.getCircuitConfiguration(itemStack);
}
return 0;
int maxIndex = metaValueItem.getModelAmount() - 1;
int index = modelDispatcher.getModelIndex(itemStack, maxIndex);
Validate.inclusiveBetween(0, maxIndex, index,
"Model index should be in range from 0 to %d (inclusive), where %d is supplied", maxIndex, index);

return index;
}

@SideOnly(Side.CLIENT)
Expand Down Expand Up @@ -787,6 +774,7 @@ public MetaItem<T> getMetaItem() {
private IItemColorProvider colorProvider;
private IItemDurabilityManager durabilityManager;
private IEnchantabilityHelper enchantabilityHelper;
private IItemModelDispatcher itemModelDispatcher;
private EnumRarity rarity;

private int burnValue = 0;
Expand Down Expand Up @@ -927,6 +915,9 @@ protected void addItemComponentsInternal(IItemComponent... stats) {
if (itemComponent instanceof IEnchantabilityHelper) {
this.enchantabilityHelper = (IEnchantabilityHelper) itemComponent;
}
if (itemComponent instanceof IItemModelDispatcher iItemModelDispatcher) {
this.itemModelDispatcher = iItemModelDispatcher;
}
this.allStats.add(itemComponent);
}
}
Expand Down Expand Up @@ -987,6 +978,11 @@ public IEnchantabilityHelper getEnchantabilityHelper() {
return enchantabilityHelper;
}

@Nullable
public IItemModelDispatcher getItemModelDispatcher() {
return itemModelDispatcher;
}

public int getBurnValue() {
return burnValue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gregtech.api.items.metaitem.stats;

import gregtech.api.items.metaitem.MetaItem;

import net.minecraft.item.ItemStack;

@FunctionalInterface
public interface IItemModelDispatcher extends IItemComponent {

/**
* Get the model index for the given item stack. <br>
* The index range will be checked at
* {@link MetaItem#getModelIndex(ItemStack)}.
*
* @param itemStack The specific item stack.
* @param maxIndex The max model index, from
* {@link MetaItem.MetaValueItem#getModelAmount()} - 1.
* @return The model index for the specific stack, should be ranged between
* {@code 0} (inclusive) and {@code maxIndex} (inclusive).
*/
int getModelIndex(ItemStack itemStack, int maxIndex);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gregtech.api.capability.IGhostSlotConfigurable;
import gregtech.api.items.gui.ItemUIFactory;
import gregtech.api.items.metaitem.stats.IItemBehaviour;
import gregtech.api.items.metaitem.stats.IItemModelDispatcher;
import gregtech.api.items.metaitem.stats.ISubItemHandler;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.mui.GTGuiTextures;
Expand Down Expand Up @@ -33,7 +34,7 @@
import java.util.ArrayList;
import java.util.List;

public class IntCircuitBehaviour implements IItemBehaviour, ItemUIFactory, ISubItemHandler {
public class IntCircuitBehaviour implements IItemBehaviour, ItemUIFactory, ISubItemHandler, IItemModelDispatcher {

@Override
public void addInformation(ItemStack itemStack, List<String> lines) {
Expand Down Expand Up @@ -115,4 +116,9 @@ public String getItemSubType(ItemStack itemStack) {
public void getSubItems(ItemStack itemStack, CreativeTabs creativeTab, NonNullList<ItemStack> subItems) {
subItems.add(itemStack.copy());
}

@Override
public int getModelIndex(ItemStack itemStack, int maxIndex) {
return IntCircuitIngredient.getCircuitConfiguration(itemStack);
}
}
Loading