Merge pull request #1695 from yueh/b-prevents-crafting-of-disabled-parts

Prevents crafting of disabled parts
This commit is contained in:
yueh 2015-07-24 22:27:21 +02:00
commit 15993eb3c7
29 changed files with 488 additions and 165 deletions

View file

@ -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<ItemStack> maybeStack( int stackSize );
/**
* @return <tt>true</tt> if definition is enabled
*/
boolean isEnabled();
}

View file

@ -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 );
}

View file

@ -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;

View file

@ -53,6 +53,7 @@ import appeng.api.util.IOrientable;
import appeng.block.networking.BlockCableBus;
import appeng.core.features.AEFeature;
import appeng.core.features.AETileBlockFeatureHandler;
import appeng.core.features.ActivityState;
import appeng.core.features.IAEFeature;
import appeng.core.features.ItemStackSrc;
import appeng.helpers.ICustomCollision;
@ -89,8 +90,6 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements IAEFeature,
protected void setTileEntity( Class<? extends TileEntity> c )
{
this.tileEntityType = c;
AEBaseTile.registerTileItem( c, new ItemStackSrc( this, 0 ) );
this.isInventory = IInventory.class.isAssignableFrom( c );
this.setTileProvider( this.hasBlockTileEntity() );
}

View file

@ -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();

View file

@ -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 <http://www.gnu.org/licenses/lgpl>.
*/
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 ) );
}
}

View file

@ -29,6 +29,7 @@ import appeng.api.definitions.ITileDefinition;
import appeng.block.AEBaseTileBlock;
import appeng.core.CommonHelper;
import appeng.core.CreativeTab;
import appeng.tile.AEBaseTile;
import appeng.util.Platform;
@ -82,6 +83,7 @@ public final class AETileBlockFeatureHandler implements IFeatureHandler
GameRegistry.registerBlock( this.featured, null, registryName );
GameRegistry.registerItem( this.definition.maybeItem().get(), registryName );
GameRegistry.registerTileEntity( this.featured.getTileEntityClass(), this.featured.toString() );
AEBaseTile.registerTileItem( this.featured.getTileEntityClass(), new BlockStackSrc( this.featured, 0, ActivityState.from( this.isFeatureAvailable() ) ) );
}
}
}

View file

@ -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 <http://www.gnu.org/licenses/lgpl>.
*/
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;
}
}
}

View file

@ -21,6 +21,7 @@ package appeng.core.features;
import java.lang.reflect.Constructor;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ObjectArrays;
@ -37,8 +38,8 @@ import appeng.block.AEBaseBlock;
public class BlockDefinition extends ItemDefinition implements IBlockDefinition
{
private final Block block;
private final boolean enabled;
private static final ItemBlockTransformer ITEMBLOCK_TRANSFORMER = new ItemBlockTransformer();
private final Optional<Block> block;
public BlockDefinition( Block block, ActivityState state )
{
@ -47,8 +48,14 @@ public class BlockDefinition extends ItemDefinition implements IBlockDefinition
Preconditions.checkNotNull( block );
Preconditions.checkNotNull( state );
this.block = block;
this.enabled = state == ActivityState.Enabled;
if( state == ActivityState.Enabled )
{
this.block = Optional.of( block );
}
else
{
this.block = Optional.absent();
}
}
/**
@ -92,7 +99,7 @@ public class BlockDefinition extends ItemDefinition implements IBlockDefinition
*
* TODO: throw an exception instead of returning null? As this could cause issue later on.
*
* @param block the block to create the {@link ItemBlock} from
* @param block the block to create the {@link ItemBlock} from
* @param itemclass the class used to construct it.
*
* @return an {@link Item} for the block. Actually always a sub type of {@link ItemBlock}
@ -121,38 +128,51 @@ public class BlockDefinition extends ItemDefinition implements IBlockDefinition
@Override
public final Optional<Block> maybeBlock()
{
return Optional.of( this.block );
return this.block;
}
@Override
public final Optional<ItemBlock> maybeItemBlock()
{
if( this.enabled )
{
return Optional.of( new ItemBlock( this.block ) );
}
else
{
return Optional.absent();
}
return this.block.transform( ITEMBLOCK_TRANSFORMER );
}
@Override
public final Optional<ItemStack> maybeStack( int stackSize )
{
if( this.enabled )
{
return Optional.of( new ItemStack( this.block ) );
}
else
{
return Optional.absent();
}
return this.block.transform( new ItemStackTransformer( stackSize ) );
}
@Override
public final boolean isSameAs( IBlockAccess world, int x, int y, int z )
{
return this.enabled && world.getBlock( x, y, z ) == this.block;
return this.isEnabled() && world.getBlock( x, y, z ) == this.block.get();
}
private static class ItemBlockTransformer implements Function<Block, ItemBlock>
{
@Override
public ItemBlock apply( Block input )
{
return new ItemBlock( input );
}
}
private static class ItemStackTransformer implements Function<Block, ItemStack>
{
private final int stackSize;
public ItemStackTransformer( int stackSize )
{
Preconditions.checkArgument( stackSize > 0 );
this.stackSize = stackSize;
}
@Override
public ItemStack apply( Block input )
{
return new ItemStack( input, this.stackSize );
}
}
}

View file

@ -0,0 +1,74 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl>.
*/
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;
public class BlockStackSrc implements IStackSrc
{
public final Block block;
public final int damage;
private final boolean enabled;
public BlockStackSrc( Block block, int damage, ActivityState state )
{
Preconditions.checkNotNull( block );
Preconditions.checkArgument( damage >= 0 );
Preconditions.checkNotNull( state );
Preconditions.checkArgument( state == ActivityState.Enabled || state == ActivityState.Disabled );
this.block = block;
this.damage = damage;
this.enabled = state == ActivityState.Enabled;
}
@Nullable
@Override
public ItemStack stack( int i )
{
return new ItemStack( this.block, i, this.damage );
}
@Override
public Item getItem()
{
return null;
}
@Override
public int getDamage()
{
return this.damage;
}
@Override
public boolean isEnabled()
{
return this.enabled;
}
}

View file

@ -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;
}
}

View file

@ -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.core.features;
import javax.annotation.Nonnull;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
@ -33,27 +34,39 @@ import appeng.api.definitions.IItemDefinition;
public final class DamagedItemDefinition implements IItemDefinition
{
private final IStackSrc source;
private static final ItemTransformer ITEM_TRANSFORMER = new ItemTransformer();
private final Optional<IStackSrc> source;
public DamagedItemDefinition( @Nonnull IStackSrc source )
{
this.source = Preconditions.checkNotNull( source );
Preconditions.checkNotNull( source );
if( source.isEnabled() )
{
this.source = Optional.of( source );
}
else
{
this.source = Optional.absent();
}
}
@Override
public Optional<Item> maybeItem()
{
final Item item = this.source.getItem();
return Optional.fromNullable( item );
return this.source.transform( ITEM_TRANSFORMER );
}
@Override
public Optional<ItemStack> maybeStack( int stackSize )
{
final ItemStack stack = this.source.stack( stackSize );
return this.source.transform( new ItemStackTransformer( stackSize ) );
}
return Optional.fromNullable( stack );
@Override
public boolean isEnabled()
{
return this.source.isPresent();
}
@Override
@ -64,7 +77,7 @@ public final class DamagedItemDefinition implements IItemDefinition
return false;
}
return comparableStack.getItem() == this.source.getItem() && comparableStack.getItemDamage() == this.source.getDamage();
return this.isEnabled() && comparableStack.getItem() == this.source.get().getItem() && comparableStack.getItemDamage() == this.source.get().getDamage();
}
@Override
@ -72,4 +85,31 @@ public final class DamagedItemDefinition implements IItemDefinition
{
return false;
}
private static class ItemTransformer implements Function<IStackSrc, Item>
{
@Override
public Item apply( IStackSrc input )
{
return input.getItem();
}
}
private static class ItemStackTransformer implements Function<IStackSrc, ItemStack>
{
private final int stackSize;
public ItemStackTransformer( int stackSize )
{
Preconditions.checkArgument( stackSize > 0 );
this.stackSize = stackSize;
}
@Override
public ItemStack apply( IStackSrc input )
{
return input.stack( this.stackSize );
}
}
}

View file

@ -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();
}

View file

@ -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,7 @@
package appeng.core.features;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
@ -32,41 +33,45 @@ import appeng.util.Platform;
public class ItemDefinition implements IItemDefinition
{
private final Item item;
private final boolean enabled;
private final Optional<Item> item;
public ItemDefinition( Item item, ActivityState state )
{
Preconditions.checkNotNull( item );
Preconditions.checkNotNull( state );
this.item = item;
this.enabled = state == ActivityState.Enabled;
if( state == ActivityState.Enabled )
{
this.item = Optional.of( item );
}
else
{
this.item = Optional.absent();
}
}
@Override
public final Optional<Item> maybeItem()
{
return Optional.of( this.item );
return this.item;
}
@Override
public Optional<ItemStack> maybeStack( int stackSize )
{
if( this.enabled )
{
return Optional.of( new ItemStack( this.item ) );
}
else
{
return Optional.absent();
}
return this.item.transform( new ItemStackTransformer( stackSize ) );
}
@Override
public boolean isEnabled()
{
return this.item.isPresent();
}
@Override
public final boolean isSameAs( ItemStack comparableStack )
{
return this.enabled && Platform.isSameItemType( comparableStack, this.maybeStack( 1 ).get() );
return this.isEnabled() && Platform.isSameItemType( comparableStack, this.maybeStack( 1 ).get() );
}
@Override
@ -74,4 +79,22 @@ public class ItemDefinition implements IItemDefinition
{
return false;
}
private static class ItemStackTransformer implements Function<Item, ItemStack>
{
private final int stackSize;
public ItemStackTransformer( int stackSize )
{
Preconditions.checkArgument( stackSize > 0 );
this.stackSize = stackSize;
}
@Override
public ItemStack apply( Item input )
{
return new ItemStack( input, this.stackSize );
}
}
}

View file

@ -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,7 +21,8 @@ package appeng.core.features;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import com.google.common.base.Preconditions;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -29,39 +30,27 @@ import net.minecraft.item.ItemStack;
public class ItemStackSrc implements IStackSrc
{
public final Item item;
public final Block block;
private final Item item;
public final int damage;
private final boolean enabled;
public ItemStackSrc( Item i, int dmg )
public ItemStackSrc( Item item, int damage, ActivityState state )
{
this.block = null;
this.item = i;
this.damage = dmg;
}
Preconditions.checkNotNull( item );
Preconditions.checkArgument( damage >= 0 );
Preconditions.checkNotNull( state );
Preconditions.checkArgument( state == ActivityState.Enabled || state == ActivityState.Disabled );
public ItemStackSrc( Block b, int dmg )
{
this.item = null;
this.block = b;
this.damage = dmg;
this.item = item;
this.damage = damage;
this.enabled = state == ActivityState.Enabled;
}
@Nullable
@Override
public ItemStack stack( int i )
{
if( this.block != null )
{
return new ItemStack( this.block, i, this.damage );
}
if( this.item != null )
{
return new ItemStack( this.item, i, this.damage );
}
return null;
return new ItemStack( this.item, i, this.damage );
}
@Override
@ -75,4 +64,10 @@ public class ItemStackSrc implements IStackSrc
{
return this.damage;
}
@Override
public boolean isEnabled()
{
return this.enabled;
}
}

View file

@ -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;
}
}

View file

@ -19,6 +19,7 @@
package appeng.core.features;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
@ -30,7 +31,8 @@ import appeng.block.AEBaseTileBlock;
public final class TileDefinition extends BlockDefinition implements ITileDefinition
{
private final AEBaseTileBlock block;
private static final TileEntityTransformer TILEENTITY_TRANSFORMER = new TileEntityTransformer();
private final Optional<AEBaseTileBlock> block;
public TileDefinition( AEBaseTileBlock block, ActivityState state )
{
@ -40,14 +42,30 @@ public final class TileDefinition extends BlockDefinition implements ITileDefini
Preconditions.checkNotNull( state );
Preconditions.checkNotNull( block.getTileEntityClass() );
this.block = block;
if( state == ActivityState.Enabled )
{
this.block = Optional.of( block );
}
else
{
this.block = Optional.absent();
}
}
@Override
public Optional<? extends Class<? extends TileEntity>> maybeEntity()
{
final Class<? extends TileEntity> entity = this.block.getTileEntityClass();
return this.block.transform( TILEENTITY_TRANSFORMER );
}
return Optional.of( entity );
private static class TileEntityTransformer implements Function<AEBaseTileBlock, Class<? extends TileEntity>>
{
@Override
public Class<? extends TileEntity> apply( AEBaseTileBlock input )
{
final Class<? extends TileEntity> entity = input.getTileEntityClass();
return entity;
}
}
}

View file

@ -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,6 +77,12 @@ public final class WrappedDamageItemDefinition implements ITileDefinition
return this.definition.maybeBlock().transform( new BlockTransformFunction( stackSize, this.damage ) );
}
@Override
public boolean isEnabled()
{
return this.definition.isEnabled();
}
@Override
public boolean isSameAs( ItemStack comparableStack )
{

View file

@ -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<AxisAlignedBB> boxes = new ArrayList<AxisAlignedBB>();
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 ) ) ) )

View file

@ -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<String> lines, boolean displayMoreInfo )
protected void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayMoreInfo )
{
super.addInformation( stack, player, lines, displayMoreInfo );
}
protected void getCheckedSubItems( Item sameItem, CreativeTabs creativeTab, List<ItemStack> itemStacks )
{
super.getSubItems( sameItem, creativeTab, itemStacks );
}
}

View file

@ -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<ItemStack> itemStacks )
{
List<MaterialType> types = Arrays.asList( MaterialType.values() );
Collections.sort( types, new Comparator<MaterialType>()
@ -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 ) );
}
}
}

View file

@ -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<ItemStack> 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 ) ) );
}
}

View file

@ -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<ItemStack> 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() ) );
}
}
}

View file

@ -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<ItemStack> itemStacks )
{
this.calculateSubTypes();
list.addAll( this.subTypes );
itemStacks.addAll( this.subTypes );
}
private void calculateSubTypes()
{
if( this.subTypes == null )
{
this.subTypes = new ArrayList<ItemStack>();
this.subTypes = new ArrayList<ItemStack>( 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<ItemStack> tmpList = new ArrayList<ItemStack>();
List<ItemStack> tmpList = new ArrayList<ItemStack>( 100 );
b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList );
for( ItemStack l : tmpList )
{

View file

@ -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<Entry<Integer, PartTypeWithVariant>> REGISTERED_COMPARATOR = new RegisteredComparator();
public static ItemMultiPart instance;
private final NameResolver nameResolver;
private final Map<Integer, PartTypeWithVariant> registered;
private final Map<Integer, PartTypeWithVariant> unregistered;
public ItemMultiPart( IPartHelper partHelper )
{
Preconditions.checkNotNull( partHelper );
this.registered = new HashMap<Integer, PartTypeWithVariant>();
this.unregistered = new HashMap<Integer, PartTypeWithVariant>();
this.registered = new HashMap<Integer, PartTypeWithVariant>( 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,16 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
assert mat != null;
assert pti != null;
final Map<Integer, PartTypeWithVariant> 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 );
if( enabled )
{
this.registered.put( partDamage, pti );
}
}
public int getDamageByType( PartType t )
@ -180,12 +185,24 @@ 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
public boolean onItemUse( ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
{
if( this.getTypeByStack( is ) == PartType.InvalidType )
{
return false;
}
return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w );
}
@ -204,7 +221,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 +238,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<Integer, PartTypeWithVariant> 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<ItemStack> itemStacks )
{
List<Entry<Integer, PartTypeWithVariant>> types = new ArrayList<Entry<Integer, PartTypeWithVariant>>( this.registered.entrySet() );
Collections.sort( types, REGISTERED_COMPARATOR );
for( Entry<Integer, PartTypeWithVariant> part : types )
{
cList.add( new ItemStack( this, 1, part.getKey() ) );
}
}
@Override
public void registerIcons( IIconRegister par1IconRegister )
{
for( Entry<Integer, PartTypeWithVariant> 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 +279,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<? extends IPart> part = type.getPart();
if( part == null )
{
return null;
}
try
{
@ -302,10 +323,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 +392,18 @@ 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<Entry<Integer, PartTypeWithVariant>>
{
@Override

View file

@ -31,9 +31,9 @@ import appeng.integration.IntegrationType;
import appeng.parts.automation.PartAnnihilationPlane;
import appeng.parts.automation.PartExportBus;
import appeng.parts.automation.PartFormationPlane;
import appeng.parts.automation.PartIdentityAnnihilationPlane;
import appeng.parts.automation.PartImportBus;
import appeng.parts.automation.PartLevelEmitter;
import appeng.parts.automation.PartIdentityAnnihilationPlane;
import appeng.parts.misc.PartCableAnchor;
import appeng.parts.misc.PartInterface;
import appeng.parts.misc.PartInvertedToggleBus;

View file

@ -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<ItemStack> 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

View file

@ -51,7 +51,7 @@ import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.api.util.IOrientable;
import appeng.core.AELog;
import appeng.core.features.ItemStackSrc;
import appeng.core.features.IStackSrc;
import appeng.helpers.ICustomNameObject;
import appeng.helpers.IPriorityHost;
import appeng.tile.events.AETileEventHandler;
@ -66,14 +66,14 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
public static final ThreadLocal<WeakReference<AEBaseTile>> DROP_NO_ITEMS = new ThreadLocal<WeakReference<AEBaseTile>>();
private static final Map<Class<? extends AEBaseTile>, Map<TileEventType, List<AETileEventHandler>>> HANDLERS = new HashMap<Class<? extends AEBaseTile>, Map<TileEventType, List<AETileEventHandler>>>();
private static final Map<Class<? extends TileEntity>, ItemStackSrc> ITEM_STACKS = new HashMap<Class<? extends TileEntity>, ItemStackSrc>();
private static final Map<Class<? extends TileEntity>, IStackSrc> ITEM_STACKS = new HashMap<Class<? extends TileEntity>, IStackSrc>();
private int renderFragment = 0;
@Nullable
public String customName;
private ForgeDirection forward = ForgeDirection.UNKNOWN;
private ForgeDirection up = ForgeDirection.UNKNOWN;
public static void registerTileItem( Class<? extends TileEntity> c, ItemStackSrc wat )
public static void registerTileItem( Class<? extends TileEntity> c, IStackSrc wat )
{
ITEM_STACKS.put( c, wat );
}
@ -98,7 +98,7 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
@Nullable
protected ItemStack getItemFromTile( Object obj )
{
ItemStackSrc src = ITEM_STACKS.get( obj.getClass() );
IStackSrc src = ITEM_STACKS.get( obj.getClass() );
if( src == null )
{
return null;

View file

@ -450,6 +450,7 @@ item.appliedenergistics2.ItemPart.InvertedToggleBus.name=ME Inverted Toggle Bus
item.appliedenergistics2.ItemPart.ToggleBus.name=ME Toggle Bus
item.appliedenergistics2.ItemPart.CraftingMonitor.name=ME Crafting Monitor
item.appliedenergistics2.ItemPart.InterfaceTerminal.name=ME Interface Terminal
item.appliedenergistics2.ItemPart.InvalidType.name=Disabled Item
item.appliedenergistics2.ItemSpatialStorageCell.128Cubed.name=128³ Spatial Storage Cell
item.appliedenergistics2.ItemSpatialStorageCell.16Cubed.name=16³ Spatial Storage Cell