reformatted all src files (#141)
This commit is contained in:
@@ -19,8 +19,6 @@
|
||||
package appeng.recipes;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.api.definitions.IItems;
|
||||
@@ -36,162 +34,131 @@ import appeng.items.materials.MaterialType;
|
||||
import appeng.items.misc.ItemCrystalSeed;
|
||||
import appeng.items.parts.ItemPart;
|
||||
import appeng.items.parts.PartType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class AEItemResolver implements ISubItemResolver
|
||||
{
|
||||
public class AEItemResolver implements ISubItemResolver {
|
||||
|
||||
@Override
|
||||
public Object resolveItemByName( final String nameSpace, final String itemName )
|
||||
{
|
||||
@Override
|
||||
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 (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." ) )
|
||||
{
|
||||
return this.paintBall( items.coloredPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), false );
|
||||
}
|
||||
if (itemName.startsWith("paint_ball.")) {
|
||||
return this.paintBall(items.coloredPaintBall(), itemName.substring(itemName.indexOf('.') + 1), false);
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "lumen_paint_ball." ) )
|
||||
{
|
||||
return this.paintBall( items.coloredPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), true );
|
||||
}
|
||||
if (itemName.startsWith("lumen_paint_ball.")) {
|
||||
return this.paintBall(items.coloredPaintBall(), itemName.substring(itemName.indexOf('.') + 1), true);
|
||||
}
|
||||
|
||||
if( itemName.equals( "cable_glass" ) )
|
||||
{
|
||||
return new ResolverResultSet( "cable_glass", parts.cableGlass().allStacks( 1 ) );
|
||||
}
|
||||
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.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.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.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.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.startsWith("cable_smart.")) {
|
||||
return this.cableItem(parts.cableSmart(), itemName.substring(itemName.indexOf('.') + 1));
|
||||
}
|
||||
|
||||
if( itemName.equals( "cable_dense_covered" ) )
|
||||
{
|
||||
return new ResolverResultSet( "cable_dense_covered", parts.cableDenseCovered().allStacks( 1 ) );
|
||||
}
|
||||
if (itemName.equals("cable_dense_covered")) {
|
||||
return new ResolverResultSet("cable_dense_covered", parts.cableDenseCovered().allStacks(1));
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "cable_dense_covered." ) )
|
||||
{
|
||||
return this.cableItem( parts.cableDenseCovered(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
if (itemName.startsWith("cable_dense_covered.")) {
|
||||
return this.cableItem(parts.cableDenseCovered(), itemName.substring(itemName.indexOf('.') + 1));
|
||||
}
|
||||
|
||||
if( itemName.equals( "cable_dense_smart" ) )
|
||||
{
|
||||
return new ResolverResultSet( "cable_dense_smart", parts.cableDenseSmart().allStacks( 1 ) );
|
||||
}
|
||||
if (itemName.equals("cable_dense_smart")) {
|
||||
return new ResolverResultSet("cable_dense_smart", parts.cableDenseSmart().allStacks(1));
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "cable_dense_smart." ) )
|
||||
{
|
||||
return this.cableItem( parts.cableDenseSmart(), itemName.substring( itemName.indexOf( '.' ) + 1 ) );
|
||||
}
|
||||
if (itemName.startsWith("cable_dense_smart.")) {
|
||||
return this.cableItem(parts.cableDenseSmart(), itemName.substring(itemName.indexOf('.') + 1));
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "crystal_seed." ) )
|
||||
{
|
||||
if( itemName.equalsIgnoreCase( "crystal_seed.certus" ) )
|
||||
{
|
||||
return ItemCrystalSeed.getResolver( ItemCrystalSeed.CERTUS );
|
||||
}
|
||||
if( itemName.equalsIgnoreCase( "crystal_seed.nether" ) )
|
||||
{
|
||||
return ItemCrystalSeed.getResolver( ItemCrystalSeed.NETHER );
|
||||
}
|
||||
if( itemName.equalsIgnoreCase( "crystal_seed.fluix" ) )
|
||||
{
|
||||
return ItemCrystalSeed.getResolver( ItemCrystalSeed.FLUIX );
|
||||
}
|
||||
if (itemName.startsWith("crystal_seed.")) {
|
||||
if (itemName.equalsIgnoreCase("crystal_seed.certus")) {
|
||||
return ItemCrystalSeed.getResolver(ItemCrystalSeed.CERTUS);
|
||||
}
|
||||
if (itemName.equalsIgnoreCase("crystal_seed.nether")) {
|
||||
return ItemCrystalSeed.getResolver(ItemCrystalSeed.NETHER);
|
||||
}
|
||||
if (itemName.equalsIgnoreCase("crystal_seed.fluix")) {
|
||||
return ItemCrystalSeed.getResolver(ItemCrystalSeed.FLUIX);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "material." ) )
|
||||
{
|
||||
final String materialName = itemName.substring( itemName.indexOf( '.' ) + 1 );
|
||||
final MaterialType mt = MaterialType.valueOf( materialName.toUpperCase() );
|
||||
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
|
||||
if( mt.getItemInstance() == ItemMaterial.instance && mt.getDamageValue() >= 0 && mt.isRegistered() )
|
||||
{
|
||||
return new ResolverResult( "material", mt.getDamageValue() );
|
||||
}
|
||||
}
|
||||
if (itemName.startsWith("material.")) {
|
||||
final String materialName = itemName.substring(itemName.indexOf('.') + 1);
|
||||
final MaterialType mt = MaterialType.valueOf(materialName.toUpperCase());
|
||||
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
|
||||
if (mt.getItemInstance() == ItemMaterial.instance && mt.getDamageValue() >= 0 && mt.isRegistered()) {
|
||||
return new ResolverResult("material", mt.getDamageValue());
|
||||
}
|
||||
}
|
||||
|
||||
if( itemName.startsWith( "part." ) )
|
||||
{
|
||||
final String partName = itemName.substring( itemName.indexOf( '.' ) + 1 );
|
||||
final PartType pt = PartType.valueOf( partName.toUpperCase() );
|
||||
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
|
||||
final int dVal = ItemPart.instance.getDamageByType( pt );
|
||||
if( dVal >= 0 )
|
||||
{
|
||||
return new ResolverResult( "part", dVal );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (itemName.startsWith("part.")) {
|
||||
final String partName = itemName.substring(itemName.indexOf('.') + 1);
|
||||
final PartType pt = PartType.valueOf(partName.toUpperCase());
|
||||
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
|
||||
final int dVal = ItemPart.instance.getDamageByType(pt);
|
||||
if (dVal >= 0) {
|
||||
return new ResolverResult("part", dVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object paintBall( final AEColoredItemDefinition partType, final String substring, final boolean lumen )
|
||||
{
|
||||
AEColor col;
|
||||
private Object paintBall(final AEColoredItemDefinition partType, final String substring, final boolean lumen) {
|
||||
AEColor col;
|
||||
|
||||
try
|
||||
{
|
||||
col = AEColor.valueOf( substring.toUpperCase() );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
col = AEColor.TRANSPARENT;
|
||||
}
|
||||
try {
|
||||
col = AEColor.valueOf(substring.toUpperCase());
|
||||
} catch (final Throwable t) {
|
||||
col = AEColor.TRANSPARENT;
|
||||
}
|
||||
|
||||
if( col == AEColor.TRANSPARENT )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (col == AEColor.TRANSPARENT) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack is = partType.stack( col, 1 );
|
||||
return new ResolverResult( "paint_ball", ( lumen ? 20 : 0 ) + is.getItemDamage() );
|
||||
}
|
||||
final ItemStack is = partType.stack(col, 1);
|
||||
return new ResolverResult("paint_ball", (lumen ? 20 : 0) + is.getItemDamage());
|
||||
}
|
||||
|
||||
private Object cableItem( final AEColoredItemDefinition partType, final String substring )
|
||||
{
|
||||
AEColor col;
|
||||
private Object cableItem(final AEColoredItemDefinition partType, final String substring) {
|
||||
AEColor col;
|
||||
|
||||
try
|
||||
{
|
||||
col = AEColor.valueOf( substring.toUpperCase() );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
col = AEColor.TRANSPARENT;
|
||||
}
|
||||
try {
|
||||
col = AEColor.valueOf(substring.toUpperCase());
|
||||
} catch (final Throwable t) {
|
||||
col = AEColor.TRANSPARENT;
|
||||
}
|
||||
|
||||
final ItemStack is = partType.stack( col, 1 );
|
||||
return new ResolverResult( "part", is.getItemDamage() );
|
||||
}
|
||||
final ItemStack is = partType.stack(col, 1);
|
||||
return new ResolverResult("part", is.getItemDamage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,21 @@
|
||||
|
||||
package appeng.recipes;
|
||||
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import appeng.recipes.handlers.GrinderHandler;
|
||||
import appeng.recipes.handlers.InscriberHandler;
|
||||
import appeng.recipes.handlers.SmeltingHandler;
|
||||
import com.google.gson.*;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -9,123 +23,82 @@ import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
public class AERecipeLoader {
|
||||
private static final String AERECIPE_BASE = "/aerecipes";
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
private final Map<ResourceLocation, IAERecipeFactory> factories = new HashMap<>();
|
||||
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
private final ModContainer mod;
|
||||
private final JsonContext ctx;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import appeng.recipes.handlers.GrinderHandler;
|
||||
import appeng.recipes.handlers.InscriberHandler;
|
||||
import appeng.recipes.handlers.SmeltingHandler;
|
||||
public AERecipeLoader() {
|
||||
this.mod = Loader.instance().getIndexedModList().get(AppEng.MOD_ID);
|
||||
this.ctx = new JsonContext(AppEng.MOD_ID);
|
||||
|
||||
this.initFactories();
|
||||
}
|
||||
|
||||
public class AERecipeLoader
|
||||
{
|
||||
private static final String AERECIPE_BASE = "/aerecipes";
|
||||
private static Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
private final Map<ResourceLocation, IAERecipeFactory> factories = new HashMap<>();
|
||||
public boolean loadProcessingRecipes() {
|
||||
return CraftingHelper.findFiles(this.mod, "assets/" + AppEng.MOD_ID + AERECIPE_BASE, this::preprocess, this::process, true, true);
|
||||
}
|
||||
|
||||
private final ModContainer mod;
|
||||
private final JsonContext ctx;
|
||||
private boolean preprocess(final Path root) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public AERecipeLoader()
|
||||
{
|
||||
this.mod = Loader.instance().getIndexedModList().get( AppEng.MOD_ID );
|
||||
this.ctx = new JsonContext( AppEng.MOD_ID );
|
||||
private boolean process(final Path root, final Path file) {
|
||||
String relative = root.relativize(file).toString();
|
||||
if (!"json".equals(FilenameUtils.getExtension(file.toString())) || relative.startsWith("_")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.initFactories();
|
||||
}
|
||||
String name = FilenameUtils.removeExtension(relative).replaceAll("\\\\", "/");
|
||||
ResourceLocation key = new ResourceLocation(this.ctx.getModId(), name);
|
||||
|
||||
public boolean loadProcessingRecipes()
|
||||
{
|
||||
return CraftingHelper.findFiles( this.mod, "assets/" + AppEng.MOD_ID + AERECIPE_BASE, this::preprocess, this::process, true, true );
|
||||
}
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = Files.newBufferedReader(file);
|
||||
JsonObject json = JsonUtils.fromJson(GSON, reader, JsonObject.class);
|
||||
if (json.has("conditions") && !CraftingHelper.processConditions(JsonUtils.getJsonArray(json, "conditions"), this.ctx)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean preprocess( final Path root )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
this.register(json);
|
||||
} catch (JsonParseException e) {
|
||||
FMLLog.log.error("Parsing error loading recipe {}", key, e);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
FMLLog.log.error("Couldn't read recipe {} from {}", key, file, e);
|
||||
return false;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
|
||||
private boolean process( final Path root, final Path file )
|
||||
{
|
||||
String relative = root.relativize( file ).toString();
|
||||
if( !"json".equals( FilenameUtils.getExtension( file.toString() ) ) || relative.startsWith( "_" ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = FilenameUtils.removeExtension( relative ).replaceAll( "\\\\", "/" );
|
||||
ResourceLocation key = new ResourceLocation( this.ctx.getModId(), name );
|
||||
private void register(JsonObject json) {
|
||||
if (json == null || json.isJsonNull()) {
|
||||
throw new JsonSyntaxException("Json cannot be null");
|
||||
}
|
||||
|
||||
BufferedReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = Files.newBufferedReader( file );
|
||||
JsonObject json = JsonUtils.fromJson( GSON, reader, JsonObject.class );
|
||||
if( json.has( "conditions" ) && !CraftingHelper.processConditions( JsonUtils.getJsonArray( json, "conditions" ), this.ctx ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
String type = this.ctx.appendModId(JsonUtils.getString(json, "type"));
|
||||
if (type.isEmpty()) {
|
||||
throw new JsonSyntaxException("Recipe type can not be an empty string");
|
||||
}
|
||||
|
||||
this.register( json );
|
||||
}
|
||||
catch( JsonParseException e )
|
||||
{
|
||||
FMLLog.log.error( "Parsing error loading recipe {}", key, e );
|
||||
return false;
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
FMLLog.log.error( "Couldn't read recipe {} from {}", key, file, e );
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly( reader );
|
||||
}
|
||||
IAERecipeFactory factory = this.factories.get(new ResourceLocation(type));
|
||||
if (factory == null) {
|
||||
throw new JsonSyntaxException("Unknown recipe type: " + type);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
factory.register(json, this.ctx);
|
||||
}
|
||||
|
||||
private void register( JsonObject json )
|
||||
{
|
||||
if( json == null || json.isJsonNull() )
|
||||
{
|
||||
throw new JsonSyntaxException( "Json cannot be null" );
|
||||
}
|
||||
|
||||
String type = this.ctx.appendModId( JsonUtils.getString( json, "type" ) );
|
||||
if( type.isEmpty() )
|
||||
{
|
||||
throw new JsonSyntaxException( "Recipe type can not be an empty string" );
|
||||
}
|
||||
|
||||
IAERecipeFactory factory = this.factories.get( new ResourceLocation( type ) );
|
||||
if( factory == null )
|
||||
{
|
||||
throw new JsonSyntaxException( "Unknown recipe type: " + type );
|
||||
}
|
||||
|
||||
factory.register( json, this.ctx );
|
||||
}
|
||||
|
||||
private void initFactories()
|
||||
{
|
||||
this.factories.put( new ResourceLocation( AppEng.MOD_ID, "inscriber" ), new InscriberHandler() );
|
||||
this.factories.put( new ResourceLocation( AppEng.MOD_ID, "smelt" ), new SmeltingHandler() );
|
||||
this.factories.put( new ResourceLocation( AppEng.MOD_ID, "grinder" ), new GrinderHandler() );
|
||||
}
|
||||
private void initFactories() {
|
||||
this.factories.put(new ResourceLocation(AppEng.MOD_ID, "inscriber"), new InscriberHandler());
|
||||
this.factories.put(new ResourceLocation(AppEng.MOD_ID, "smelt"), new SmeltingHandler());
|
||||
this.factories.put(new ResourceLocation(AppEng.MOD_ID, "grinder"), new GrinderHandler());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
|
||||
package appeng.recipes;
|
||||
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
|
||||
|
||||
public interface IAERecipeFactory
|
||||
{
|
||||
void register( JsonObject json, JsonContext ctx );
|
||||
public interface IAERecipeFactory {
|
||||
void register(JsonObject json, JsonContext ctx);
|
||||
}
|
||||
|
||||
@@ -29,17 +29,14 @@ import appeng.api.recipes.IRecipeLoader;
|
||||
* @version rv3 - 10.08.2015
|
||||
* @since rv0
|
||||
*/
|
||||
public class RecipeHandler implements IRecipeHandler
|
||||
{
|
||||
@Override
|
||||
public void parseRecipes( final IRecipeLoader loader, final String path )
|
||||
{
|
||||
// dummy
|
||||
}
|
||||
public class RecipeHandler implements IRecipeHandler {
|
||||
@Override
|
||||
public void parseRecipes(final IRecipeLoader loader, final String path) {
|
||||
// dummy
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectRecipes()
|
||||
{
|
||||
// dummy
|
||||
}
|
||||
@Override
|
||||
public void injectRecipes() {
|
||||
// dummy
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,12 @@
|
||||
package appeng.recipes.game;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.*;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -34,154 +33,130 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
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.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public final class DisassembleRecipe extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
private static final ItemStack MISMATCHED_STACK = ItemStack.EMPTY;
|
||||
public final class DisassembleRecipe extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
|
||||
private static final ItemStack MISMATCHED_STACK = ItemStack.EMPTY;
|
||||
|
||||
private final Map<IItemDefinition, IItemDefinition> cellMappings;
|
||||
private final Map<IItemDefinition, IItemDefinition> nonCellMappings;
|
||||
private final Map<IItemDefinition, IItemDefinition> cellMappings;
|
||||
private final Map<IItemDefinition, IItemDefinition> nonCellMappings;
|
||||
|
||||
public DisassembleRecipe()
|
||||
{
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
final IBlocks blocks = definitions.blocks();
|
||||
final IItems items = definitions.items();
|
||||
final IMaterials mats = definitions.materials();
|
||||
public DisassembleRecipe() {
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
final IBlocks blocks = definitions.blocks();
|
||||
final IItems items = definitions.items();
|
||||
final IMaterials mats = definitions.materials();
|
||||
|
||||
this.cellMappings = new HashMap<>( 4 );
|
||||
this.nonCellMappings = new HashMap<>( 5 );
|
||||
this.cellMappings = new HashMap<>(4);
|
||||
this.nonCellMappings = new HashMap<>(5);
|
||||
|
||||
this.cellMappings.put( items.cell1k(), mats.cell1kPart() );
|
||||
this.cellMappings.put( items.cell4k(), mats.cell4kPart() );
|
||||
this.cellMappings.put( items.cell16k(), mats.cell16kPart() );
|
||||
this.cellMappings.put( items.cell64k(), mats.cell64kPart() );
|
||||
this.cellMappings.put(items.cell1k(), mats.cell1kPart());
|
||||
this.cellMappings.put(items.cell4k(), mats.cell4kPart());
|
||||
this.cellMappings.put(items.cell16k(), mats.cell16kPart());
|
||||
this.cellMappings.put(items.cell64k(), mats.cell64kPart());
|
||||
|
||||
this.nonCellMappings.put( items.encodedPattern(), mats.blankPattern() );
|
||||
this.nonCellMappings.put( blocks.craftingStorage1k(), mats.cell1kPart() );
|
||||
this.nonCellMappings.put( blocks.craftingStorage4k(), mats.cell4kPart() );
|
||||
this.nonCellMappings.put( blocks.craftingStorage16k(), mats.cell16kPart() );
|
||||
this.nonCellMappings.put( blocks.craftingStorage64k(), mats.cell64kPart() );
|
||||
}
|
||||
this.nonCellMappings.put(items.encodedPattern(), mats.blankPattern());
|
||||
this.nonCellMappings.put(blocks.craftingStorage1k(), mats.cell1kPart());
|
||||
this.nonCellMappings.put(blocks.craftingStorage4k(), mats.cell4kPart());
|
||||
this.nonCellMappings.put(blocks.craftingStorage16k(), mats.cell16kPart());
|
||||
this.nonCellMappings.put(blocks.craftingStorage64k(), mats.cell64kPart());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches( final InventoryCrafting inv, final World w )
|
||||
{
|
||||
return !this.getOutput( inv ).isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean matches(final InventoryCrafting inv, final World w) {
|
||||
return !this.getOutput(inv).isEmpty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ItemStack getOutput( final IInventory inventory )
|
||||
{
|
||||
int itemCount = 0;
|
||||
ItemStack output = MISMATCHED_STACK;
|
||||
@Nullable
|
||||
private ItemStack getOutput(final IInventory inventory) {
|
||||
int itemCount = 0;
|
||||
ItemStack output = MISMATCHED_STACK;
|
||||
|
||||
for( int slotIndex = 0; slotIndex < inventory.getSizeInventory(); slotIndex++ )
|
||||
{
|
||||
final ItemStack stackInSlot = inventory.getStackInSlot( slotIndex );
|
||||
if( !stackInSlot.isEmpty() )
|
||||
{
|
||||
// needs a single input in the recipe
|
||||
itemCount++;
|
||||
if( itemCount > 1 )
|
||||
{
|
||||
return MISMATCHED_STACK;
|
||||
}
|
||||
for (int slotIndex = 0; slotIndex < inventory.getSizeInventory(); slotIndex++) {
|
||||
final ItemStack stackInSlot = inventory.getStackInSlot(slotIndex);
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
// needs a single input in the recipe
|
||||
itemCount++;
|
||||
if (itemCount > 1) {
|
||||
return MISMATCHED_STACK;
|
||||
}
|
||||
|
||||
// handle storage cells
|
||||
Optional<ItemStack> maybeCellOutput = this.getCellOutput( stackInSlot );
|
||||
if( maybeCellOutput.isPresent() )
|
||||
{
|
||||
ItemStack storageCellStack = maybeCellOutput.get();
|
||||
// make sure the storage cell stackInSlot empty...
|
||||
final IMEInventory<IAEItemStack> cellInv = AEApi.instance()
|
||||
.registries()
|
||||
.cell()
|
||||
.getCellInventory( stackInSlot, null,
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
if( cellInv != null )
|
||||
{
|
||||
final IItemList<IAEItemStack> list = cellInv
|
||||
.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||
if( !list.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
// handle storage cells
|
||||
Optional<ItemStack> maybeCellOutput = this.getCellOutput(stackInSlot);
|
||||
if (maybeCellOutput.isPresent()) {
|
||||
ItemStack storageCellStack = maybeCellOutput.get();
|
||||
// make sure the storage cell stackInSlot empty...
|
||||
final IMEInventory<IAEItemStack> cellInv = AEApi.instance()
|
||||
.registries()
|
||||
.cell()
|
||||
.getCellInventory(stackInSlot, null,
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
if (cellInv != null) {
|
||||
final IItemList<IAEItemStack> list = cellInv
|
||||
.getAvailableItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
|
||||
if (!list.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
output = storageCellStack;
|
||||
}
|
||||
output = storageCellStack;
|
||||
}
|
||||
|
||||
// handle crafting storage blocks
|
||||
output = this.getNonCellOutput( stackInSlot ).orElse( output );
|
||||
}
|
||||
}
|
||||
// handle crafting storage blocks
|
||||
output = this.getNonCellOutput(stackInSlot).orElse(output);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private Optional<ItemStack> getCellOutput( final ItemStack compared )
|
||||
{
|
||||
for( final Map.Entry<IItemDefinition, IItemDefinition> entry : this.cellMappings.entrySet() )
|
||||
{
|
||||
if( entry.getKey().isSameAs( compared ) )
|
||||
{
|
||||
return entry.getValue().maybeStack( 1 );
|
||||
}
|
||||
}
|
||||
@Nonnull
|
||||
private Optional<ItemStack> getCellOutput(final ItemStack compared) {
|
||||
for (final Map.Entry<IItemDefinition, IItemDefinition> entry : this.cellMappings.entrySet()) {
|
||||
if (entry.getKey().isSameAs(compared)) {
|
||||
return entry.getValue().maybeStack(1);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private Optional<ItemStack> getNonCellOutput( final ItemStack compared )
|
||||
{
|
||||
for( final Map.Entry<IItemDefinition, IItemDefinition> entry : this.nonCellMappings.entrySet() )
|
||||
{
|
||||
if( entry.getKey().isSameAs( compared ) )
|
||||
{
|
||||
return entry.getValue().maybeStack( 1 );
|
||||
}
|
||||
}
|
||||
@Nonnull
|
||||
private Optional<ItemStack> getNonCellOutput(final ItemStack compared) {
|
||||
for (final Map.Entry<IItemDefinition, IItemDefinition> entry : this.nonCellMappings.entrySet()) {
|
||||
if (entry.getKey().isSameAs(compared)) {
|
||||
return entry.getValue().maybeStack(1);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack getCraftingResult( final InventoryCrafting inv )
|
||||
{
|
||||
return this.getOutput( inv );
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack getCraftingResult(final InventoryCrafting inv) {
|
||||
return this.getOutput(inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit( int i, int i1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canFit(int i, int i1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() // no default output..
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() // no default output..
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getRemainingItems( final InventoryCrafting inv )
|
||||
{
|
||||
return ForgeHooks.defaultRecipeGetRemainingItems( inv );
|
||||
}
|
||||
@Override
|
||||
public NonNullList<ItemStack> getRemainingItems(final InventoryCrafting inv) {
|
||||
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,10 @@
|
||||
package appeng.recipes.game;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IComparableDefinition;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.items.parts.ItemFacade;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -29,72 +31,59 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IComparableDefinition;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.items.parts.ItemFacade;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
public final class FacadeRecipe extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
private final IComparableDefinition anchor;
|
||||
private final ItemFacade facade;
|
||||
public final class FacadeRecipe extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
|
||||
private final IComparableDefinition anchor;
|
||||
private final ItemFacade facade;
|
||||
|
||||
public FacadeRecipe( ItemFacade facade )
|
||||
{
|
||||
this.facade = facade;
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
public FacadeRecipe(ItemFacade facade) {
|
||||
this.facade = facade;
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
|
||||
this.anchor = definitions.parts().cableAnchor();
|
||||
}
|
||||
this.anchor = definitions.parts().cableAnchor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches( final InventoryCrafting inv, final World w )
|
||||
{
|
||||
return !this.getOutput( inv, false ).isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean matches(final InventoryCrafting inv, final World w) {
|
||||
return !this.getOutput(inv, false).isEmpty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ItemStack getOutput( final IInventory inv, final boolean createFacade )
|
||||
{
|
||||
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 ) ) )
|
||||
{
|
||||
final ItemStack facades = this.facade.createFacadeForItem( inv.getStackInSlot( 4 ), !createFacade );
|
||||
if( !facades.isEmpty() && createFacade )
|
||||
{
|
||||
facades.setCount( 4 );
|
||||
}
|
||||
return facades;
|
||||
}
|
||||
}
|
||||
@Nullable
|
||||
private ItemStack getOutput(final IInventory inv, final boolean createFacade) {
|
||||
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))) {
|
||||
final ItemStack facades = this.facade.createFacadeForItem(inv.getStackInSlot(4), !createFacade);
|
||||
if (!facades.isEmpty() && createFacade) {
|
||||
facades.setCount(4);
|
||||
}
|
||||
return facades;
|
||||
}
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult( final InventoryCrafting inv )
|
||||
{
|
||||
return this.getOutput( inv, true );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getCraftingResult(final InventoryCrafting inv) {
|
||||
return this.getOutput(inv, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit( int i, int i1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canFit(int i, int i1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() // no default output..
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() // no default output..
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getRemainingItems( final InventoryCrafting inv )
|
||||
{
|
||||
return ForgeHooks.defaultRecipeGetRemainingItems( inv );
|
||||
}
|
||||
@Override
|
||||
public NonNullList<ItemStack> getRemainingItems(final InventoryCrafting inv) {
|
||||
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,42 @@
|
||||
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.IGrinderRecipeBuilder;
|
||||
import appeng.api.features.IGrinderRegistry;
|
||||
import appeng.recipes.IAERecipeFactory;
|
||||
import appeng.recipes.factories.recipes.PartRecipeFactory;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
|
||||
|
||||
public class GrinderHandler implements IAERecipeFactory
|
||||
{
|
||||
public class GrinderHandler implements IAERecipeFactory {
|
||||
|
||||
@Override
|
||||
public void register( JsonObject json, JsonContext ctx )
|
||||
{
|
||||
// TODO only primary for now
|
||||
@Override
|
||||
public void register(JsonObject json, JsonContext ctx) {
|
||||
// TODO only primary for now
|
||||
|
||||
JsonObject result = JsonUtils.getJsonObject( json, "result" );
|
||||
ItemStack primary = PartRecipeFactory.getResult( result, ctx, "primary" );
|
||||
ItemStack[] input = CraftingHelper.getIngredient( json.get( "input" ), ctx ).getMatchingStacks();
|
||||
JsonObject result = JsonUtils.getJsonObject(json, "result");
|
||||
ItemStack primary = PartRecipeFactory.getResult(result, ctx, "primary");
|
||||
ItemStack[] input = CraftingHelper.getIngredient(json.get("input"), ctx).getMatchingStacks();
|
||||
|
||||
int turns = 5;
|
||||
if( json.has( "turns" ) )
|
||||
{
|
||||
turns = JsonUtils.getInt( json, "turns" );
|
||||
}
|
||||
int turns = 5;
|
||||
if (json.has("turns")) {
|
||||
turns = JsonUtils.getInt(json, "turns");
|
||||
}
|
||||
|
||||
final IGrinderRegistry reg = AEApi.instance().registries().grinder();
|
||||
for( int i = 0; i < input.length; ++i )
|
||||
{
|
||||
final IGrinderRecipeBuilder builder = reg.builder();
|
||||
final IGrinderRegistry reg = AEApi.instance().registries().grinder();
|
||||
for (int i = 0; i < input.length; ++i) {
|
||||
final IGrinderRecipeBuilder builder = reg.builder();
|
||||
|
||||
builder.withOutput( primary );
|
||||
builder.withInput( input[i] );
|
||||
builder.withTurns( turns );
|
||||
builder.withOutput(primary);
|
||||
builder.withInput(input[i]);
|
||||
builder.withTurns(turns);
|
||||
|
||||
reg.addRecipe( builder.build() );
|
||||
}
|
||||
}
|
||||
reg.addRecipe(builder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,17 +19,15 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.exceptions.MissingIngredientException;
|
||||
import appeng.api.exceptions.RegistrationException;
|
||||
import appeng.recipes.RecipeHandler;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public interface IWebsiteSerializer
|
||||
{
|
||||
public interface IWebsiteSerializer {
|
||||
|
||||
String getPattern( RecipeHandler han );
|
||||
String getPattern(RecipeHandler han);
|
||||
|
||||
boolean canCraft( ItemStack output ) throws RegistrationException, MissingIngredientException;
|
||||
boolean canCraft(ItemStack output) throws RegistrationException, MissingIngredientException;
|
||||
}
|
||||
|
||||
@@ -1,71 +1,60 @@
|
||||
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.IInscriberRecipeBuilder;
|
||||
import appeng.api.features.IInscriberRegistry;
|
||||
import appeng.api.features.InscriberProcessType;
|
||||
import appeng.recipes.IAERecipeFactory;
|
||||
import appeng.recipes.factories.recipes.PartRecipeFactory;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class InscriberHandler implements IAERecipeFactory
|
||||
{
|
||||
public class InscriberHandler implements IAERecipeFactory {
|
||||
|
||||
@Override
|
||||
public void register( JsonObject json, JsonContext ctx )
|
||||
{
|
||||
ItemStack result = PartRecipeFactory.getResult( json, ctx );
|
||||
String mode = JsonUtils.getString( json, "mode" );
|
||||
@Override
|
||||
public void register(JsonObject json, JsonContext ctx) {
|
||||
ItemStack result = PartRecipeFactory.getResult(json, ctx);
|
||||
String mode = JsonUtils.getString(json, "mode");
|
||||
|
||||
JsonObject ingredients = JsonUtils.getJsonObject( json, "ingredients" );
|
||||
JsonObject ingredients = JsonUtils.getJsonObject(json, "ingredients");
|
||||
|
||||
List<ItemStack> middle = Arrays.asList( CraftingHelper.getIngredient( ingredients.get( "middle" ), ctx ).getMatchingStacks() );
|
||||
ItemStack[] top = new ItemStack[] { null };
|
||||
if( ingredients.has( "top" ) )
|
||||
{
|
||||
top = CraftingHelper.getIngredient( JsonUtils.getJsonObject( ingredients, "top" ), ctx ).getMatchingStacks();
|
||||
}
|
||||
List<ItemStack> middle = Arrays.asList(CraftingHelper.getIngredient(ingredients.get("middle"), ctx).getMatchingStacks());
|
||||
ItemStack[] top = new ItemStack[]{null};
|
||||
if (ingredients.has("top")) {
|
||||
top = CraftingHelper.getIngredient(JsonUtils.getJsonObject(ingredients, "top"), ctx).getMatchingStacks();
|
||||
}
|
||||
|
||||
ItemStack[] bottom = new ItemStack[] { null };
|
||||
if( ingredients.has( "bottom" ) )
|
||||
{
|
||||
bottom = CraftingHelper.getIngredient( JsonUtils.getJsonObject( ingredients, "bottom" ), ctx ).getMatchingStacks();
|
||||
}
|
||||
ItemStack[] bottom = new ItemStack[]{null};
|
||||
if (ingredients.has("bottom")) {
|
||||
bottom = CraftingHelper.getIngredient(JsonUtils.getJsonObject(ingredients, "bottom"), ctx).getMatchingStacks();
|
||||
}
|
||||
|
||||
final IInscriberRegistry reg = AEApi.instance().registries().inscriber();
|
||||
for( int i = 0; i < top.length; ++i )
|
||||
{
|
||||
for( int j = 0; j < bottom.length; ++j )
|
||||
{
|
||||
final IInscriberRecipeBuilder builder = reg.builder();
|
||||
builder.withOutput( result );
|
||||
builder.withProcessType( "press".equals( mode ) ? InscriberProcessType.PRESS : InscriberProcessType.INSCRIBE );
|
||||
builder.withInputs( middle );
|
||||
final IInscriberRegistry reg = AEApi.instance().registries().inscriber();
|
||||
for (int i = 0; i < top.length; ++i) {
|
||||
for (int j = 0; j < bottom.length; ++j) {
|
||||
final IInscriberRecipeBuilder builder = reg.builder();
|
||||
builder.withOutput(result);
|
||||
builder.withProcessType("press".equals(mode) ? InscriberProcessType.PRESS : InscriberProcessType.INSCRIBE);
|
||||
builder.withInputs(middle);
|
||||
|
||||
if( top[i] != null )
|
||||
{
|
||||
builder.withTopOptional( top[i] );
|
||||
}
|
||||
if( bottom[j] != null )
|
||||
{
|
||||
builder.withBottomOptional( bottom[j] );
|
||||
}
|
||||
if (top[i] != null) {
|
||||
builder.withTopOptional(top[i]);
|
||||
}
|
||||
if (bottom[j] != null) {
|
||||
builder.withBottomOptional(bottom[j]);
|
||||
}
|
||||
|
||||
reg.addRecipe( builder.build() );
|
||||
}
|
||||
}
|
||||
}
|
||||
reg.addRecipe(builder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +1,29 @@
|
||||
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
|
||||
import appeng.recipes.IAERecipeFactory;
|
||||
import appeng.recipes.factories.recipes.PartRecipeFactory;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import appeng.recipes.IAERecipeFactory;
|
||||
import appeng.recipes.factories.recipes.PartRecipeFactory;
|
||||
|
||||
public class SmeltingHandler implements IAERecipeFactory {
|
||||
@Override
|
||||
public void register(JsonObject json, JsonContext ctx) {
|
||||
ItemStack result = PartRecipeFactory.getResult(json, ctx);
|
||||
ItemStack[] input = CraftingHelper.getIngredient(json.get("input"), ctx).getMatchingStacks();
|
||||
float xp = 0.0f;
|
||||
if (json.has("xp")) {
|
||||
xp = JsonUtils.getFloat(json, "xp");
|
||||
}
|
||||
|
||||
public class SmeltingHandler implements IAERecipeFactory
|
||||
{
|
||||
@Override
|
||||
public void register( JsonObject json, JsonContext ctx )
|
||||
{
|
||||
ItemStack result = PartRecipeFactory.getResult( json, ctx );
|
||||
ItemStack[] input = CraftingHelper.getIngredient( json.get( "input" ), ctx ).getMatchingStacks();
|
||||
float xp = 0.0f;
|
||||
if( json.has( "xp" ) )
|
||||
{
|
||||
xp = JsonUtils.getFloat( json, "xp" );
|
||||
}
|
||||
|
||||
for( int i = 0; i < input.length; ++i )
|
||||
{
|
||||
GameRegistry.addSmelting( input[i], result, xp );
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < input.length; ++i) {
|
||||
GameRegistry.addSmelting(input[i], result, xp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,15 +22,14 @@ package appeng.recipes.ores;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public interface IOreListener
|
||||
{
|
||||
public interface IOreListener {
|
||||
|
||||
/**
|
||||
* Called with various items registered in the dictionary.
|
||||
* AppEng.oreDictionary.observe(...) to register them.
|
||||
*
|
||||
* @param name name of ore
|
||||
* @param item item with name
|
||||
*/
|
||||
void oreRegistered( String name, ItemStack item );
|
||||
/**
|
||||
* Called with various items registered in the dictionary.
|
||||
* AppEng.oreDictionary.observe(...) to register them.
|
||||
*
|
||||
* @param name name of ore
|
||||
* @param item item with name
|
||||
*/
|
||||
void oreRegistered(String name, ItemStack item);
|
||||
}
|
||||
|
||||
@@ -19,73 +19,61 @@
|
||||
package appeng.recipes.ores;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OreDictionaryHandler
|
||||
{
|
||||
|
||||
public static final OreDictionaryHandler INSTANCE = new OreDictionaryHandler();
|
||||
public class OreDictionaryHandler {
|
||||
|
||||
private final List<IOreListener> oreListeners = new ArrayList<>();
|
||||
public static final OreDictionaryHandler INSTANCE = new OreDictionaryHandler();
|
||||
|
||||
@SubscribeEvent
|
||||
public void onOreDictionaryRegister( final OreDictionary.OreRegisterEvent event )
|
||||
{
|
||||
if( event.getName() == null || event.getOre().isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
private final List<IOreListener> oreListeners = new ArrayList<>();
|
||||
|
||||
if( this.shouldCare( event.getName() ) )
|
||||
{
|
||||
for( final IOreListener v : this.oreListeners )
|
||||
{
|
||||
v.oreRegistered( event.getName(), event.getOre() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onOreDictionaryRegister(final OreDictionary.OreRegisterEvent event) {
|
||||
if (event.getName() == null || event.getOre().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just limit what items are sent to the final listeners, I got sick of strange items showing up...
|
||||
*
|
||||
* @param name name about cared item
|
||||
*
|
||||
* @return true if it should care
|
||||
*/
|
||||
private boolean shouldCare( final String name )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (this.shouldCare(event.getName())) {
|
||||
for (final IOreListener v : this.oreListeners) {
|
||||
v.oreRegistered(event.getName(), event.getOre());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new IOreListener and immediately notifies it of any previous ores, any ores added latter will be added at
|
||||
* that point.
|
||||
*
|
||||
* @param n to be added ore listener
|
||||
*/
|
||||
public void observe( final IOreListener n )
|
||||
{
|
||||
this.oreListeners.add( n );
|
||||
/**
|
||||
* Just limit what items are sent to the final listeners, I got sick of strange items showing up...
|
||||
*
|
||||
* @param name name about cared item
|
||||
* @return true if it should care
|
||||
*/
|
||||
private boolean shouldCare(final String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// notify the listener of any ore already in existence.
|
||||
for( final String name : OreDictionary.getOreNames() )
|
||||
{
|
||||
if( name != null && this.shouldCare( name ) )
|
||||
{
|
||||
for( final ItemStack item : OreDictionary.getOres( name ) )
|
||||
{
|
||||
if( !item.isEmpty() )
|
||||
{
|
||||
n.oreRegistered( name, item );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds a new IOreListener and immediately notifies it of any previous ores, any ores added latter will be added at
|
||||
* that point.
|
||||
*
|
||||
* @param n to be added ore listener
|
||||
*/
|
||||
public void observe(final IOreListener n) {
|
||||
this.oreListeners.add(n);
|
||||
|
||||
// notify the listener of any ore already in existence.
|
||||
for (final String name : OreDictionary.getOreNames()) {
|
||||
if (name != null && this.shouldCare(name)) {
|
||||
for (final ItemStack item : OreDictionary.getOres(name)) {
|
||||
if (!item.isEmpty()) {
|
||||
n.oreRegistered(name, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user