Merge pull request #231 from thatsIch/checkedinformation

Added type safe addInformation for the AE base class of ItemBlock with `addCheckedInformation`
This commit is contained in:
FireBall1725 2014-10-04 11:25:25 -04:00
commit 810cd476d5
4 changed files with 27 additions and 12 deletions

View file

@ -736,7 +736,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
}
public Class<AEBaseItemBlock> getItemBlockClass()
public Class<? extends AEBaseItemBlock> getItemBlockClass()
{
return AEBaseItemBlock.class;
}

View file

@ -19,13 +19,16 @@ import appeng.client.render.ItemRenderer;
import appeng.me.helpers.IGridProxyable;
import appeng.tile.AEBaseTile;
import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class AEBaseItemBlock extends ItemBlock
{
final AEBaseBlock blockType;
public AEBaseItemBlock(Block id) {
public AEBaseItemBlock(Block id)
{
super( id );
blockType = (AEBaseBlock) id;
hasSubtypes = blockType.hasSubtypes;
@ -49,9 +52,17 @@ public class AEBaseItemBlock extends ItemBlock
}
@Override
public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips)
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public final void addInformation(ItemStack itemStack, EntityPlayer player, List toolTip, boolean advancedTooltips)
{
blockType.addInformation( is, player, lines, advancedItemTooltips );
this.addCheckedInformation( itemStack, player, toolTip, advancedTooltips );
}
@SideOnly(Side.CLIENT)
public void addCheckedInformation(ItemStack itemStack, EntityPlayer player, List<String> toolTip, boolean advancedToolTips)
{
this.blockType.addInformation( itemStack, player, toolTip, advancedToolTips );
}
@Override

View file

@ -3,6 +3,8 @@ package appeng.block;
import java.text.MessageFormat;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -22,11 +24,12 @@ public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEIte
}
@Override
public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips)
@SideOnly(Side.CLIENT)
public void addCheckedInformation(ItemStack itemStack, EntityPlayer player, List<String> toolTip, boolean advancedTooltips)
{
NBTTagCompound tag = is.getTagCompound();
NBTTagCompound tag = itemStack.getTagCompound();
double internalCurrentPower = 0;
double internalMaxPower = getMax( is );
double internalMaxPower = this.getMaxEnergyCapacity();
if ( tag != null )
{
@ -35,12 +38,12 @@ public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEIte
double percent = internalCurrentPower / internalMaxPower;
lines.add( GuiText.StoredEnergy.getLocal() + ":" + MessageFormat.format( " {0,number,#} ", internalCurrentPower )
toolTip.add( GuiText.StoredEnergy.getLocal() + ":" + MessageFormat.format( " {0,number,#} ", internalCurrentPower )
+ Platform.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) );
}
private double getMax(ItemStack is)
private double getMaxEnergyCapacity()
{
Block blk = Block.getBlockFromItem( this );
if ( blk == AEApi.instance().blocks().blockEnergyCell.block() )
@ -65,7 +68,7 @@ public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEIte
public double injectAEPower(ItemStack is, double amt)
{
double internalCurrentPower = getInternal( is );
double internalMaxPower = getMax( is );
double internalMaxPower = getMaxEnergyCapacity();
internalCurrentPower += amt;
if ( internalCurrentPower > internalMaxPower )
{
@ -98,7 +101,7 @@ public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEIte
@Override
public double getAEMaxPower(ItemStack is)
{
return getMax( is );
return getMaxEnergyCapacity();
}
@Override

View file

@ -5,6 +5,7 @@ import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import appeng.block.AEBaseItemBlock;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -85,7 +86,7 @@ public class BlockEnergyCell extends AEBaseBlock
}
@Override
public Class getItemBlockClass()
public Class<? extends AEBaseItemBlock> getItemBlockClass()
{
return AEBaseItemBlockChargeable.class;
}