Fixes #675 No disabled feature should log spam or crash anymore.
Deprecates the old usage of the AEItemDefinitions via the direct method access of * blocks() * parts() * items() * materials() and thus use the new re-direct via definitions(). All definitions are now initialized, no matter what. But SubItems, Items and Blocks are not registered, if by chance are disabled.
This commit is contained in:
@@ -22,6 +22,9 @@ package appeng.recipes;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
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;
|
||||
@@ -34,63 +37,68 @@ import appeng.items.misc.ItemCrystalSeed;
|
||||
import appeng.items.parts.ItemMultiPart;
|
||||
import appeng.items.parts.PartType;
|
||||
|
||||
|
||||
public class AEItemResolver implements ISubItemResolver
|
||||
{
|
||||
|
||||
@Override
|
||||
public Object resolveItemByName(String nameSpace, String itemName)
|
||||
public Object resolveItemByName( String nameSpace, 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( "PaintBall." ) )
|
||||
{
|
||||
return this.paintBall( AEApi.instance().items().itemPaintBall, itemName.substring( itemName.indexOf( "." ) + 1 ), false );
|
||||
return this.paintBall( items.coloredPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), false );
|
||||
}
|
||||
|
||||
if ( itemName.startsWith( "LumenPaintBall." ) )
|
||||
{
|
||||
return this.paintBall( AEApi.instance().items().itemPaintBall, itemName.substring( itemName.indexOf( "." ) + 1 ), true );
|
||||
return this.paintBall( items.coloredLumenPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), true );
|
||||
}
|
||||
|
||||
if ( itemName.equals( "CableGlass" ) )
|
||||
{
|
||||
return new ResolverResultSet( "CableGlass", AEApi.instance().parts().partCableGlass.allStacks( 1 ) );
|
||||
return new ResolverResultSet( "CableGlass", parts.cableGlass().allStacks( 1 ) );
|
||||
}
|
||||
|
||||
if ( itemName.startsWith( "CableGlass." ) )
|
||||
{
|
||||
return this.cableItem( AEApi.instance().parts().partCableGlass, itemName.substring( itemName.indexOf( "." ) + 1 ) );
|
||||
return this.cableItem( parts.cableGlass(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
|
||||
if ( itemName.equals( "CableCovered" ) )
|
||||
{
|
||||
return new ResolverResultSet( "CableCovered", AEApi.instance().parts().partCableCovered.allStacks( 1 ) );
|
||||
return new ResolverResultSet( "CableCovered", parts.cableCovered().allStacks( 1 ) );
|
||||
}
|
||||
|
||||
if ( itemName.startsWith( "CableCovered." ) )
|
||||
{
|
||||
return this.cableItem( AEApi.instance().parts().partCableCovered, itemName.substring( itemName.indexOf( "." ) + 1 ) );
|
||||
return this.cableItem( parts.cableCovered(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
|
||||
if ( itemName.equals( "CableSmart" ) )
|
||||
{
|
||||
return new ResolverResultSet( "CableSmart", AEApi.instance().parts().partCableSmart.allStacks( 1 ) );
|
||||
return new ResolverResultSet( "CableSmart", parts.cableSmart().allStacks( 1 ) );
|
||||
}
|
||||
|
||||
if ( itemName.startsWith( "CableSmart." ) )
|
||||
{
|
||||
return this.cableItem( AEApi.instance().parts().partCableSmart, itemName.substring( itemName.indexOf( "." ) + 1 ) );
|
||||
return this.cableItem( parts.cableSmart(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
|
||||
if ( itemName.equals( "CableDense" ) )
|
||||
{
|
||||
return new ResolverResultSet( "CableDense", AEApi.instance().parts().partCableDense.allStacks( 1 ) );
|
||||
return new ResolverResultSet( "CableDense", parts.cableDense().allStacks( 1 ) );
|
||||
}
|
||||
|
||||
if ( itemName.startsWith( "CableDense." ) )
|
||||
{
|
||||
return this.cableItem( AEApi.instance().parts().partCableDense, itemName.substring( itemName.indexOf( "." ) + 1 ) );
|
||||
return this.cableItem( parts.cableDense(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
|
||||
if ( itemName.startsWith( "ItemCrystalSeed." ) )
|
||||
@@ -107,7 +115,7 @@ public class AEItemResolver implements ISubItemResolver
|
||||
|
||||
if ( itemName.startsWith( "ItemMaterial." ) )
|
||||
{
|
||||
String materialName = itemName.substring( itemName.indexOf( "." ) + 1 );
|
||||
String materialName = itemName.substring( itemName.indexOf( '.' ) + 1 );
|
||||
MaterialType mt = MaterialType.valueOf( materialName );
|
||||
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
|
||||
if ( mt.itemInstance == ItemMultiMaterial.instance && mt.damageValue >= 0 && mt.isRegistered() )
|
||||
@@ -116,7 +124,7 @@ public class AEItemResolver implements ISubItemResolver
|
||||
|
||||
if ( itemName.startsWith( "ItemPart." ) )
|
||||
{
|
||||
String partName = itemName.substring( itemName.indexOf( "." ) + 1 );
|
||||
String partName = itemName.substring( itemName.indexOf( '.' ) + 1 );
|
||||
PartType pt = PartType.valueOf( partName );
|
||||
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
|
||||
int dVal = ItemMultiPart.instance.getDamageByType( pt );
|
||||
@@ -128,15 +136,15 @@ public class AEItemResolver implements ISubItemResolver
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object paintBall(AEColoredItemDefinition partType, String substring, boolean lumen)
|
||||
private Object paintBall( AEColoredItemDefinition partType, String substring, boolean lumen )
|
||||
{
|
||||
AEColor col = AEColor.Transparent;
|
||||
AEColor col;
|
||||
|
||||
try
|
||||
{
|
||||
col = AEColor.valueOf( substring );
|
||||
}
|
||||
catch (Throwable t)
|
||||
catch ( Throwable t )
|
||||
{
|
||||
col = AEColor.Transparent;
|
||||
}
|
||||
@@ -145,18 +153,18 @@ public class AEItemResolver implements ISubItemResolver
|
||||
return null;
|
||||
|
||||
ItemStack is = partType.stack( col, 1 );
|
||||
return new ResolverResult( "ItemPaintBall", (lumen ? 20 : 0) + is.getItemDamage() );
|
||||
return new ResolverResult( "ItemPaintBall", ( lumen ? 20 : 0 ) + is.getItemDamage() );
|
||||
}
|
||||
|
||||
private Object cableItem(AEColoredItemDefinition partType, String substring)
|
||||
private Object cableItem( AEColoredItemDefinition partType, String substring )
|
||||
{
|
||||
AEColor col = AEColor.Transparent;
|
||||
AEColor col;
|
||||
|
||||
try
|
||||
{
|
||||
col = AEColor.valueOf( substring );
|
||||
}
|
||||
catch (Throwable t)
|
||||
catch ( Throwable t )
|
||||
{
|
||||
col = AEColor.Transparent;
|
||||
}
|
||||
|
||||
@@ -30,15 +30,20 @@ import java.util.Map.Entry;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import cpw.mods.fml.common.LoaderState;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IBlocks;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.api.definitions.IItems;
|
||||
import appeng.api.exceptions.MissingIngredientError;
|
||||
import appeng.api.exceptions.RecipeError;
|
||||
import appeng.api.exceptions.RegistrationError;
|
||||
@@ -258,7 +263,17 @@ public class RecipeHandler implements IRecipeHandler
|
||||
if ( !id.modId.equals( AppEng.MOD_ID ) && !id.modId.equals( "minecraft" ) )
|
||||
throw new RecipeError( "Not applicable for website" );
|
||||
|
||||
if ( is.getItem() == AEApi.instance().items().itemCrystalSeed.item() )
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
final IItems items = definitions.items();
|
||||
final IBlocks blocks = definitions.blocks();
|
||||
|
||||
final Optional<Item> maybeCrystalSeedItem = items.crystalSeed().maybeItem();
|
||||
final Optional<Item> maybeSkyStoneItem = blocks.skyStone().maybeItem();
|
||||
final Optional<Item> maybeCraftingStorageItem = blocks.craftingStorage1k().maybeItem();
|
||||
final Optional<Item> maybeCraftingUnitItem = blocks.craftingUnit().maybeItem();
|
||||
final Optional<Item> maybeSkyChestItem = blocks.skyChest().maybeItem();
|
||||
|
||||
if ( maybeCrystalSeedItem.isPresent() && is.getItem() == maybeCrystalSeedItem.get() )
|
||||
{
|
||||
int dmg = is.getItemDamage();
|
||||
if ( dmg < ItemCrystalSeed.Nether )
|
||||
@@ -268,7 +283,7 @@ public class RecipeHandler implements IRecipeHandler
|
||||
else if ( dmg < ItemCrystalSeed.END )
|
||||
realName += ".Fluix";
|
||||
}
|
||||
else if ( is.getItem() == AEApi.instance().blocks().blockSkyStone.item() )
|
||||
else if ( maybeSkyStoneItem.isPresent() && is.getItem() == maybeSkyStoneItem.get() )
|
||||
{
|
||||
switch (is.getItemDamage())
|
||||
{
|
||||
@@ -284,7 +299,7 @@ public class RecipeHandler implements IRecipeHandler
|
||||
default:
|
||||
}
|
||||
}
|
||||
else if ( is.getItem() == AEApi.instance().blocks().blockCraftingStorage1k.item() )
|
||||
else if ( maybeCraftingStorageItem.isPresent() && is.getItem() == maybeCraftingStorageItem.get() )
|
||||
{
|
||||
switch (is.getItemDamage())
|
||||
{
|
||||
@@ -300,7 +315,7 @@ public class RecipeHandler implements IRecipeHandler
|
||||
default:
|
||||
}
|
||||
}
|
||||
else if ( is.getItem() == AEApi.instance().blocks().blockCraftingUnit.item() )
|
||||
else if ( maybeCraftingUnitItem.isPresent() && is.getItem() == maybeCraftingUnitItem.get() )
|
||||
{
|
||||
switch (is.getItemDamage())
|
||||
{
|
||||
@@ -310,7 +325,7 @@ public class RecipeHandler implements IRecipeHandler
|
||||
default:
|
||||
}
|
||||
}
|
||||
else if ( is.getItem() == AEApi.instance().blocks().blockSkyChest.item() )
|
||||
else if ( maybeSkyChestItem.isPresent() && is.getItem() == maybeSkyChestItem.get() )
|
||||
{
|
||||
switch (is.getItemDamage())
|
||||
{
|
||||
|
||||
@@ -18,32 +18,69 @@
|
||||
|
||||
package appeng.recipes.game;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.Blocks;
|
||||
import appeng.api.definitions.Items;
|
||||
import appeng.api.definitions.Materials;
|
||||
import appeng.api.definitions.IBlocks;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.api.definitions.IItems;
|
||||
import appeng.api.definitions.IMaterials;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class DisassembleRecipe implements IRecipe
|
||||
{
|
||||
|
||||
private final Materials mats = AEApi.instance().materials();
|
||||
private final Items items = AEApi.instance().items();
|
||||
private final Blocks blocks = AEApi.instance().blocks();
|
||||
private final IMaterials mats;
|
||||
private final IItems items;
|
||||
private final IBlocks blocks;
|
||||
private final Map<IItemDefinition, IItemDefinition> cellMappings;
|
||||
private final Map<IItemDefinition, IItemDefinition> nonCellMappings;
|
||||
|
||||
private ItemStack getOutput(InventoryCrafting inv, boolean createFacade)
|
||||
public DisassembleRecipe()
|
||||
{
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
|
||||
this.blocks = definitions.blocks();
|
||||
this.items = definitions.items();
|
||||
this.mats = definitions.materials();
|
||||
this.cellMappings = new HashMap<IItemDefinition, IItemDefinition>( 4 );
|
||||
this.nonCellMappings = new HashMap<IItemDefinition, IItemDefinition>( 5 );
|
||||
|
||||
this.cellMappings.put( this.items.cell1k(), this.mats.cell1kPart() );
|
||||
this.cellMappings.put( this.items.cell4k(), this.mats.cell4kPart() );
|
||||
this.cellMappings.put( this.items.cell16k(), this.mats.cell16kPart() );
|
||||
this.cellMappings.put( this.items.cell64k(), this.mats.cell64kPart() );
|
||||
|
||||
this.nonCellMappings.put( this.items.encodedPattern(), this.mats.blankPattern() );
|
||||
this.nonCellMappings.put( this.blocks.craftingStorage1k(), this.mats.cell1kPart() );
|
||||
this.nonCellMappings.put( this.blocks.craftingStorage4k(), this.mats.cell4kPart() );
|
||||
this.nonCellMappings.put( this.blocks.craftingStorage16k(), this.mats.cell16kPart() );
|
||||
this.nonCellMappings.put( this.blocks.craftingStorage64k(), this.mats.cell64kPart() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches( InventoryCrafting inv, World w )
|
||||
{
|
||||
return this.getOutput( inv, false ) != null;
|
||||
}
|
||||
|
||||
private ItemStack getOutput( InventoryCrafting inv, boolean createFacade )
|
||||
{
|
||||
ItemStack hasCell = null;
|
||||
|
||||
for (int x = 0; x < inv.getSizeInventory(); x++)
|
||||
for ( int x = 0; x < inv.getSizeInventory(); x++ )
|
||||
{
|
||||
ItemStack is = inv.getStackInSlot( x );
|
||||
if ( is != null )
|
||||
@@ -51,17 +88,7 @@ public class DisassembleRecipe implements IRecipe
|
||||
if ( hasCell != null )
|
||||
return null;
|
||||
|
||||
if ( this.items.itemCell1k.sameAsStack( is ) )
|
||||
hasCell = this.mats.materialCell1kPart.stack( 1 );
|
||||
|
||||
if ( this.items.itemCell4k.sameAsStack( is ) )
|
||||
hasCell = this.mats.materialCell4kPart.stack( 1 );
|
||||
|
||||
if ( this.items.itemCell16k.sameAsStack( is ) )
|
||||
hasCell = this.mats.materialCell16kPart.stack( 1 );
|
||||
|
||||
if ( this.items.itemCell64k.sameAsStack( is ) )
|
||||
hasCell = this.mats.materialCell64kPart.stack( 1 );
|
||||
hasCell = this.getCellOutput( is );
|
||||
|
||||
// make sure the storage cell is empty...
|
||||
if ( hasCell != null )
|
||||
@@ -75,20 +102,7 @@ public class DisassembleRecipe implements IRecipe
|
||||
}
|
||||
}
|
||||
|
||||
if ( this.items.itemEncodedPattern.sameAsStack( is ) )
|
||||
hasCell = this.mats.materialBlankPattern.stack( 1 );
|
||||
|
||||
if ( this.blocks.blockCraftingStorage1k.sameAsStack( is ) )
|
||||
hasCell = this.mats.materialCell1kPart.stack( 1 );
|
||||
|
||||
if ( this.blocks.blockCraftingStorage4k.sameAsStack( is ) )
|
||||
hasCell = this.mats.materialCell4kPart.stack( 1 );
|
||||
|
||||
if ( this.blocks.blockCraftingStorage16k.sameAsStack( is ) )
|
||||
hasCell = this.mats.materialCell16kPart.stack( 1 );
|
||||
|
||||
if ( this.blocks.blockCraftingStorage64k.sameAsStack( is ) )
|
||||
hasCell = this.mats.materialCell64kPart.stack( 1 );
|
||||
hasCell = this.getNonCellOutput( is );
|
||||
|
||||
if ( hasCell == null )
|
||||
return null;
|
||||
@@ -98,14 +112,34 @@ public class DisassembleRecipe implements IRecipe
|
||||
return hasCell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inv, World w)
|
||||
private ItemStack getCellOutput( ItemStack compared )
|
||||
{
|
||||
return this.getOutput( inv, false ) != null;
|
||||
for ( Map.Entry<IItemDefinition, IItemDefinition> entry : this.cellMappings.entrySet() )
|
||||
{
|
||||
if ( entry.getKey().isSameAs( compared ) )
|
||||
{
|
||||
return entry.getValue().maybeStack( 1 ).get();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ItemStack getNonCellOutput( ItemStack compared )
|
||||
{
|
||||
for ( Map.Entry<IItemDefinition, IItemDefinition> entry : this.nonCellMappings.entrySet() )
|
||||
{
|
||||
if ( entry.getKey().isSameAs( compared ) )
|
||||
{
|
||||
return entry.getValue().maybeStack( 1 ).get();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
public ItemStack getCraftingResult( InventoryCrafting inv )
|
||||
{
|
||||
return this.getOutput( inv, true );
|
||||
}
|
||||
@@ -121,5 +155,4 @@ public class DisassembleRecipe implements IRecipe
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,8 @@
|
||||
package appeng.recipes.game;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -29,20 +31,23 @@ import net.minecraft.world.World;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.util.AEItemDefinition;
|
||||
import appeng.api.definitions.IComparableDefinition;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.items.parts.ItemFacade;
|
||||
|
||||
|
||||
public class FacadeRecipe implements IRecipe
|
||||
public final class FacadeRecipe implements IRecipe
|
||||
{
|
||||
|
||||
private final Optional<AEItemDefinition> maybeAnchor;
|
||||
private final Optional<AEItemDefinition> maybeFacade;
|
||||
private final IComparableDefinition anchor;
|
||||
private final Optional<Item> maybeFacade;
|
||||
|
||||
public FacadeRecipe()
|
||||
{
|
||||
this.maybeFacade = Optional.fromNullable( AEApi.instance().items().itemFacade );
|
||||
this.maybeAnchor = Optional.fromNullable( AEApi.instance().parts().partCableAnchor );
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
|
||||
this.maybeFacade = definitions.items().facade().maybeItem();
|
||||
this.anchor = definitions.parts().cableAnchor();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,24 +56,25 @@ public class FacadeRecipe implements IRecipe
|
||||
return this.getOutput( inv, false ) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ItemStack getOutput( IInventory inv, boolean createFacade )
|
||||
{
|
||||
if ( this.maybeAnchor.isPresent() && this.maybeFacade.isPresent() && inv.getStackInSlot( 0 ) == null && inv.getStackInSlot( 2 ) == null && inv.getStackInSlot( 6 ) == null && inv.getStackInSlot( 8 ) == null )
|
||||
if ( inv.getStackInSlot( 0 ) == null && inv.getStackInSlot( 2 ) == null && inv.getStackInSlot( 6 ) == null && inv.getStackInSlot( 8 ) == null )
|
||||
{
|
||||
final AEItemDefinition anchorDefinition = this.maybeAnchor.get();
|
||||
final AEItemDefinition facadeDefinition = this.maybeFacade.get();
|
||||
|
||||
if ( anchorDefinition.sameAsStack( inv.getStackInSlot( 1 ) ) && anchorDefinition.sameAsStack( inv.getStackInSlot( 3 ) ) && anchorDefinition.sameAsStack( inv.getStackInSlot( 5 ) ) && anchorDefinition.sameAsStack( inv.getStackInSlot( 7 ) ) )
|
||||
if ( this.anchor.isSameAs( inv.getStackInSlot( 1 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 3 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 5 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 7 ) ) )
|
||||
{
|
||||
final Item itemDefinition = facadeDefinition.item();
|
||||
final ItemFacade facade = (ItemFacade) itemDefinition;
|
||||
for ( Item facadeItemDefinition : this.maybeFacade.asSet() )
|
||||
{
|
||||
final ItemFacade facade = (ItemFacade) facadeItemDefinition;
|
||||
|
||||
ItemStack facades = facade.createFacadeForItem( inv.getStackInSlot( 4 ), !createFacade );
|
||||
if ( facades != null && createFacade )
|
||||
facades.stackSize = 4;
|
||||
return facades;
|
||||
ItemStack facades = facade.createFacadeForItem( inv.getStackInSlot( 4 ), !createFacade );
|
||||
if ( facades != null && createFacade )
|
||||
facades.stackSize = 4;
|
||||
return facades;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user