2015-08-29 14:33:25 +02:00
/ *
* This file ( " CrusherRecipeManualRegistry.java " ) is part of the Actually Additions Mod for Minecraft .
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http : //github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https : //github.com/Ellpeck/ActuallyAdditions
*
* <EFBFBD> 2015 Ellpeck
* /
2015-03-07 12:51:28 +01:00
package ellpeck.actuallyadditions.recipe ;
2015-03-07 02:23:31 +01:00
2015-07-01 16:06:40 +02:00
import ellpeck.actuallyadditions.config.values.ConfigBoolValues ;
import ellpeck.actuallyadditions.util.ModUtil ;
import ellpeck.actuallyadditions.util.Util ;
2015-03-07 02:23:31 +01:00
import net.minecraft.item.ItemStack ;
2015-05-07 16:36:29 +02:00
import net.minecraftforge.oredict.OreDictionary ;
2015-03-07 02:23:31 +01:00
import java.util.ArrayList ;
2015-07-01 16:06:40 +02:00
public class CrusherRecipeManualRegistry {
2015-03-07 02:23:31 +01:00
2015-07-17 23:22:10 +02:00
public static ArrayList < CrusherRecipe > recipes = new ArrayList < CrusherRecipe > ( ) ;
2015-03-07 02:23:31 +01:00
2015-07-01 16:06:40 +02:00
public static void registerRecipe ( ItemStack input , ItemStack outputOne , ItemStack outputTwo , int secondChance ) {
if ( ! hasRecipe ( input , outputOne ) ) {
recipes . add ( new CrusherRecipe ( input , outputOne , outputTwo , secondChance ) ) ;
}
2015-07-01 15:14:39 +02:00
}
2015-07-01 16:06:40 +02:00
public static void registerRecipe ( String input , String outputOne , int outputOneAmount ) {
registerRecipe ( input , outputOne , " " , 0 , outputOneAmount , 0 ) ;
2015-03-07 02:23:31 +01:00
}
2015-07-01 16:06:40 +02:00
public static void registerRecipe ( String input , String outputOne , String outputTwo , int secondChance , int outputOneAmount , int outputTwoAmount ) {
2015-06-21 02:28:49 +02:00
ArrayList < ItemStack > inputStacks = ( ArrayList < ItemStack > ) OreDictionary . getOres ( input , false ) ;
ArrayList < ItemStack > outputOneStacks = ( ArrayList < ItemStack > ) OreDictionary . getOres ( outputOne , false ) ;
2015-07-01 21:32:48 +02:00
ArrayList < ItemStack > outputTwoStacks = ( outputTwo = = null | | outputTwo . isEmpty ( ) ) ? null : ( ArrayList < ItemStack > ) OreDictionary . getOres ( outputTwo , false ) ;
2015-05-07 16:36:29 +02:00
if ( inputStacks ! = null & & ! inputStacks . isEmpty ( ) ) {
2015-05-24 13:58:34 +02:00
for ( ItemStack anInput : inputStacks ) {
ItemStack theInput = anInput . copy ( ) ;
2015-05-07 16:36:29 +02:00
if ( outputOneStacks ! = null & & ! outputOneStacks . isEmpty ( ) ) {
2015-05-24 13:58:34 +02:00
for ( ItemStack anOutputOne : outputOneStacks ) {
ItemStack theOutputOne = anOutputOne . copy ( ) ;
2015-07-01 16:06:40 +02:00
theOutputOne . stackSize = outputOneAmount ;
2015-05-07 16:36:29 +02:00
if ( outputTwoStacks ! = null & & ! outputTwoStacks . isEmpty ( ) ) {
2015-05-24 13:58:34 +02:00
for ( ItemStack anOutputTwo : outputTwoStacks ) {
ItemStack theOutputTwo = anOutputTwo . copy ( ) ;
2015-07-01 16:06:40 +02:00
theOutputTwo . stackSize = outputTwoAmount ;
2015-06-21 02:28:49 +02:00
registerRecipe ( theInput , theOutputOne , theOutputTwo , secondChance ) ;
2015-05-07 16:36:29 +02:00
}
}
2015-06-21 02:28:49 +02:00
else registerRecipe ( theInput , theOutputOne , null , 0 ) ;
2015-05-07 16:36:29 +02:00
}
}
2015-07-01 16:06:40 +02:00
else {
if ( ConfigBoolValues . DO_CRUSHER_SPAM . isEnabled ( ) )
2015-07-01 18:14:21 +02:00
ModUtil . LOGGER . warn ( " Couldn't register Crusher Recipe! An Item with OreDictionary Registry ' " + outputOne + " ' doesn't exist! It should be the output of ' " + input + " '! " ) ;
2015-07-01 16:06:40 +02:00
}
2015-05-07 16:36:29 +02:00
}
}
2015-07-01 16:06:40 +02:00
else {
if ( ConfigBoolValues . DO_CRUSHER_SPAM . isEnabled ( ) )
2015-07-01 18:14:21 +02:00
ModUtil . LOGGER . warn ( " Couldn't register Crusher Recipe! Didn't find Items registered as ' " + input + " '! " ) ;
2015-07-01 16:06:40 +02:00
}
2015-05-07 16:36:29 +02:00
}
2015-06-21 02:28:49 +02:00
public static void registerRecipe ( ItemStack input , ItemStack outputOne ) {
registerRecipe ( input , outputOne , null , 0 ) ;
2015-05-07 16:36:29 +02:00
}
2015-06-21 02:28:49 +02:00
public static ItemStack getOutput ( ItemStack input , boolean wantSecond ) {
2015-07-01 16:06:40 +02:00
for ( CrusherRecipe recipe : recipes ) {
if ( recipe . input . isItemEqual ( input ) | | ( recipe . input . getItem ( ) = = input . getItem ( ) & & recipe . input . getItemDamage ( ) = = Util . WILDCARD ) ) {
2015-03-07 02:23:31 +01:00
return wantSecond ? recipe . secondOutput : recipe . firstOutput ;
}
}
return null ;
}
2015-06-21 02:28:49 +02:00
public static boolean hasRecipe ( ItemStack input , ItemStack outputOne ) {
2015-07-01 16:06:40 +02:00
for ( CrusherRecipe recipe : recipes ) {
if ( recipe . input . isItemEqual ( input ) & & recipe . firstOutput . isItemEqual ( outputOne ) | | ( recipe . input . getItem ( ) = = input . getItem ( ) & & recipe . firstOutput . getItem ( ) = = outputOne . getItem ( ) & & recipe . input . getItemDamage ( ) = = Util . WILDCARD ) ) return true ;
2015-05-04 17:26:50 +02:00
}
2015-05-25 17:00:54 +02:00
return false ;
2015-05-04 17:26:50 +02:00
}
2015-06-21 02:28:49 +02:00
public static int getSecondChance ( ItemStack input ) {
2015-07-01 16:06:40 +02:00
for ( CrusherRecipe recipe : recipes ) {
if ( recipe . input . isItemEqual ( input ) | | ( recipe . input . getItem ( ) = = input . getItem ( ) & & recipe . input . getItemDamage ( ) = = Util . WILDCARD ) ) {
2015-03-07 02:23:31 +01:00
return recipe . secondChance ;
}
}
return 0 ;
}
2015-07-01 16:06:40 +02:00
public static class CrusherRecipe {
2015-03-07 02:23:31 +01:00
public final ItemStack input ;
public final ItemStack firstOutput ;
public final ItemStack secondOutput ;
public final int secondChance ;
2015-07-01 16:06:40 +02:00
public CrusherRecipe ( ItemStack input , ItemStack firstOutput , ItemStack secondOutput , int secondChance ) {
2015-03-07 02:23:31 +01:00
this . input = input ;
this . firstOutput = firstOutput ;
this . secondOutput = secondOutput ;
this . secondChance = secondChance ;
}
}
}