Applied-Energistics-2-tiler.../src/main/java/appeng/recipes/AEItemResolver.java

188 lines
5.4 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, 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.recipes;
import net.minecraft.item.ItemStack;
2015-12-24 02:07:03 +01:00
import appeng.api.AEApi;
import appeng.api.definitions.IDefinitions;
import appeng.api.definitions.IItems;
import appeng.api.definitions.IParts;
import appeng.api.recipes.ISubItemResolver;
import appeng.api.recipes.ResolverResult;
import appeng.api.recipes.ResolverResultSet;
import appeng.api.util.AEColor;
import appeng.api.util.AEColoredItemDefinition;
import appeng.core.AppEng;
import appeng.items.materials.ItemMaterial;
2016-09-17 17:05:07 +02:00
import appeng.items.materials.MaterialType;
import appeng.items.misc.ItemCrystalSeed;
import appeng.items.parts.ItemPart;
import appeng.items.parts.PartType;
public class AEItemResolver implements ISubItemResolver
{
@Override
2015-09-30 14:24:40 +02:00
public Object resolveItemByName( final String nameSpace, final String itemName )
{
if( nameSpace.equals( AppEng.MOD_ID ) )
{
final IDefinitions definitions = AEApi.instance().definitions();
final IItems items = definitions.items();
final IParts parts = definitions.parts();
if( itemName.startsWith( "paint_ball." ) )
2014-07-11 22:07:16 +02:00
{
return this.paintBall( items.coloredPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), false );
2014-07-11 22:07:16 +02:00
}
if( itemName.startsWith( "lumen_paint_ball." ) )
2014-07-11 22:07:16 +02:00
{
return this.paintBall( items.coloredLumenPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), true );
2014-07-11 22:07:16 +02:00
}
if( itemName.equals( "cable_glass" ) )
{
return new ResolverResultSet( "cable_glass", parts.cableGlass().allStacks( 1 ) );
}
if( itemName.startsWith( "cable_glass." ) )
{
return this.cableItem( parts.cableGlass(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
}
if( itemName.equals( "cable_covered" ) )
{
return new ResolverResultSet( "cable_covered", parts.cableCovered().allStacks( 1 ) );
}
if( itemName.startsWith( "cable_covered." ) )
{
return this.cableItem( parts.cableCovered(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
}
if( itemName.equals( "cable_smart" ) )
{
return new ResolverResultSet( "cable_smart", parts.cableSmart().allStacks( 1 ) );
}
if( itemName.startsWith( "cable_smart." ) )
{
return this.cableItem( parts.cableSmart(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
}
if( itemName.equals( "cable_dense" ) )
{
return new ResolverResultSet( "cable_dense", parts.cableDense().allStacks( 1 ) );
}
if( itemName.startsWith( "cable_dense." ) )
{
return this.cableItem( parts.cableDense(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
}
if( itemName.startsWith( "crystal_seed." ) )
{
if( itemName.equalsIgnoreCase( "crystal_seed.certus" ) )
2015-04-29 02:30:53 +02:00
{
return ItemCrystalSeed.getResolver( ItemCrystalSeed.CERTUS );
2015-04-29 02:30:53 +02:00
}
if( itemName.equalsIgnoreCase( "crystal_seed.nether" ) )
2015-04-29 02:30:53 +02:00
{
return ItemCrystalSeed.getResolver( ItemCrystalSeed.NETHER );
2015-04-29 02:30:53 +02:00
}
if( itemName.equalsIgnoreCase( "crystal_seed.fluix" ) )
2015-04-29 02:30:53 +02:00
{
return ItemCrystalSeed.getResolver( ItemCrystalSeed.FLUIX );
2015-04-29 02:30:53 +02:00
}
return null;
}
if( itemName.startsWith( "material." ) )
{
2015-09-30 14:24:40 +02:00
final String materialName = itemName.substring( itemName.indexOf( '.' ) + 1 );
final MaterialType mt = MaterialType.valueOf( materialName );
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
if( mt.getItemInstance() == ItemMaterial.instance && mt.getDamageValue() >= 0 && mt.isRegistered() )
2015-04-29 02:30:53 +02:00
{
return new ResolverResult( "material", mt.getDamageValue() );
2015-04-29 02:30:53 +02:00
}
}
if( itemName.startsWith( "part." ) )
{
2015-09-30 14:24:40 +02:00
final String partName = itemName.substring( itemName.indexOf( '.' ) + 1 );
final PartType pt = PartType.valueOf( partName );
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
final int dVal = ItemPart.instance.getDamageByType( pt );
if( dVal >= 0 )
2015-04-29 02:30:53 +02:00
{
return new ResolverResult( "part", dVal );
2015-04-29 02:30:53 +02:00
}
}
}
return null;
}
2015-09-30 14:24:40 +02:00
private Object paintBall( final AEColoredItemDefinition partType, final String substring, final boolean lumen )
2014-07-11 22:07:16 +02:00
{
AEColor col;
2014-07-11 22:07:16 +02:00
try
{
col = AEColor.valueOf( substring.toUpperCase() );
2014-07-11 22:07:16 +02:00
}
2015-09-30 14:24:40 +02:00
catch( final Throwable t )
2014-07-11 22:07:16 +02:00
{
2016-09-17 15:02:51 +02:00
col = AEColor.TRANSPARENT;
2014-07-11 22:07:16 +02:00
}
2016-09-17 15:02:51 +02:00
if( col == AEColor.TRANSPARENT )
2015-04-29 02:30:53 +02:00
{
2014-07-11 22:07:16 +02:00
return null;
2015-04-29 02:30:53 +02:00
}
2014-07-29 04:52:17 +02:00
2015-09-30 14:24:40 +02:00
final ItemStack is = partType.stack( col, 1 );
return new ResolverResult( "paint_ball", ( lumen ? 20 : 0 ) + is.getItemDamage() );
2014-07-11 22:07:16 +02:00
}
2014-07-29 04:52:17 +02:00
2015-09-30 14:24:40 +02:00
private Object cableItem( final AEColoredItemDefinition partType, final String substring )
{
AEColor col;
try
{
col = AEColor.valueOf( substring.toUpperCase() );
}
2015-09-30 14:24:40 +02:00
catch( final Throwable t )
{
2016-09-17 15:02:51 +02:00
col = AEColor.TRANSPARENT;
}
2015-09-30 14:24:40 +02:00
final ItemStack is = partType.stack( col, 1 );
return new ResolverResult( "part", is.getItemDamage() );
}
}