Fixes #1474: Prevents crafting of disabled recipes and deletes invalid parts
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -9,6 +27,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;
|
||||
@@ -75,7 +94,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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -53,7 +53,7 @@ public final class ColoredItemDefinition implements AEColoredItemDefinition
|
||||
return null;
|
||||
}
|
||||
|
||||
return is.item;
|
||||
return is.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,6 +96,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
|
||||
@@ -26,6 +26,7 @@ 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;
|
||||
|
||||
@@ -34,15 +35,14 @@ public final class DamagedItemDefinition implements IItemDefinition
|
||||
{
|
||||
private final String identifier;
|
||||
private final IStackSrc source;
|
||||
private final boolean enabled;
|
||||
|
||||
public DamagedItemDefinition( @Nonnull String identifier, @Nonnull IStackSrc source )
|
||||
{
|
||||
Preconditions.checkNotNull( identifier );
|
||||
this.identifier = Preconditions.checkNotNull( identifier );
|
||||
Preconditions.checkArgument( !identifier.isEmpty() );
|
||||
Preconditions.checkNotNull( source );
|
||||
|
||||
this.identifier = identifier;
|
||||
this.source = source;
|
||||
this.source = Preconditions.checkNotNull( source );
|
||||
this.enabled = source.isEnabled();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -63,15 +63,38 @@ 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
|
||||
public boolean isSameAs( ItemStack comparableStack )
|
||||
{
|
||||
// is available && is same item && has same damage
|
||||
return comparableStack != null && comparableStack.getItem() == this.source.getItem() && comparableStack.getItemDamage() == this.source.getDamage();
|
||||
if( comparableStack == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.enabled && comparableStack.getItem() == this.source.getItem() && comparableStack.getItemDamage() == this.source.getDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameAs( IBlockAccess world, int x, int y, int z )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -75,6 +75,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;
|
||||
import appeng.items.materials.MaterialType;
|
||||
@@ -26,12 +28,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;
|
||||
}
|
||||
@@ -53,4 +54,10 @@ public class MaterialStackSrc implements IStackSrc
|
||||
{
|
||||
return this.src.damageValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user