Rework ContainerInscriber validation (#3238)

* Correctly handle metadata wildcard for inscriber inputs
This commit is contained in:
fscan 2017-11-26 15:46:02 +01:00 committed by yueh
parent 5fa2c0ab27
commit f0d807f0a2
3 changed files with 30 additions and 37 deletions

View file

@ -120,28 +120,23 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres
if( s == this.middle )
{
for( final ItemStack optional : AEApi.instance().registries().inscriber().getOptionals() )
IItemDefinition press = AEApi.instance().definitions().materials().namePress();
if( press.isSameAs( top ) || press.isSameAs( bot ) )
{
if( Platform.itemComparisons().isSameItem( optional, is ) )
{
return false;
}
return !press.isSameAs( is );
}
boolean matches = false;
boolean found = false;
for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() )
{
final boolean matchA = ( top.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( top,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( ( bot.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( bot,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) ) );
final boolean matchB = ( bot.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( bot,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( ( top.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( top,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) ) );
final boolean matchA = !top
.isEmpty() && ( Platform.itemComparisons().isSameItem( top, recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) || Platform
.itemComparisons()
.isSameItem( top, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
final boolean matchB = !bot
.isEmpty() && ( Platform.itemComparisons().isSameItem( bot, recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) || Platform
.itemComparisons()
.isSameItem( bot, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
if( matchA || matchB )
{
@ -150,21 +145,19 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres
{
if( Platform.itemComparisons().isSameItem( is, option ) )
{
found = true;
return true;
}
}
}
}
if( matches && !found )
if( matches )
{
return false;
}
}
if( ( s == this.top && !bot.isEmpty() ) || ( s == this.bottom && !top.isEmpty() ) )
else if( ( s == this.top && !bot.isEmpty() ) || ( s == this.bottom && !top.isEmpty() ) )
{
ItemStack otherSlot = ItemStack.EMPTY;
ItemStack otherSlot;
if( s == this.top )
{
otherSlot = this.bottom.getStack();
@ -182,28 +175,24 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres
}
// everything else
boolean isValid = false;
for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() )
{
if( Platform.itemComparisons().isSameItem( recipe.getTopOptional().orElse( ItemStack.EMPTY ), otherSlot ) )
boolean isValid = false;
if( Platform.itemComparisons().isSameItem( otherSlot, recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) )
{
isValid = Platform.itemComparisons().isSameItem( is, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) );
}
else if( Platform.itemComparisons().isSameItem( recipe.getBottomOptional().orElse( ItemStack.EMPTY ), otherSlot ) )
else if( Platform.itemComparisons().isSameItem( otherSlot, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) )
{
isValid = Platform.itemComparisons().isSameItem( is, recipe.getTopOptional().orElse( ItemStack.EMPTY ) );
}
if( isValid )
{
break;
return true;
}
}
if( !isValid )
{
return false;
}
return false;
}
return true;

View file

@ -172,7 +172,7 @@ public class SlotRestrictedInput extends AppEngSlot
for( final ItemStack optional : AEApi.instance().registries().inscriber().getOptionals() )
{
if( Platform.itemComparisons().isSameItem( optional, i ) )
if( Platform.itemComparisons().isSameItem( i, optional ) )
{
return true;
}

View file

@ -281,9 +281,13 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
@Nullable
public IInscriberRecipe getTask()
{
final ItemStack plateA = this.topItemHandler.getStackInSlot( 0 );
final ItemStack plateB = this.bottomItemHandler.getStackInSlot( 0 );
ItemStack renamedItem = this.sideItemHandler.getStackInSlot( 0 );
return getTask( this.sideItemHandler.getStackInSlot( 0 ), this.topItemHandler.getStackInSlot( 0 ), this.bottomItemHandler.getStackInSlot( 0 ) );
}
@Nullable
private IInscriberRecipe getTask( final ItemStack input, final ItemStack plateA, final ItemStack plateB )
{
ItemStack renamedItem = input;
if( !plateA.isEmpty() && plateA.getCount() > 1 )
{
@ -379,7 +383,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
{
for( final ItemStack option : recipe.getInputs() )
{
if( Platform.itemComparisons().isSameItem( option, this.sideItemHandler.getStackInSlot( 0 ) ) )
if( Platform.itemComparisons().isSameItem( input, option ) )
{
return recipe;
}
@ -606,7 +610,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
for( final ItemStack optionals : AEApi.instance().registries().inscriber().getOptionals() )
{
if( Platform.itemComparisons().isSameItem( optionals, stack ) )
if( Platform.itemComparisons().isSameItem( stack, optionals ) )
{
return true;
}