Implement against interface

This commit is contained in:
thatsIch
2014-11-05 10:21:50 +01:00
parent 4e1b93b842
commit 61588fd736
@@ -1,11 +1,31 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.items.tools.powered; package appeng.items.tools.powered;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@@ -21,6 +41,7 @@ import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode; import appeng.api.config.FuzzyMode;
@@ -55,15 +76,16 @@ import appeng.util.ItemSorters;
import appeng.util.Platform; import appeng.util.Platform;
import appeng.util.item.AEItemStack; import appeng.util.item.AEItemStack;
public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCell, IItemGroup, IBlockTool, IMouseWheelItem public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCell, IItemGroup, IBlockTool, IMouseWheelItem
{ {
final static HashMap<Integer, AEColor> oreToColor = new HashMap<Integer, AEColor>(); final static Map<Integer, AEColor> oreToColor = new HashMap<Integer, AEColor>();
static static
{ {
for (AEColor col : AEColor.values()) for ( AEColor col : AEColor.values() )
{ {
if ( col == AEColor.Transparent ) if ( col == AEColor.Transparent )
continue; continue;
@@ -73,7 +95,8 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
public ToolColorApplicator() { public ToolColorApplicator()
{
super( ToolColorApplicator.class, null ); super( ToolColorApplicator.class, null );
setFeature( EnumSet.of( AEFeature.ColorApplicator, AEFeature.PoweredTools ) ); setFeature( EnumSet.of( AEFeature.ColorApplicator, AEFeature.PoweredTools ) );
maxStoredPower = AEConfig.instance.colorApplicatorBattery; maxStoredPower = AEConfig.instance.colorApplicatorBattery;
@@ -88,7 +111,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() ); BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() );
} }
public ItemStack getColor(ItemStack is) public ItemStack getColor( ItemStack is )
{ {
NBTTagCompound c = is.getTagCompound(); NBTTagCompound c = is.getTagCompound();
if ( c != null && c.hasKey( "color" ) ) if ( c != null && c.hasKey( "color" ) )
@@ -102,7 +125,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
return findNextColor( is, null, 0 ); return findNextColor( is, null, 0 );
} }
public AEColor getColorFromItem(ItemStack paintBall) public AEColor getColorFromItem( ItemStack paintBall )
{ {
if ( paintBall == null ) if ( paintBall == null )
return null; return null;
@@ -112,14 +135,14 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
if ( paintBall.getItem() instanceof ItemPaintBall ) if ( paintBall.getItem() instanceof ItemPaintBall )
{ {
ItemPaintBall ipb = (ItemPaintBall) paintBall.getItem(); ItemPaintBall ipb = ( ItemPaintBall ) paintBall.getItem();
return ipb.getColor( paintBall ); return ipb.getColor( paintBall );
} }
else else
{ {
int[] id = OreDictionary.getOreIDs( paintBall ); int[] id = OreDictionary.getOreIDs( paintBall );
for (int oreID : id) for ( int oreID : id )
{ {
if ( oreToColor.containsKey( oreID ) ) if ( oreToColor.containsKey( oreID ) )
return oreToColor.get( oreID ); return oreToColor.get( oreID );
@@ -129,12 +152,12 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
return null; return null;
} }
public AEColor getActiveColor(ItemStack tol) public AEColor getActiveColor( ItemStack tol )
{ {
return getColorFromItem( getColor( tol ) ); return getColorFromItem( getColor( tol ) );
} }
private ItemStack findNextColor(ItemStack is, ItemStack anchor, int scrollOffset) private ItemStack findNextColor( ItemStack is, ItemStack anchor, int scrollOffset )
{ {
ItemStack newColor = null; ItemStack newColor = null;
@@ -152,13 +175,13 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
{ {
LinkedList<IAEItemStack> list = new LinkedList<IAEItemStack>(); LinkedList<IAEItemStack> list = new LinkedList<IAEItemStack>();
for (IAEItemStack i : itemList) for ( IAEItemStack i : itemList )
list.add( i ); list.add( i );
Collections.sort( list, new Comparator<IAEItemStack>() { Collections.sort( list, new Comparator<IAEItemStack>(){
@Override @Override
public int compare(IAEItemStack a, IAEItemStack b) public int compare( IAEItemStack a, IAEItemStack b )
{ {
return ItemSorters.compareInt( a.getItemDamage(), b.getItemDamage() ); return ItemSorters.compareInt( a.getItemDamage(), b.getItemDamage() );
} }
@@ -171,7 +194,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
IAEItemStack where = list.getFirst(); IAEItemStack where = list.getFirst();
int cycles = 1 + list.size(); int cycles = 1 + list.size();
while (cycles > 0 && !where.equals( anchor )) while ( cycles > 0 && !where.equals( anchor ) )
{ {
list.addLast( list.removeFirst() ); list.addLast( list.removeFirst() );
cycles--; cycles--;
@@ -194,7 +217,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
return newColor; return newColor;
} }
public void setColor(ItemStack is, ItemStack newColor) public void setColor( ItemStack is, ItemStack newColor )
{ {
NBTTagCompound data = Platform.openNbtData( is ); NBTTagCompound data = Platform.openNbtData( is );
if ( newColor == null ) if ( newColor == null )
@@ -208,7 +231,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
@Override @Override
public boolean onItemUse(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ) public boolean onItemUse( ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
{ {
Block blk = w.getBlock( x, y, z ); Block blk = w.getBlock( x, y, z );
double powerPerUse = 100; double powerPerUse = 100;
@@ -238,9 +261,9 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
// clean cables. // clean cables.
if ( te instanceof IColorableTile ) if ( te instanceof IColorableTile )
{ {
if ( getAECurrentPower( is ) > powerPerUse && ((IColorableTile) te).getColor() != AEColor.Transparent ) if ( getAECurrentPower( is ) > powerPerUse && ( ( IColorableTile ) te ).getColor() != AEColor.Transparent )
{ {
if ( ((IColorableTile) te).recolourBlock( orientation, AEColor.Transparent, p ) ) if ( ( ( IColorableTile ) te ).recolourBlock( orientation, AEColor.Transparent, p ) )
{ {
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() ); inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
extractAEPower( is, powerPerUse ); extractAEPower( is, powerPerUse );
@@ -256,7 +279,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
{ {
inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() ); inv.extractItems( AEItemStack.create( paintBall ), Actionable.MODULATE, new BaseActionSource() );
extractAEPower( is, powerPerUse ); extractAEPower( is, powerPerUse );
((TilePaint) painted).cleanSide( orientation.getOpposite() ); ( ( TilePaint ) painted ).cleanSide( orientation.getOpposite() );
return true; return true;
} }
} }
@@ -286,7 +309,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
return false; return false;
} }
private boolean recolourBlock(Block blk, ForgeDirection side, World w, int x, int y, int z, ForgeDirection orientation, AEColor newColor, EntityPlayer p) private boolean recolourBlock( Block blk, ForgeDirection side, World w, int x, int y, int z, ForgeDirection orientation, AEColor newColor, EntityPlayer p )
{ {
if ( blk == Blocks.carpet ) if ( blk == Blocks.carpet )
{ {
@@ -336,12 +359,12 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
if ( blk instanceof BlockCableBus ) if ( blk instanceof BlockCableBus )
return ((BlockCableBus) blk).recolourBlock( w, x, y, z, side, newColor.ordinal(), p ); return ( ( BlockCableBus ) blk ).recolourBlock( w, x, y, z, side, newColor.ordinal(), p );
return blk.recolourBlock( w, x, y, z, side, newColor.ordinal() ); return blk.recolourBlock( w, x, y, z, side, newColor.ordinal() );
} }
public void cycleColors(ItemStack is, ItemStack paintBall, int i) public void cycleColors( ItemStack is, ItemStack paintBall, int i )
{ {
if ( paintBall == null ) if ( paintBall == null )
{ {
@@ -354,7 +377,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
@Override @Override
public String getItemStackDisplayName(ItemStack par1ItemStack) public String getItemStackDisplayName( ItemStack par1ItemStack )
{ {
String extra = GuiText.Empty.getLocal(); String extra = GuiText.Empty.getLocal();
@@ -367,7 +390,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
@Override @Override
public void addCheckedInformation(ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation ) public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
{ {
super.addCheckedInformation( stack, player, lines, displayAdditionalInformation ); super.addCheckedInformation( stack, player, lines, displayAdditionalInformation );
@@ -375,7 +398,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
if ( cdi instanceof CellInventoryHandler ) if ( cdi instanceof CellInventoryHandler )
{ {
ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv(); ICellInventory cd = ( ( ICellInventoryHandler ) cdi ).getCellInv();
if ( cd != null ) if ( cd != null )
{ {
lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalBytes() + " " + GuiText.BytesUsed.getLocal() ); lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalBytes() + " " + GuiText.BytesUsed.getLocal() );
@@ -385,31 +408,31 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
@Override @Override
public int getBytes(ItemStack cellItem) public int getBytes( ItemStack cellItem )
{ {
return 512; return 512;
} }
@Override @Override
public int BytePerType(ItemStack cell) public int BytePerType( ItemStack cell )
{ {
return 8; return 8;
} }
@Override @Override
public int getTotalTypes(ItemStack cellItem) public int getTotalTypes( ItemStack cellItem )
{ {
return 27; return 27;
} }
@Override @Override
public boolean isBlackListed(ItemStack cellItem, IAEItemStack requestedAddition) public boolean isBlackListed( ItemStack cellItem, IAEItemStack requestedAddition )
{ {
if ( requestedAddition != null ) if ( requestedAddition != null )
{ {
int[] id = OreDictionary.getOreIDs( requestedAddition.getItemStack() ); int[] id = OreDictionary.getOreIDs( requestedAddition.getItemStack() );
for (int x : id) for ( int x : id )
{ {
if ( oreToColor.containsKey( x ) ) if ( oreToColor.containsKey( x ) )
return false; return false;
@@ -418,7 +441,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
if ( requestedAddition.getItem() instanceof ItemSnowball ) if ( requestedAddition.getItem() instanceof ItemSnowball )
return false; return false;
return !(requestedAddition.getItem() instanceof ItemPaintBall && requestedAddition.getItemDamage() < 20); return !( requestedAddition.getItem() instanceof ItemPaintBall && requestedAddition.getItemDamage() < 20 );
} }
return true; return true;
} }
@@ -430,51 +453,51 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
@Override @Override
public boolean isStorageCell(ItemStack i) public boolean isStorageCell( ItemStack i )
{ {
return true; return true;
} }
@Override @Override
public IInventory getUpgradesInventory(ItemStack is) public IInventory getUpgradesInventory( ItemStack is )
{ {
return new CellUpgrades( is, 2 ); return new CellUpgrades( is, 2 );
} }
@Override @Override
public IInventory getConfigInventory(ItemStack is) public IInventory getConfigInventory( ItemStack is )
{ {
return new CellConfig( is ); return new CellConfig( is );
} }
@Override @Override
public FuzzyMode getFuzzyMode(ItemStack is) public FuzzyMode getFuzzyMode( ItemStack is )
{ {
String fz = Platform.openNbtData( is ).getString( "FuzzyMode" ); String fz = Platform.openNbtData( is ).getString( "FuzzyMode" );
try try
{ {
return FuzzyMode.valueOf( fz ); return FuzzyMode.valueOf( fz );
} }
catch (Throwable t) catch ( Throwable t )
{ {
return FuzzyMode.IGNORE_ALL; return FuzzyMode.IGNORE_ALL;
} }
} }
@Override @Override
public String getUnlocalizedGroupName(Set<ItemStack> others, ItemStack is) public String getUnlocalizedGroupName( Set<ItemStack> others, ItemStack is )
{ {
return GuiText.StorageCells.getUnlocalized(); return GuiText.StorageCells.getUnlocalized();
} }
@Override @Override
public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) public void setFuzzyMode( ItemStack is, FuzzyMode fzMode )
{ {
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() ); Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
} }
@Override @Override
public boolean isEditable(ItemStack is) public boolean isEditable( ItemStack is )
{ {
return true; return true;
} }
@@ -486,7 +509,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
@Override @Override
public void onWheel(ItemStack is, boolean up) public void onWheel( ItemStack is, boolean up )
{ {
cycleColors( is, getColor( is ), up ? 1 : -1 ); cycleColors( is, getColor( is ), up ? 1 : -1 );
} }