Fixes #1474: Prevents crafting of disabled recipes and deletes invalid parts

This commit is contained in:
thatsIch
2015-05-24 13:36:43 +02:00
committed by yueh
parent 3e6231492e
commit 91b8d30a15
21 changed files with 276 additions and 93 deletions
@@ -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;
}
}
}
@@ -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;
}
}
@@ -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<ItemStack> 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
@@ -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();
}
@@ -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 )
{
@@ -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;
}
}
@@ -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;
}
}
@@ -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 )
{