Energy Cell Item Models (#44)

* Added energy cell item models.

* Removed the client-side only interface and moved to a method in AEBaseBlock instead.
This commit is contained in:
shartte
2016-08-16 15:38:53 +02:00
committed by dpeter99
parent 785e40ce3e
commit 026de7d590
6 changed files with 113 additions and 19 deletions
@@ -25,6 +25,8 @@ import java.util.List;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -32,6 +34,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.block.AEBaseItemBlock;
import appeng.block.AEBaseItemBlockChargeable;
import appeng.block.AEBaseTileBlock;
@@ -96,4 +99,40 @@ public class BlockEnergyCell extends AEBaseTileBlock
{
return AEBaseItemBlockChargeable.class;
}
/**
* Helper method that returns the energy fill factor (between 0 and 1) of a given item stack.
* Returns 0 if the item stack has no fill factor.
*/
private static double getFillFactor( ItemStack is ) {
if( !( is.getItem() instanceof IAEItemPowerStorage ) )
{
return 0;
}
AEBaseItemBlockChargeable itemChargeable = (AEBaseItemBlockChargeable) is.getItem();
double curPower = itemChargeable.getAECurrentPower( is );
double maxPower = itemChargeable.getAEMaxPower( is );
return curPower / maxPower;
}
/**
* Determines which version of the energy cell model should be used depending on the fill factor
* of the item stack.
*/
@SideOnly( Side.CLIENT )
@Override
public ItemMeshDefinition getItemMeshDefinition()
{
return is -> {
double fillFactor = getFillFactor( is );
int storageLevel = TileEnergyCell.getStorageLevelFromFillFactor(fillFactor);
return new ModelResourceLocation( "appliedenergistics2:tile.BlockEnergyCell", "fullness=" + storageLevel );
};
}
}