reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
@@ -19,49 +19,40 @@
package appeng.recipes.factories.conditions;
import java.util.Locale;
import java.util.function.BooleanSupplier;
import java.util.stream.Stream;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.IConditionFactory;
import net.minecraftforge.common.crafting.JsonContext;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import java.util.Locale;
import java.util.function.BooleanSupplier;
import java.util.stream.Stream;
public class Features implements IConditionFactory
{
private static final String JSON_FEATURES_KEY = "features";
public class Features implements IConditionFactory {
private static final String JSON_FEATURES_KEY = "features";
@Override
public BooleanSupplier parse( JsonContext jsonContext, JsonObject jsonObject )
{
final boolean result;
@Override
public BooleanSupplier parse(JsonContext jsonContext, JsonObject jsonObject) {
final boolean result;
if( JsonUtils.isJsonArray( jsonObject, JSON_FEATURES_KEY ) )
{
final JsonArray features = JsonUtils.getJsonArray( jsonObject, JSON_FEATURES_KEY );
if (JsonUtils.isJsonArray(jsonObject, JSON_FEATURES_KEY)) {
final JsonArray features = JsonUtils.getJsonArray(jsonObject, JSON_FEATURES_KEY);
result = Stream.of( features )
.allMatch( p -> AEConfig.instance().isFeatureEnabled( AEFeature.valueOf( p.getAsString().toUpperCase( Locale.ENGLISH ) ) ) );
}
else if( JsonUtils.isString( jsonObject, JSON_FEATURES_KEY ) )
{
final String featureName = JsonUtils.getString( jsonObject, JSON_FEATURES_KEY ).toUpperCase( Locale.ENGLISH );
final AEFeature feature = AEFeature.valueOf( featureName );
result = Stream.of(features)
.allMatch(p -> AEConfig.instance().isFeatureEnabled(AEFeature.valueOf(p.getAsString().toUpperCase(Locale.ENGLISH))));
} else if (JsonUtils.isString(jsonObject, JSON_FEATURES_KEY)) {
final String featureName = JsonUtils.getString(jsonObject, JSON_FEATURES_KEY).toUpperCase(Locale.ENGLISH);
final AEFeature feature = AEFeature.valueOf(featureName);
result = AEConfig.instance().isFeatureEnabled( feature );
}
else
{
result = false;
}
result = AEConfig.instance().isFeatureEnabled(feature);
} else {
result = false;
}
return () -> result;
}
return () -> result;
}
}
@@ -19,40 +19,33 @@
package appeng.recipes.factories.conditions;
import java.util.function.BooleanSupplier;
import appeng.core.Api;
import appeng.core.AppEng;
import com.google.gson.JsonObject;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.IConditionFactory;
import net.minecraftforge.common.crafting.JsonContext;
import appeng.core.Api;
import appeng.core.AppEng;
import java.util.function.BooleanSupplier;
public class MaterialExists implements IConditionFactory
{
private static final String JSON_MATERIAL_KEY = "material";
public class MaterialExists implements IConditionFactory {
private static final String JSON_MATERIAL_KEY = "material";
@Override
public BooleanSupplier parse( JsonContext jsonContext, JsonObject jsonObject )
{
final boolean result;
@Override
public BooleanSupplier parse(JsonContext jsonContext, JsonObject jsonObject) {
final boolean result;
if( JsonUtils.isString( jsonObject, JSON_MATERIAL_KEY ) )
{
final String material = JsonUtils.getString( jsonObject, JSON_MATERIAL_KEY );
final Object item = Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, material );
if (JsonUtils.isString(jsonObject, JSON_MATERIAL_KEY)) {
final String material = JsonUtils.getString(jsonObject, JSON_MATERIAL_KEY);
final Object item = Api.INSTANCE.registries().recipes().resolveItem(AppEng.MOD_ID, material);
result = item != null;
}
else
{
result = false;
}
result = item != null;
} else {
result = false;
}
return () -> result;
return () -> result;
}
}
}
@@ -14,19 +14,15 @@ public class PartExists implements IConditionFactory {
private static final String JSON_MATERIAL_KEY = "part";
@Override
public BooleanSupplier parse(JsonContext jsonContext, JsonObject jsonObject )
{
public BooleanSupplier parse(JsonContext jsonContext, JsonObject jsonObject) {
final boolean result;
if( JsonUtils.isString( jsonObject, JSON_MATERIAL_KEY ) )
{
final String part = JsonUtils.getString( jsonObject, JSON_MATERIAL_KEY );
final Object item = Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, part );
if (JsonUtils.isString(jsonObject, JSON_MATERIAL_KEY)) {
final String part = JsonUtils.getString(jsonObject, JSON_MATERIAL_KEY);
final Object item = Api.INSTANCE.registries().recipes().resolveItem(AppEng.MOD_ID, part);
result = item != null;
}
else
{
} else {
result = false;
}
@@ -19,50 +19,43 @@
package appeng.recipes.factories.ingredients;
import javax.annotation.Nonnull;
import com.google.gson.JsonObject;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.crafting.IIngredientFactory;
import net.minecraftforge.common.crafting.JsonContext;
import appeng.api.recipes.ResolverResult;
import appeng.api.recipes.ResolverResultSet;
import appeng.core.AELog;
import appeng.core.Api;
import appeng.core.AppEng;
import com.google.gson.JsonObject;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.crafting.IIngredientFactory;
import net.minecraftforge.common.crafting.JsonContext;
import javax.annotation.Nonnull;
public class PartIngredientFactory implements IIngredientFactory
{
public class PartIngredientFactory implements IIngredientFactory {
@Nonnull
@Override
public net.minecraft.item.crafting.Ingredient parse( JsonContext context, JsonObject json )
{
final String partName = json.get( "part" ).getAsString();
final Object result = Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, partName );
@Nonnull
@Override
public net.minecraft.item.crafting.Ingredient parse(JsonContext context, JsonObject json) {
final String partName = json.get("part").getAsString();
final Object result = Api.INSTANCE.registries().recipes().resolveItem(AppEng.MOD_ID, partName);
if( result instanceof ResolverResultSet )
{
final ResolverResultSet resolverResultSet = (ResolverResultSet) result;
if (result instanceof ResolverResultSet) {
final ResolverResultSet resolverResultSet = (ResolverResultSet) result;
return net.minecraft.item.crafting.Ingredient
.fromStacks( resolverResultSet.results.toArray( new ItemStack[resolverResultSet.results.size()] ) );
}
else if( result instanceof ResolverResult )
{
final ResolverResult resolverResult = (ResolverResult) result;
return net.minecraft.item.crafting.Ingredient
.fromStacks(resolverResultSet.results.toArray(new ItemStack[resolverResultSet.results.size()]));
} else if (result instanceof ResolverResult) {
final ResolverResult resolverResult = (ResolverResult) result;
final Item item = Item.getByNameOrId( AppEng.MOD_ID + ":" + resolverResult.itemName );
final ItemStack itemStack = new ItemStack( item, 1, resolverResult.damageValue, resolverResult.compound );
final Item item = Item.getByNameOrId(AppEng.MOD_ID + ":" + resolverResult.itemName);
final ItemStack itemStack = new ItemStack(item, 1, resolverResult.damageValue, resolverResult.compound);
return net.minecraft.item.crafting.Ingredient.fromStacks( itemStack );
}
return net.minecraft.item.crafting.Ingredient.fromStacks(itemStack);
}
AELog.warn( "Looking for ingredient with name '" + partName + "' ended up with a null item!" );
return net.minecraft.item.crafting.Ingredient.EMPTY;
}
AELog.warn("Looking for ingredient with name '" + partName + "' ended up with a null item!");
return net.minecraft.item.crafting.Ingredient.EMPTY;
}
}
@@ -19,17 +19,13 @@
package appeng.recipes.factories.recipes;
import java.util.Map;
import java.util.Set;
import appeng.api.AEApi;
import appeng.api.recipes.ResolverResult;
import appeng.core.AELog;
import appeng.core.AppEng;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import com.google.gson.*;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
@@ -43,170 +39,135 @@ import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import appeng.api.AEApi;
import appeng.api.recipes.ResolverResult;
import appeng.core.AELog;
import appeng.core.AppEng;
import java.util.Map;
import java.util.Set;
/**
* @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" ) )
{
return shapedFactory( context, json );
}
else if( type.contains( "shapeless" ) )
{
return shapelessFactory( context, json );
}
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 + "'!" );
}
}
public class PartRecipeFactory implements IRecipeFactory {
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
String type = JsonUtils.getString(json, "type");
if (type.contains("shaped")) {
return shapedFactory(context, json);
} else if (type.contains("shapeless")) {
return shapelessFactory(context, json);
} 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 + "'!");
}
}
public static ItemStack getResult( JsonObject json, JsonContext context )
{
return getResult( json, context, "result" );
}
public static ItemStack getResult(JsonObject json, JsonContext context) {
return getResult(json, context, "result");
}
public static ItemStack getResult( JsonObject json, JsonContext context, String name )
{
JsonObject resultObject = JsonUtils.getJsonObject( json, name );
public static ItemStack getResult(JsonObject json, JsonContext context, String name) {
JsonObject resultObject = JsonUtils.getJsonObject(json, name);
if( resultObject.has( "part" ) )
{
return getPart( resultObject );
}
else if( resultObject.has( "item" ) )
{
return CraftingHelper.getItemStack( resultObject, context );
}
else
{
throw new JsonSyntaxException( "Result has no 'part' or 'item' property." );
}
}
if (resultObject.has("part")) {
return getPart(resultObject);
} else if (resultObject.has("item")) {
return CraftingHelper.getItemStack(resultObject, context);
} else {
throw new JsonSyntaxException("Result has no 'part' or 'item' property.");
}
}
private static ItemStack getPart( JsonObject resultObject )
{
String ingredient = JsonUtils.getString( resultObject, "part" );
Object result = AEApi.instance().registries().recipes().resolveItem( AppEng.MOD_ID, ingredient );
if( result instanceof ResolverResult )
{
ResolverResult resolverResult = (ResolverResult) result;
private static ItemStack getPart(JsonObject resultObject) {
String ingredient = JsonUtils.getString(resultObject, "part");
Object result = AEApi.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!");
}
return new ItemStack( item, JsonUtils.getInt( resultObject, "count", 1 ), resolverResult.damageValue, resolverResult.compound );
}
else
{
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 + "'." );
}
}
return new ItemStack(item, JsonUtils.getInt(resultObject, "count", 1), resolverResult.damageValue, resolverResult.compound);
} else {
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 + "'.");
}
}
// Copied from ShapedOreRecipe.java, modified a bit.
private static ShapedOreRecipe shapedFactory( JsonContext context, JsonObject json )
{
String group = JsonUtils.getString( json, "group", "" );
// Copied from ShapedOreRecipe.java, modified a bit.
private static ShapedOreRecipe shapedFactory(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);
}
return new ShapedOreRecipe( group.isEmpty() ? null : new ResourceLocation( group ), getResult( json, context ), primer );
}
return new ShapedOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), getResult(json, context), primer);
}
// Copied from ShapelessOreRecipe.java, modified a bit.
private static ShapelessOreRecipe shapelessFactory( JsonContext context, JsonObject json )
{
String group = JsonUtils.getString( json, "group", "" );
// Copied from ShapelessOreRecipe.java, modified a bit.
private static ShapelessOreRecipe shapelessFactory(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");
}
return new ShapelessOreRecipe( group.isEmpty() ? null : new ResourceLocation( group ), ings, getResult( json, context ) );
}
return new ShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), ings, getResult(json, context));
}
}