Added type safe addInformation for the AE base class of ItemBlock with addCheckedInformation
Added type safe class reference for all energy cells
This commit is contained in:
parent
739b4f8432
commit
c19d780979
4 changed files with 27 additions and 12 deletions
|
@ -736,7 +736,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<AEBaseItemBlock> getItemBlockClass()
|
public Class<? extends AEBaseItemBlock> getItemBlockClass()
|
||||||
{
|
{
|
||||||
return AEBaseItemBlock.class;
|
return AEBaseItemBlock.class;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,16 @@ import appeng.client.render.ItemRenderer;
|
||||||
import appeng.me.helpers.IGridProxyable;
|
import appeng.me.helpers.IGridProxyable;
|
||||||
import appeng.tile.AEBaseTile;
|
import appeng.tile.AEBaseTile;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class AEBaseItemBlock extends ItemBlock
|
public class AEBaseItemBlock extends ItemBlock
|
||||||
{
|
{
|
||||||
|
|
||||||
final AEBaseBlock blockType;
|
final AEBaseBlock blockType;
|
||||||
|
|
||||||
public AEBaseItemBlock(Block id) {
|
public AEBaseItemBlock(Block id)
|
||||||
|
{
|
||||||
super( id );
|
super( id );
|
||||||
blockType = (AEBaseBlock) id;
|
blockType = (AEBaseBlock) id;
|
||||||
hasSubtypes = blockType.hasSubtypes;
|
hasSubtypes = blockType.hasSubtypes;
|
||||||
|
@ -49,9 +52,17 @@ public class AEBaseItemBlock extends ItemBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
|
|
|
@ -3,6 +3,8 @@ package appeng.block;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -22,11 +24,12 @@ public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEIte
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 internalCurrentPower = 0;
|
||||||
double internalMaxPower = getMax( is );
|
double internalMaxPower = this.getMaxEnergyCapacity();
|
||||||
|
|
||||||
if ( tag != null )
|
if ( tag != null )
|
||||||
{
|
{
|
||||||
|
@ -35,12 +38,12 @@ public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEIte
|
||||||
|
|
||||||
double percent = internalCurrentPower / internalMaxPower;
|
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 ) );
|
+ Platform.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getMax(ItemStack is)
|
private double getMaxEnergyCapacity()
|
||||||
{
|
{
|
||||||
Block blk = Block.getBlockFromItem( this );
|
Block blk = Block.getBlockFromItem( this );
|
||||||
if ( blk == AEApi.instance().blocks().blockEnergyCell.block() )
|
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)
|
public double injectAEPower(ItemStack is, double amt)
|
||||||
{
|
{
|
||||||
double internalCurrentPower = getInternal( is );
|
double internalCurrentPower = getInternal( is );
|
||||||
double internalMaxPower = getMax( is );
|
double internalMaxPower = getMaxEnergyCapacity();
|
||||||
internalCurrentPower += amt;
|
internalCurrentPower += amt;
|
||||||
if ( internalCurrentPower > internalMaxPower )
|
if ( internalCurrentPower > internalMaxPower )
|
||||||
{
|
{
|
||||||
|
@ -98,7 +101,7 @@ public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEIte
|
||||||
@Override
|
@Override
|
||||||
public double getAEMaxPower(ItemStack is)
|
public double getAEMaxPower(ItemStack is)
|
||||||
{
|
{
|
||||||
return getMax( is );
|
return getMaxEnergyCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import appeng.block.AEBaseItemBlock;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -85,7 +86,7 @@ public class BlockEnergyCell extends AEBaseBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class getItemBlockClass()
|
public Class<? extends AEBaseItemBlock> getItemBlockClass()
|
||||||
{
|
{
|
||||||
return AEBaseItemBlockChargeable.class;
|
return AEBaseItemBlockChargeable.class;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue