Format sourcecode

This commit is contained in:
yueh
2017-07-20 21:17:10 +02:00
parent 66437897be
commit 621910df91
295 changed files with 2142 additions and 1562 deletions
+12 -11
View File
@@ -416,7 +416,6 @@ public class RecipeHandler implements IRecipeHandler
}
}
for( final Entry<Class, Integer> e : processed.entrySet() )
{
AELog.info( "Recipes Loading: " + e.getKey().getSimpleName() + ": " + e.getValue() + " loaded." );
@@ -769,7 +768,8 @@ public class RecipeHandler implements IRecipeHandler
public static class MaterialExists implements IConditionFactory
{
@Override
public BooleanSupplier parse( JsonContext jsonContext, JsonObject jsonObject ) {
public BooleanSupplier parse( JsonContext jsonContext, JsonObject jsonObject )
{
String material = JsonUtils.getString( jsonObject, "material" );
Object result = (Object) Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, material );
return () -> result != null;
@@ -777,19 +777,20 @@ public class RecipeHandler implements IRecipeHandler
}
}
public static class PartFactory implements IIngredientFactory
{
public static class PartFactory implements IIngredientFactory
{
@Nonnull
@Override
public net.minecraft.item.crafting.Ingredient parse( JsonContext context, JsonObject json )
{
@Nonnull
@Override
public net.minecraft.item.crafting.Ingredient parse( JsonContext context, JsonObject json )
{
String partName = json.get( "part" ).getAsString();
Object result = (Object) Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, partName );
if( result instanceof ResolverResultSet )
{
ResolverResultSet resolverResultSet = (ResolverResultSet) result;
return net.minecraft.item.crafting.Ingredient.fromStacks(resolverResultSet.results.toArray(new ItemStack[resolverResultSet.results.size()]));
return net.minecraft.item.crafting.Ingredient
.fromStacks( resolverResultSet.results.toArray( new ItemStack[resolverResultSet.results.size()] ) );
}
else if( result instanceof ResolverResult )
{
@@ -803,7 +804,7 @@ public class RecipeHandler implements IRecipeHandler
AELog.warn( "Looking for ingredient with name '" + partName + "' ended up with a null item!" );
return net.minecraft.item.crafting.Ingredient.EMPTY;
}
}
}
}
}
@@ -163,7 +163,8 @@ public final class DisassembleRecipe extends net.minecraftforge.registries.IForg
}
@Override
public boolean canFit(int i, int i1) {
public boolean canFit( int i, int i1 )
{
return false;
}
@@ -60,7 +60,8 @@ public final class FacadeRecipe extends net.minecraftforge.registries.IForgeRegi
{
if( inv.getStackInSlot( 0 ).isEmpty() && inv.getStackInSlot( 2 ).isEmpty() && inv.getStackInSlot( 6 ).isEmpty() && inv.getStackInSlot( 8 ).isEmpty() )
{
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 ) ) )
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 ItemStack facades = facade.createFacadeForItem( inv.getStackInSlot( 4 ), !createFacade );
if( !facades.isEmpty() && createFacade )
@@ -81,7 +82,8 @@ public final class FacadeRecipe extends net.minecraftforge.registries.IForgeRegi
}
@Override
public boolean canFit(int i, int i1) {
public boolean canFit( int i, int i1 )
{
return false;
}
@@ -38,6 +38,7 @@ import appeng.api.recipes.IIngredient;
import javax.annotation.Nullable;
public class ShapedRecipe extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe, IRecipeBakeable
{
// Added in for future ease of change, but hard coded for now.
@@ -178,7 +179,8 @@ public class ShapedRecipe extends net.minecraftforge.registries.IForgeRegistryEn
}
@Override
public boolean canFit(int i, int i1) {
public boolean canFit( int i, int i1 )
{
return false;
}
@@ -273,7 +275,8 @@ public class ShapedRecipe extends net.minecraftforge.registries.IForgeRegistryEn
{
return false;
}
return( target.getItem() == input.getItem() && ( target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage() ) );
return( target.getItem() == input
.getItem() && ( target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage() ) );
}
public ShapedRecipe setMirrored( final boolean mirror )
@@ -138,7 +138,8 @@ public class ShapelessRecipe extends net.minecraftforge.registries.IForgeRegistr
}
@Override
public boolean canFit(int i, int i1) {
public boolean canFit( int i, int i1 )
{
return false;
}
@@ -150,7 +151,8 @@ public class ShapelessRecipe extends net.minecraftforge.registries.IForgeRegistr
private boolean checkItemEquals( final ItemStack target, final ItemStack input )
{
return( target.getItem() == input.getItem() && ( target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage() ) );
return( target.getItem() == input
.getItem() && ( target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage() ) );
}
/**
@@ -114,7 +114,7 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer
try
{
// TODO : 1.12 Cleanup/remove the old recipe loader.
// Registration.addRecipeToRegister( new ShapedRecipe( outIS, args.toArray( new Object[args.size()] ) ) );
// Registration.addRecipeToRegister( new ShapedRecipe( outIS, args.toArray( new Object[args.size()] ) ) );
}
catch( final Throwable e )
{
@@ -77,7 +77,8 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
try
{
// TODO : 1.12 Cleanup/remove the old recipe loader.
// Registration.addRecipeToRegister( new ShapelessRecipe( outIS, args.toArray( new Object[args.size()] ) ) );
// Registration.addRecipeToRegister( new ShapelessRecipe( outIS, args.toArray( new Object[args.size()] ) )
// );
}
catch( final Throwable e )
{
@@ -18,6 +18,7 @@
package appeng.recipes.helpers;
import appeng.core.AppEng;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
@@ -28,36 +29,37 @@ import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.common.crafting.JsonContext;
/**
* @author GuntherDW
*/
public class PartRecipeFactory implements IRecipeFactory
{
@Override
public IRecipe parse( JsonContext context, JsonObject json )
{
String type = JsonUtils.getString( json, "type" );
if( type.contains( "shaped" ) )
{
PartShapedCraftingFactory recipe = PartShapedCraftingFactory.factory( context, json );
CraftingHelper.ShapedPrimer primer = new CraftingHelper.ShapedPrimer();
primer.width = recipe.getWidth();
primer.height = recipe.getHeight();
primer.mirrored = JsonUtils.getBoolean( json, "mirrored", true );
primer.input = recipe.getIngredients();
@Override
public IRecipe parse( JsonContext context, JsonObject json )
{
String type = JsonUtils.getString( json, "type" );
if( type.contains( "shaped" ) )
{
PartShapedCraftingFactory recipe = PartShapedCraftingFactory.factory( context, json );
CraftingHelper.ShapedPrimer primer = new CraftingHelper.ShapedPrimer();
primer.width = recipe.getWidth();
primer.height = recipe.getHeight();
primer.mirrored = JsonUtils.getBoolean( json, "mirrored", true );
primer.input = recipe.getIngredients();
return new PartShapedCraftingFactory( new ResourceLocation( AppEng.MOD_ID, "part_shaped_crafting" ), recipe.getRecipeOutput(), primer );
}
else if( type.contains( "shapeless" ) )
{
PartShapelessCraftingFactory recipe = PartShapelessCraftingFactory.factory( context, json );
return new PartShapedCraftingFactory( new ResourceLocation( AppEng.MOD_ID, "part_shaped_crafting" ), recipe.getRecipeOutput(), primer );
}
else if( type.contains( "shapeless" ) )
{
PartShapelessCraftingFactory recipe = PartShapelessCraftingFactory.factory( context, json );
return new PartShapelessCraftingFactory( new ResourceLocation( AppEng.MOD_ID, "part_shapeless_crafting" ), recipe.getIngredients(), recipe.getRecipeOutput() );
}
else
{
throw new JsonSyntaxException( "Applied Energistics 2 was given a custom recipe that it does not know how to handle!\n"
+ "Type should either be '" + AppEng.MOD_ID + ":shapeless' or '" + AppEng.MOD_ID + ":shaped', got '" + type + "'!" );
}
}
return new PartShapelessCraftingFactory( new ResourceLocation( AppEng.MOD_ID, "part_shapeless_crafting" ), recipe.getIngredients(), recipe
.getRecipeOutput() );
}
else
{
throw new JsonSyntaxException( "Applied Energistics 2 was given a custom recipe that it does not know how to handle!\n" + "Type should either be '" + AppEng.MOD_ID + ":shapeless' or '" + AppEng.MOD_ID + ":shaped', got '" + type + "'!" );
}
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.helpers;
import appeng.api.recipes.ResolverResult;
import appeng.core.AELog;
import appeng.core.Api;
@@ -42,96 +43,96 @@ import javax.annotation.Nonnull;
import java.util.Map;
import java.util.Set;
/**
* @author GuntherDW
*/
public class PartShapedCraftingFactory extends ShapedOreRecipe
{
public PartShapedCraftingFactory( ResourceLocation group, @Nonnull ItemStack result, CraftingHelper.ShapedPrimer primer )
{
super( group, result, primer );
}
public PartShapedCraftingFactory( ResourceLocation group, @Nonnull ItemStack result, CraftingHelper.ShapedPrimer primer )
{
super( group, result, primer );
}
// Copied from ShapedOreRecipe.java, modified a bit.
public static PartShapedCraftingFactory factory( JsonContext context, JsonObject json )
{
String group = JsonUtils.getString( json, "group", "" );
// Copied from ShapedOreRecipe.java, modified a bit.
public static PartShapedCraftingFactory factory( JsonContext context, JsonObject json )
{
String group = JsonUtils.getString( json, "group", "" );
Map<Character, Ingredient> ingMap = Maps.newHashMap();
for( Map.Entry<String, JsonElement> entry : JsonUtils.getJsonObject( json, "key" ).entrySet() )
{
if( entry.getKey().length() != 1 )
throw new JsonSyntaxException( "Invalid key entry: '" + entry.getKey() + "' is an invalid symbol (must be 1 character only)." );
if( " ".equals( entry.getKey() ) )
throw new JsonSyntaxException( "Invalid key entry: ' ' is a reserved symbol." );
Map<Character, Ingredient> ingMap = Maps.newHashMap();
for( Map.Entry<String, JsonElement> entry : JsonUtils.getJsonObject( json, "key" ).entrySet() )
{
if( entry.getKey().length() != 1 )
throw new JsonSyntaxException( "Invalid key entry: '" + entry.getKey() + "' is an invalid symbol (must be 1 character only)." );
if( " ".equals( entry.getKey() ) )
throw new JsonSyntaxException( "Invalid key entry: ' ' is a reserved symbol." );
ingMap.put( entry.getKey().toCharArray()[0], CraftingHelper.getIngredient( entry.getValue(), context ) );
}
ingMap.put( entry.getKey().toCharArray()[0], CraftingHelper.getIngredient( entry.getValue(), context ) );
}
ingMap.put( ' ', net.minecraft.item.crafting.Ingredient.EMPTY );
ingMap.put( ' ', net.minecraft.item.crafting.Ingredient.EMPTY );
JsonArray patternJ = JsonUtils.getJsonArray( json, "pattern" );
JsonArray patternJ = JsonUtils.getJsonArray( json, "pattern" );
if( patternJ.size() == 0 )
throw new JsonSyntaxException( "Invalid pattern: empty pattern not allowed" );
if( patternJ.size() == 0 )
throw new JsonSyntaxException( "Invalid pattern: empty pattern not allowed" );
String[] pattern = new String[patternJ.size()];
for( int x = 0; x < pattern.length; ++x )
{
String line = JsonUtils.getString( patternJ.get( x ), "pattern[" + x + "]" );
if( x > 0 && pattern[0].length() != line.length() )
throw new JsonSyntaxException( "Invalid pattern: each row must be the same width" );
pattern[x] = line;
}
String[] pattern = new String[patternJ.size()];
for( int x = 0; x < pattern.length; ++x )
{
String line = JsonUtils.getString( patternJ.get( x ), "pattern[" + x + "]" );
if( x > 0 && pattern[0].length() != line.length() )
throw new JsonSyntaxException( "Invalid pattern: each row must be the same width" );
pattern[x] = line;
}
CraftingHelper.ShapedPrimer primer = new CraftingHelper.ShapedPrimer();
primer.width = pattern[0].length();
primer.height = pattern.length;
primer.mirrored = JsonUtils.getBoolean( json, "mirrored", true );
primer.input = NonNullList.withSize( primer.width * primer.height, net.minecraft.item.crafting.Ingredient.EMPTY );
CraftingHelper.ShapedPrimer primer = new CraftingHelper.ShapedPrimer();
primer.width = pattern[0].length();
primer.height = pattern.length;
primer.mirrored = JsonUtils.getBoolean( json, "mirrored", true );
primer.input = NonNullList.withSize( primer.width * primer.height, net.minecraft.item.crafting.Ingredient.EMPTY );
Set<Character> keys = Sets.newHashSet( ingMap.keySet() );
keys.remove( ' ' );
Set<Character> keys = Sets.newHashSet( ingMap.keySet() );
keys.remove( ' ' );
int x = 0;
for( String line : pattern )
{
for( char chr : line.toCharArray() )
{
net.minecraft.item.crafting.Ingredient ing = ingMap.get( chr );
if( ing == null )
throw new JsonSyntaxException( "Pattern references symbol '" + chr + "' but it's not defined in the key" );
primer.input.set( x++, ing );
keys.remove( chr );
}
}
int x = 0;
for( String line : pattern )
{
for( char chr : line.toCharArray() )
{
net.minecraft.item.crafting.Ingredient ing = ingMap.get( chr );
if( ing == null )
throw new JsonSyntaxException( "Pattern references symbol '" + chr + "' but it's not defined in the key" );
primer.input.set( x++, ing );
keys.remove( chr );
}
}
if( !keys.isEmpty() )
throw new JsonSyntaxException( "Key defines symbols that aren't used in pattern: " + keys );
if( !keys.isEmpty() )
throw new JsonSyntaxException( "Key defines symbols that aren't used in pattern: " + keys );
JsonObject resultObject = (JsonObject) json.get( "result" );
int count = JsonUtils.getInt( resultObject, "count", 1 );
JsonObject resultObject = (JsonObject) json.get( "result" );
int count = JsonUtils.getInt( resultObject, "count", 1);
String ingredient = resultObject.get( "part" ).getAsString();
Object result = (Object) Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, ingredient );
if( result instanceof ResolverResult )
{
ResolverResult resolverResult = (ResolverResult) result;
String ingredient = resultObject.get( "part" ).getAsString();
Object result = (Object) Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, ingredient );
if( result instanceof ResolverResult )
{
ResolverResult resolverResult = (ResolverResult) result;
Item item = Item.getByNameOrId( AppEng.MOD_ID + ":" + resolverResult.itemName );
if( item == null )
{
AELog.warn( "item was null for " + resolverResult.itemName + " ( " + ingredient + " )!" );
throw new JsonSyntaxException( "Got a null item for " + resolverResult.itemName + " ( " + ingredient + " ). This should never happen!" );
}
ItemStack itemStack = new ItemStack( item, count, resolverResult.damageValue, resolverResult.compound );
Item item = Item.getByNameOrId( AppEng.MOD_ID + ":" + resolverResult.itemName );
if(item == null)
{
AELog.warn( "item was null for " + resolverResult.itemName + " ( " + ingredient + " )!" );
throw new JsonSyntaxException ( "Got a null item for " + resolverResult.itemName + " ( " + ingredient + " ). This should never happen!" );
}
ItemStack itemStack = new ItemStack( item, count, resolverResult.damageValue, resolverResult.compound );
return new PartShapedCraftingFactory( group.isEmpty() ? null : new ResourceLocation( group ), itemStack, primer );
}
return new PartShapedCraftingFactory( group.isEmpty() ? null : new ResourceLocation( group ), itemStack, primer );
}
// Should never reach this part unless mangled JSON or bug in AE.
throw new JsonSyntaxException ( "Couldn't find the resulting item in AE. This means AE was provided a recipe that it shouldn't be handling.\nWas looking for : '" + ingredient + "'." );
}
// Should never reach this part unless mangled JSON or bug in AE.
throw new JsonSyntaxException( "Couldn't find the resulting item in AE. This means AE was provided a recipe that it shouldn't be handling.\nWas looking for : '" + ingredient + "'." );
}
}
@@ -18,6 +18,7 @@
package appeng.recipes.helpers;
import appeng.api.recipes.ResolverResult;
import appeng.api.recipes.ResolverResultSet;
import appeng.core.AELog;
@@ -39,52 +40,52 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
import javax.annotation.Nonnull;
/**
* @author GuntherDW
*/
public class PartShapelessCraftingFactory extends ShapelessOreRecipe
{
public PartShapelessCraftingFactory( ResourceLocation group, NonNullList<Ingredient> input, @Nonnull ItemStack result )
{
super( group, input, result );
}
public PartShapelessCraftingFactory( ResourceLocation group, NonNullList<Ingredient> input, @Nonnull ItemStack result )
{
super( group, input, result );
}
// Copied from ShapelessOreRecipe.java, modified a bit.
public static PartShapelessCraftingFactory factory( JsonContext context, JsonObject json)
{
String group = JsonUtils.getString(json, "group", "");
// Copied from ShapelessOreRecipe.java, modified a bit.
public static PartShapelessCraftingFactory factory( JsonContext context, JsonObject json )
{
String group = JsonUtils.getString( json, "group", "" );
NonNullList<Ingredient> ings = NonNullList.create();
for( JsonElement ele : JsonUtils.getJsonArray( json, "ingredients" ) )
ings.add( CraftingHelper.getIngredient( ele, context ) );
NonNullList<Ingredient> ings = NonNullList.create();
for( JsonElement ele : JsonUtils.getJsonArray( json, "ingredients" ) )
ings.add( CraftingHelper.getIngredient( ele, context ) );
if( ings.isEmpty() )
throw new JsonParseException("No ingredients for shapeless recipe");
if( ings.isEmpty() )
throw new JsonParseException( "No ingredients for shapeless recipe" );
JsonObject resultObject = (JsonObject) json.get( "result" );
int count = JsonUtils.getInt( resultObject, "count", 1);
JsonObject resultObject = (JsonObject) json.get( "result" );
int count = JsonUtils.getInt( resultObject, "count", 1 );
String ingredient = resultObject.get( "part" ).getAsString();
Object result = (Object) Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, ingredient );
if( result instanceof ResolverResult )
{
ResolverResult resolverResult = (ResolverResult) result;
String ingredient = resultObject.get( "part" ).getAsString();
Object result = (Object) Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, ingredient );
if( result instanceof ResolverResult )
{
ResolverResult resolverResult = (ResolverResult) result;
Item item = Item.getByNameOrId( AppEng.MOD_ID + ":" + resolverResult.itemName );
Item item = Item.getByNameOrId( AppEng.MOD_ID + ":" + resolverResult.itemName );
if( item == null )
{
AELog.warn( "item was null for " + resolverResult.itemName + " ( " + ingredient + " )!" );
throw new JsonSyntaxException ( "Got a null item for " + resolverResult.itemName + " ( " + ingredient + " ). This should never happen!" );
}
if( item == null )
{
AELog.warn( "item was null for " + resolverResult.itemName + " ( " + ingredient + " )!" );
throw new JsonSyntaxException( "Got a null item for " + resolverResult.itemName + " ( " + ingredient + " ). This should never happen!" );
}
ItemStack itemStack = new ItemStack( item, count, resolverResult.damageValue, resolverResult.compound );
ItemStack itemStack = new ItemStack( item, count, resolverResult.damageValue, resolverResult.compound );
return new PartShapelessCraftingFactory(group.isEmpty() ? null : new ResourceLocation(group), ings, itemStack);
}
return new PartShapelessCraftingFactory( group.isEmpty() ? null : new ResourceLocation( group ), ings, itemStack );
}
throw new JsonSyntaxException( "Couldn't find the resulting item in AE. This means AE was provided a recipe that it shouldn't be handling.\n"
+ "Was looking for : '" + ingredient + "'." );
}
throw new JsonSyntaxException( "Couldn't find the resulting item in AE. This means AE was provided a recipe that it shouldn't be handling.\n" + "Was looking for : '" + ingredient + "'." );
}
}