Ensure that disabled parts are actually disabled and removed.
This commit is contained in:
@@ -31,6 +31,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;
|
||||
|
||||
|
||||
@@ -83,7 +84,8 @@ public final class AETileBlockFeatureHandler implements IFeatureHandler
|
||||
// Bypass the forge magic with null to register our own itemblock later.
|
||||
GameRegistry.registerBlock( this.featured, null, registryName );
|
||||
GameRegistry.registerItem( this.definition.maybeItem().get(), registryName );
|
||||
|
||||
AEBaseTile.registerTileItem( this.featured.getTileEntityClass(), new BlockStackSrc( this.featured, 0, ActivityState.from( this.isFeatureAvailable() ) ) );
|
||||
|
||||
// register the block/item conversion...
|
||||
if( this.definition.maybeItem().isPresent() )
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
@@ -38,8 +39,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( final String identifier, Block block, ActivityState state )
|
||||
{
|
||||
@@ -48,8 +49,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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +100,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}
|
||||
@@ -122,38 +129,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, BlockPos pos )
|
||||
{
|
||||
return this.enabled && world.getBlockState( pos ).getBlock() == this.block;
|
||||
return this.isEnabled() && world.getBlockState( pos ).getBlock() == 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -34,15 +35,22 @@ import appeng.api.definitions.IItemDefinition;
|
||||
public final class DamagedItemDefinition implements IItemDefinition
|
||||
{
|
||||
private final String identifier;
|
||||
private final IStackSrc source;
|
||||
private final boolean enabled;
|
||||
private static final ItemTransformer ITEM_TRANSFORMER = new ItemTransformer();
|
||||
private final Optional<IStackSrc> source;
|
||||
|
||||
public DamagedItemDefinition( @Nonnull String identifier, @Nonnull IStackSrc source )
|
||||
{
|
||||
this.identifier = Preconditions.checkNotNull( identifier );
|
||||
Preconditions.checkArgument( !identifier.isEmpty() );
|
||||
this.source = Preconditions.checkNotNull( source );
|
||||
this.enabled = source.isEnabled();
|
||||
Preconditions.checkNotNull( source );
|
||||
|
||||
if( source.isEnabled() )
|
||||
{
|
||||
this.source = Optional.of( source );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.source = Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -55,30 +63,19 @@ public final class DamagedItemDefinition implements IItemDefinition
|
||||
@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 )
|
||||
{
|
||||
if ( this.enabled )
|
||||
{
|
||||
final ItemStack stack = this.source.stack( stackSize );
|
||||
|
||||
return Optional.fromNullable( stack );
|
||||
}
|
||||
else
|
||||
{
|
||||
return Optional.absent();
|
||||
}
|
||||
return this.source.transform( new ItemStackTransformer( stackSize ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return this.enabled;
|
||||
return this.source.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,7 +86,7 @@ public final class DamagedItemDefinition implements IItemDefinition
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.enabled && 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
|
||||
@@ -97,4 +94,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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,13 @@ 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;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.util.Platform;
|
||||
@@ -34,19 +36,23 @@ import appeng.util.Platform;
|
||||
public class ItemDefinition implements IItemDefinition
|
||||
{
|
||||
private final String identifier;
|
||||
private final Item item;
|
||||
private final boolean enabled;
|
||||
private final Optional<Item> item;
|
||||
|
||||
public ItemDefinition( String identifier, Item item, ActivityState state )
|
||||
{
|
||||
Preconditions.checkNotNull( identifier );
|
||||
this.identifier = Preconditions.checkNotNull( identifier );
|
||||
Preconditions.checkArgument( !identifier.isEmpty() );
|
||||
Preconditions.checkNotNull( item );
|
||||
Preconditions.checkNotNull( state );
|
||||
|
||||
this.identifier = identifier;
|
||||
this.item = item;
|
||||
this.enabled = state == ActivityState.Enabled;
|
||||
if( state == ActivityState.Enabled )
|
||||
{
|
||||
this.item = Optional.of( item );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.item = Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -59,31 +65,48 @@ public class ItemDefinition implements IItemDefinition
|
||||
@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.enabled;
|
||||
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
|
||||
public boolean isSameAs( IBlockAccess world, int x, int y, int z )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ 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;
|
||||
|
||||
@@ -32,7 +31,6 @@ public class ItemStackSrc implements IStackSrc
|
||||
{
|
||||
|
||||
private final Item item;
|
||||
public final Block block;
|
||||
public final int damage;
|
||||
private final boolean enabled;
|
||||
|
||||
@@ -43,35 +41,16 @@ public class ItemStackSrc implements IStackSrc
|
||||
Preconditions.checkNotNull( state );
|
||||
Preconditions.checkArgument( state == ActivityState.Enabled || state == ActivityState.Disabled );
|
||||
|
||||
this.block = null;
|
||||
this.item = item;
|
||||
this.damage = damage;
|
||||
this.enabled = state == ActivityState.Enabled;
|
||||
}
|
||||
|
||||
public ItemStackSrc( Block b, int dmg, ActivityState state )
|
||||
{
|
||||
this.item = null;
|
||||
this.block = b;
|
||||
this.damage = dmg;
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -32,7 +33,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( @Nonnull final String identifier, AEBaseTileBlock block, ActivityState state )
|
||||
{
|
||||
@@ -40,14 +42,30 @@ public final class TileDefinition extends BlockDefinition implements ITileDefini
|
||||
|
||||
Preconditions.checkNotNull( block );
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user