diff --git a/src/api/java/appeng/api/definitions/IItemDefinition.java b/src/api/java/appeng/api/definitions/IItemDefinition.java index 805d58deb..47eb93183 100644 --- a/src/api/java/appeng/api/definitions/IItemDefinition.java +++ b/src/api/java/appeng/api/definitions/IItemDefinition.java @@ -1,11 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2013 - 2015 AlgorithmX2 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package appeng.api.definitions; +import com.google.common.base.Optional; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import com.google.common.base.Optional; - public interface IItemDefinition extends IComparableDefinition { @@ -18,4 +41,9 @@ public interface IItemDefinition extends IComparableDefinition * @return an {@link ItemStack} with specified quantity of this item. */ Optional maybeStack( int stackSize ); + + /** + * @return true if definition is enabled + */ + boolean isEnabled(); } diff --git a/src/api/java/appeng/api/parts/IPartItem.java b/src/api/java/appeng/api/parts/IPartItem.java index dc755477f..7940339f9 100644 --- a/src/api/java/appeng/api/parts/IPartItem.java +++ b/src/api/java/appeng/api/parts/IPartItem.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2013 AlgorithmX2 + * Copyright (c) 2013 - 2015 AlgorithmX2 * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -24,6 +24,8 @@ package appeng.api.parts; +import javax.annotation.Nullable; + import net.minecraft.item.ItemStack; //@formatter:off @@ -63,5 +65,6 @@ public interface IPartItem * * @return part from item */ + @Nullable IPart createPartFromItemStack( ItemStack is ); } diff --git a/src/main/java/appeng/block/AEBaseBlock.java b/src/main/java/appeng/block/AEBaseBlock.java index d92696679..41d202e1c 100644 --- a/src/main/java/appeng/block/AEBaseBlock.java +++ b/src/main/java/appeng/block/AEBaseBlock.java @@ -56,6 +56,7 @@ import appeng.client.texture.FlippableIcon; import appeng.client.texture.MissingIcon; import appeng.core.features.AEBlockFeatureHandler; import appeng.core.features.AEFeature; +import appeng.core.features.ActivityState; import appeng.core.features.FeatureNameExtractor; import appeng.core.features.IAEFeature; import appeng.core.features.IFeatureHandler; diff --git a/src/main/java/appeng/client/render/BusRenderer.java b/src/main/java/appeng/client/render/BusRenderer.java index cf0997761..227533efd 100644 --- a/src/main/java/appeng/client/render/BusRenderer.java +++ b/src/main/java/appeng/client/render/BusRenderer.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -21,6 +21,7 @@ package appeng.client.render; import java.util.HashMap; import java.util.Map; +import javax.annotation.Nullable; import org.lwjgl.opengl.GL11; @@ -164,6 +165,7 @@ public class BusRenderer implements IItemRenderer GL11.glPopMatrix(); } + @Nullable public IPart getRenderer( ItemStack is, IPartItem c ) { int id = ( Item.getIdFromItem( is.getItem() ) << Platform.DEF_OFFSET ) | is.getItemDamage(); diff --git a/src/main/java/appeng/core/api/definitions/DefinitionConstructor.java b/src/main/java/appeng/core/api/definitions/DefinitionConstructor.java index 4b3be3c7c..6b69eb768 100644 --- a/src/main/java/appeng/core/api/definitions/DefinitionConstructor.java +++ b/src/main/java/appeng/core/api/definitions/DefinitionConstructor.java @@ -1,3 +1,21 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2015, 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 . + */ + package appeng.core.api.definitions; @@ -10,6 +28,7 @@ import appeng.api.util.AEColor; import appeng.api.util.AEColoredItemDefinition; import appeng.core.FeatureHandlerRegistry; import appeng.core.FeatureRegistry; +import appeng.core.features.ActivityState; import appeng.core.features.ColoredItemDefinition; import appeng.core.features.IAEFeature; import appeng.core.features.IFeatureHandler; @@ -76,7 +95,9 @@ public class DefinitionConstructor { for( AEColor color : AEColor.VALID_COLORS ) { - definition.add( color, new ItemStackSrc( targetItem, offset + color.ordinal() ) ); + final ActivityState state = ActivityState.from( target.isEnabled() ); + + definition.add( color, new ItemStackSrc( targetItem, offset + color.ordinal(), state ) ); } } diff --git a/src/main/java/appeng/core/features/ActivityState.java b/src/main/java/appeng/core/features/ActivityState.java index 80f1bc0e0..a4702fbe4 100644 --- a/src/main/java/appeng/core/features/ActivityState.java +++ b/src/main/java/appeng/core/features/ActivityState.java @@ -1,7 +1,38 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2015, 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 . + */ + package appeng.core.features; public enum ActivityState { - Enabled, Disabled + Enabled, + Disabled; + + public static ActivityState from( boolean enabled ) + { + if( enabled ) + { + return ActivityState.Enabled; + } + else + { + return ActivityState.Disabled; + } + } } diff --git a/src/main/java/appeng/core/features/ColoredItemDefinition.java b/src/main/java/appeng/core/features/ColoredItemDefinition.java index 070a0a9d8..2ab2e89d3 100644 --- a/src/main/java/appeng/core/features/ColoredItemDefinition.java +++ b/src/main/java/appeng/core/features/ColoredItemDefinition.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -54,7 +54,7 @@ public final class ColoredItemDefinition implements AEColoredItemDefinition return null; } - return is.item; + return is.getItem(); } @Override @@ -97,6 +97,6 @@ public final class ColoredItemDefinition implements AEColoredItemDefinition return false; } - return comparableItem.getItem() == is.item && comparableItem.getItemDamage() == is.damage; + return comparableItem.getItem() == is.getItem() && comparableItem.getItemDamage() == is.damage; } } diff --git a/src/main/java/appeng/core/features/DamagedItemDefinition.java b/src/main/java/appeng/core/features/DamagedItemDefinition.java index 86c97c3dc..e4ae3113e 100644 --- a/src/main/java/appeng/core/features/DamagedItemDefinition.java +++ b/src/main/java/appeng/core/features/DamagedItemDefinition.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -34,10 +34,12 @@ import appeng.api.definitions.IItemDefinition; public final class DamagedItemDefinition implements IItemDefinition { private final IStackSrc source; + private final boolean enabled; public DamagedItemDefinition( @Nonnull IStackSrc source ) { this.source = Preconditions.checkNotNull( source ); + this.enabled = source.isEnabled(); } @Override @@ -51,9 +53,22 @@ public final class DamagedItemDefinition implements IItemDefinition @Override public Optional maybeStack( int stackSize ) { - final ItemStack stack = this.source.stack( stackSize ); + if ( this.enabled ) + { + final ItemStack stack = this.source.stack( stackSize ); - return Optional.fromNullable( stack ); + return Optional.fromNullable( stack ); + } + else + { + return Optional.absent(); + } + } + + @Override + public boolean isEnabled() + { + return this.enabled; } @Override @@ -64,7 +79,7 @@ public final class DamagedItemDefinition implements IItemDefinition return false; } - return comparableStack.getItem() == this.source.getItem() && comparableStack.getItemDamage() == this.source.getDamage(); + return this.enabled && comparableStack.getItem() == this.source.getItem() && comparableStack.getItemDamage() == this.source.getDamage(); } @Override diff --git a/src/main/java/appeng/core/features/IStackSrc.java b/src/main/java/appeng/core/features/IStackSrc.java index 4f10410a8..cc7e1aa24 100644 --- a/src/main/java/appeng/core/features/IStackSrc.java +++ b/src/main/java/appeng/core/features/IStackSrc.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -31,4 +31,6 @@ public interface IStackSrc Item getItem(); int getDamage(); + + boolean isEnabled(); } diff --git a/src/main/java/appeng/core/features/ItemDefinition.java b/src/main/java/appeng/core/features/ItemDefinition.java index 8c0d55e48..f62b07e21 100644 --- a/src/main/java/appeng/core/features/ItemDefinition.java +++ b/src/main/java/appeng/core/features/ItemDefinition.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -63,6 +63,12 @@ public class ItemDefinition implements IItemDefinition } } + @Override + public boolean isEnabled() + { + return this.enabled; + } + @Override public final boolean isSameAs( ItemStack comparableStack ) { diff --git a/src/main/java/appeng/core/features/ItemStackSrc.java b/src/main/java/appeng/core/features/ItemStackSrc.java index 3966ac24a..a6824bccf 100644 --- a/src/main/java/appeng/core/features/ItemStackSrc.java +++ b/src/main/java/appeng/core/features/ItemStackSrc.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -21,6 +21,8 @@ package appeng.core.features; import javax.annotation.Nullable; +import com.google.common.base.Preconditions; + import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -29,22 +31,30 @@ import net.minecraft.item.ItemStack; public class ItemStackSrc implements IStackSrc { - public final Item item; + private final Item item; public final Block block; public final int damage; + private final boolean enabled; - public ItemStackSrc( Item i, int dmg ) + public ItemStackSrc( Item item, int damage, ActivityState state ) { + Preconditions.checkNotNull( item ); + Preconditions.checkArgument( damage >= 0 ); + Preconditions.checkNotNull( state ); + Preconditions.checkArgument( state == ActivityState.Enabled || state == ActivityState.Disabled ); + this.block = null; - this.item = i; - this.damage = dmg; + this.item = item; + this.damage = damage; + this.enabled = state == ActivityState.Enabled; } - public ItemStackSrc( Block b, int dmg ) + public ItemStackSrc( Block b, int dmg, ActivityState state ) { this.item = null; this.block = b; this.damage = dmg; + this.enabled = state == ActivityState.Enabled; } @Nullable @@ -75,4 +85,10 @@ public class ItemStackSrc implements IStackSrc { return this.damage; } + + @Override + public boolean isEnabled() + { + return this.enabled; + } } diff --git a/src/main/java/appeng/core/features/MaterialStackSrc.java b/src/main/java/appeng/core/features/MaterialStackSrc.java index 9b4ee560e..48b997305 100644 --- a/src/main/java/appeng/core/features/MaterialStackSrc.java +++ b/src/main/java/appeng/core/features/MaterialStackSrc.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -19,6 +19,8 @@ package appeng.core.features; +import com.google.common.base.Preconditions; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -27,12 +29,11 @@ import appeng.items.materials.MaterialType; public class MaterialStackSrc implements IStackSrc { - - final MaterialType src; + private final MaterialType src; public MaterialStackSrc( MaterialType src ) { - assert src != null; + Preconditions.checkNotNull( src ); this.src = src; } @@ -54,4 +55,10 @@ public class MaterialStackSrc implements IStackSrc { return this.src.damageValue; } + + @Override + public boolean isEnabled() + { + return true; + } } diff --git a/src/main/java/appeng/core/features/WrappedDamageItemDefinition.java b/src/main/java/appeng/core/features/WrappedDamageItemDefinition.java index dcc127de6..6aa2278fc 100644 --- a/src/main/java/appeng/core/features/WrappedDamageItemDefinition.java +++ b/src/main/java/appeng/core/features/WrappedDamageItemDefinition.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -37,6 +37,7 @@ public final class WrappedDamageItemDefinition implements ITileDefinition { private final ITileDefinition definition; private final int damage; + private final boolean enabled; public WrappedDamageItemDefinition( ITileDefinition definition, int damage ) { @@ -45,6 +46,7 @@ public final class WrappedDamageItemDefinition implements ITileDefinition this.definition = definition; this.damage = damage; + this.enabled = definition.isEnabled(); } @Override @@ -77,6 +79,12 @@ public final class WrappedDamageItemDefinition implements ITileDefinition return this.definition.maybeBlock().transform( new BlockTransformFunction( stackSize, this.damage ) ); } + @Override + public boolean isEnabled() + { + return this.enabled; + } + @Override public boolean isSameAs( ItemStack comparableStack ) { diff --git a/src/main/java/appeng/fmp/CableBusPart.java b/src/main/java/appeng/fmp/CableBusPart.java index 6dc469638..a1badadf2 100644 --- a/src/main/java/appeng/fmp/CableBusPart.java +++ b/src/main/java/appeng/fmp/CableBusPart.java @@ -514,12 +514,15 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IMask is = is.copy(); is.stackSize = 1; - IPart bp = bi.createPartFromItemStack( is ); + final IPart bp = bi.createPartFromItemStack( is ); if( !( side == null || side == ForgeDirection.UNKNOWN || this.tile() == null ) ) { List boxes = new ArrayList(); IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true ); - bp.getBoxes( bch ); + if( bp != null ) + { + bp.getBoxes( bch ); + } for( AxisAlignedBB bb : boxes ) { if( !this.tile().canAddPart( new NormallyOccludedPart( new Cuboid6( bb ) ) ) ) diff --git a/src/main/java/appeng/items/AEBaseItem.java b/src/main/java/appeng/items/AEBaseItem.java index 12de72ba9..a736c0059 100644 --- a/src/main/java/appeng/items/AEBaseItem.java +++ b/src/main/java/appeng/items/AEBaseItem.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -24,6 +24,7 @@ import java.util.List; import com.google.common.base.Optional; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -83,14 +84,26 @@ public abstract class AEBaseItem extends Item implements IAEFeature this.addCheckedInformation( stack, player, lines, displayMoreInfo ); } + @Override + @SuppressWarnings( "unchecked" ) + public final void getSubItems( Item sameItem, CreativeTabs creativeTab, List itemStacks ) + { + this.getCheckedSubItems( sameItem, creativeTab, itemStacks ); + } + @Override public boolean isBookEnchantable( ItemStack itemstack1, ItemStack itemstack2 ) { return false; } - public void addCheckedInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayMoreInfo ) + protected void addCheckedInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayMoreInfo ) { super.addInformation( stack, player, lines, displayMoreInfo ); } + + protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List itemStacks ) + { + super.getSubItems( sameItem, creativeTab, itemStacks ); + } } diff --git a/src/main/java/appeng/items/materials/ItemMultiMaterial.java b/src/main/java/appeng/items/materials/ItemMultiMaterial.java index 1540800f8..b071ef649 100644 --- a/src/main/java/appeng/items/materials/ItemMultiMaterial.java +++ b/src/main/java/appeng/items/materials/ItemMultiMaterial.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -291,7 +291,7 @@ public final class ItemMultiMaterial extends AEBaseItem implements IStorageCompo } @Override - public void getSubItems( Item par1, CreativeTabs par2CreativeTabs, List cList ) + protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List itemStacks ) { List types = Arrays.asList( MaterialType.values() ); Collections.sort( types, new Comparator() @@ -308,7 +308,7 @@ public final class ItemMultiMaterial extends AEBaseItem implements IStorageCompo { if( mat.damageValue >= 0 && mat.isRegistered() && mat.itemInstance == this ) { - cList.add( new ItemStack( this, 1, mat.damageValue ) ); + itemStacks.add( new ItemStack( this, 1, mat.damageValue ) ); } } } diff --git a/src/main/java/appeng/items/misc/ItemCrystalSeed.java b/src/main/java/appeng/items/misc/ItemCrystalSeed.java index e35a3d335..285c69ef0 100644 --- a/src/main/java/appeng/items/misc/ItemCrystalSeed.java +++ b/src/main/java/appeng/items/misc/ItemCrystalSeed.java @@ -310,21 +310,21 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal } @Override - public void getSubItems( Item i, CreativeTabs t, List l ) + protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List itemStacks ) { // lvl 0 - l.add( newStyle( new ItemStack( this, 1, CERTUS ) ) ); - l.add( newStyle( new ItemStack( this, 1, NETHER ) ) ); - l.add( newStyle( new ItemStack( this, 1, FLUIX ) ) ); + itemStacks.add( newStyle( new ItemStack( this, 1, CERTUS ) ) ); + itemStacks.add( newStyle( new ItemStack( this, 1, NETHER ) ) ); + itemStacks.add( newStyle( new ItemStack( this, 1, FLUIX ) ) ); // lvl 1 - l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + CERTUS ) ) ); - l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + NETHER ) ) ); - l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + FLUIX ) ) ); + itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + CERTUS ) ) ); + itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + NETHER ) ) ); + itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + FLUIX ) ) ); // lvl 2 - l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + CERTUS ) ) ); - l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + NETHER ) ) ); - l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + FLUIX ) ) ); + itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + CERTUS ) ) ); + itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + NETHER ) ) ); + itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + FLUIX ) ) ); } } diff --git a/src/main/java/appeng/items/misc/ItemPaintBall.java b/src/main/java/appeng/items/misc/ItemPaintBall.java index 863591fed..184a1dcae 100644 --- a/src/main/java/appeng/items/misc/ItemPaintBall.java +++ b/src/main/java/appeng/items/misc/ItemPaintBall.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -79,13 +79,13 @@ public class ItemPaintBall extends AEBaseItem } @Override - public void getSubItems( Item i, CreativeTabs ct, List l ) + protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List itemStacks ) { for( AEColor c : AEColor.values() ) { if( c != AEColor.Transparent ) { - l.add( new ItemStack( this, 1, c.ordinal() ) ); + itemStacks.add( new ItemStack( this, 1, c.ordinal() ) ); } } @@ -93,7 +93,7 @@ public class ItemPaintBall extends AEBaseItem { if( c != AEColor.Transparent ) { - l.add( new ItemStack( this, 1, DAMAGE_THRESHOLD + c.ordinal() ) ); + itemStacks.add( new ItemStack( this, 1, DAMAGE_THRESHOLD + c.ordinal() ) ); } } } diff --git a/src/main/java/appeng/items/parts/ItemFacade.java b/src/main/java/appeng/items/parts/ItemFacade.java index 9c9b190a8..c01866f8d 100644 --- a/src/main/java/appeng/items/parts/ItemFacade.java +++ b/src/main/java/appeng/items/parts/ItemFacade.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -103,17 +103,17 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte } @Override - public void getSubItems( Item number, CreativeTabs tab, List list ) + protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List itemStacks ) { this.calculateSubTypes(); - list.addAll( this.subTypes ); + itemStacks.addAll( this.subTypes ); } private void calculateSubTypes() { if( this.subTypes == null ) { - this.subTypes = new ArrayList(); + this.subTypes = new ArrayList( 1000 ); for( Object blk : Block.blockRegistry ) { Block b = (Block) blk; @@ -121,7 +121,7 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte { Item item = Item.getItemFromBlock( b ); - List tmpList = new ArrayList(); + List tmpList = new ArrayList( 100 ); b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList ); for( ItemStack l : tmpList ) { diff --git a/src/main/java/appeng/items/parts/ItemMultiPart.java b/src/main/java/appeng/items/parts/ItemMultiPart.java index c6b76f8c4..a89f12e48 100644 --- a/src/main/java/appeng/items/parts/ItemMultiPart.java +++ b/src/main/java/appeng/items/parts/ItemMultiPart.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -21,6 +21,7 @@ package appeng.items.parts; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.EnumSet; @@ -29,7 +30,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; - import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -47,6 +47,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import appeng.api.AEApi; +import appeng.api.exceptions.MissingDefinition; import appeng.api.implementations.items.IItemGroup; import appeng.api.parts.IPart; import appeng.api.parts.IPartHelper; @@ -54,6 +55,7 @@ import appeng.api.parts.IPartItem; import appeng.api.util.AEColor; import appeng.core.AEConfig; import appeng.core.features.AEFeature; +import appeng.core.features.ActivityState; import appeng.core.features.ItemStackSrc; import appeng.core.features.NameResolver; import appeng.core.localization.GuiText; @@ -64,19 +66,18 @@ import appeng.items.AEBaseItem; public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemGroup { + private static final int INITIAL_REGISTERED_CAPACITY = PartType.values().length; private static final Comparator> REGISTERED_COMPARATOR = new RegisteredComparator(); - + public static ItemMultiPart instance; private final NameResolver nameResolver; private final Map registered; - private final Map unregistered; public ItemMultiPart( IPartHelper partHelper ) { Preconditions.checkNotNull( partHelper ); - this.registered = new HashMap(); - this.unregistered = new HashMap(); + this.registered = new HashMap( INITIAL_REGISTERED_CAPACITY ); this.nameResolver = new NameResolver( this.getClass() ); this.setFeature( EnumSet.of( AEFeature.Core ) ); @@ -132,7 +133,8 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG } final int partDamage = mat.baseDamage + varID; - final ItemStackSrc output = new ItemStackSrc( this, partDamage ); + final ActivityState state = ActivityState.from( enabled ); + final ItemStackSrc output = new ItemStackSrc( this, partDamage, state ); final PartTypeWithVariant pti = new PartTypeWithVariant( mat, varID ); @@ -147,13 +149,13 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG assert mat != null; assert pti != null; - final Map reference = ( enabled ) ? this.registered : this.unregistered; - if( reference.containsKey( partDamage ) ) + final PartTypeWithVariant registeredPartType = this.registered.get( partDamage ); + if( registeredPartType != null ) { - throw new IllegalStateException( "Meta Overlap detected with type " + mat + " and damage " + partDamage + ". Found " + reference.get( partDamage ) + " there already." ); + throw new IllegalStateException( "Meta Overlap detected with type " + mat + " and damage " + partDamage + ". Found " + registeredPartType + " there already." ); } - reference.put( partDamage, pti ); + this.registered.put( partDamage, pti ); } public int getDamageByType( PartType t ) @@ -180,7 +182,14 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG @Override public IIcon getIconFromDamage( int dmg ) { - return this.registered.get( dmg ).ico; + final PartTypeWithVariant registeredType = this.registered.get( dmg ); + if( registeredType != null ) + { + return registeredType.ico; + } + + final String formattedRegistered = Arrays.toString( this.registered.keySet().toArray() ); + throw new MissingDefinition( "Tried to get the icon from a non-existent part with damage value " + dmg + ". There were registered: " + formattedRegistered + '.' ); } @Override @@ -204,7 +213,12 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG { final AEColor[] variants = AEColor.values(); - return super.getItemStackDisplayName( is ) + " - " + variants[this.registered.get( is.getItemDamage() ).variant].toString(); + final int itemDamage = is.getItemDamage(); + final PartTypeWithVariant registeredPartType = this.registered.get( itemDamage ); + if( registeredPartType != null ) + { + return super.getItemStackDisplayName( is ) + " - " + variants[registeredPartType.variant].toString(); + } } if( pt.getExtraName() != null ) @@ -216,24 +230,24 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG } @Override - public void getSubItems( Item number, CreativeTabs tab, List cList ) + public void registerIcons( IIconRegister iconRegister ) + { + for( Entry part : this.registered.entrySet() ) + { + String tex = "appliedenergistics2:" + this.getName( new ItemStack( this, 1, part.getKey() ) ); + part.getValue().ico = iconRegister.registerIcon( tex ); + } + } + + @Override + protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List itemStacks ) { List> types = new ArrayList>( this.registered.entrySet() ); Collections.sort( types, REGISTERED_COMPARATOR ); for( Entry part : types ) { - cList.add( new ItemStack( this, 1, part.getKey() ) ); - } - } - - @Override - public void registerIcons( IIconRegister par1IconRegister ) - { - for( Entry part : this.registered.entrySet() ) - { - String tex = "appliedenergistics2:" + this.getName( new ItemStack( this, 1, part.getKey() ) ); - part.getValue().ico = par1IconRegister.registerIcon( tex ); + itemStacks.add( new ItemStack( this, 1, part.getKey() ) ); } } @@ -257,21 +271,20 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG { return pt.part; } - final PartTypeWithVariant unregisteredPartType = this.unregistered.get( is.getItemDamage() ); - if( unregisteredPartType != null ) - { - return unregisteredPartType.part; - } - throw new IllegalStateException( "ItemStack " + is + " has to be either registered or unregistered, but was not found in either." ); + return PartType.InvalidType; } - @Nonnull + @Nullable @Override public IPart createPartFromItemStack( ItemStack is ) { final PartType type = this.getTypeByStack( is ); final Class part = type.getPart(); + if( part == null ) + { + return null; + } try { @@ -302,10 +315,12 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG public int variantOf( int itemDamage ) { - if( this.registered.containsKey( itemDamage ) ) + final PartTypeWithVariant registeredPartType = this.registered.get( itemDamage ); + if( registeredPartType != null ) { - return this.registered.get( itemDamage ).variant; + return registeredPartType.variant; } + return 0; } @@ -369,8 +384,19 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG this.part = part; this.variant = variant; } + + @Override + public String toString() + { + return "PartTypeWithVariant{" + + "part=" + this.part + + ", variant=" + this.variant + + ", ico=" + this.ico + + '}'; + } } - + + private static final class RegisteredComparator implements Comparator> { @Override diff --git a/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java b/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java index 3d0f782b3..41252075c 100644 --- a/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java +++ b/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2015, 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 @@ -77,15 +77,16 @@ public abstract class AERootPoweredItem extends AEBaseItem implements IAEItemPow } @Override - public void getSubItems( Item id, CreativeTabs tab, List list ) + protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List itemStacks ) { - super.getSubItems( id, tab, list ); + super.getCheckedSubItems( sameItem, creativeTab, itemStacks ); - ItemStack charged = new ItemStack( this, 1 ); - NBTTagCompound tag = Platform.openNbtData( charged ); + final ItemStack charged = new ItemStack( this, 1 ); + final NBTTagCompound tag = Platform.openNbtData( charged ); tag.setDouble( "internalCurrentPower", this.getAEMaxPower( charged ) ); tag.setDouble( "internalMaxPower", this.getAEMaxPower( charged ) ); - list.add( charged ); + + itemStacks.add( charged ); } @Override