Basic JEI integration is back
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
|
||||
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;
|
||||
|
||||
|
||||
public class GrinderHandler implements IAERecipeFactory
|
||||
{
|
||||
|
||||
@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();
|
||||
|
||||
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();
|
||||
|
||||
builder.withOutput( primary );
|
||||
builder.withInput( input[i] );
|
||||
builder.withTurns( turns );
|
||||
|
||||
reg.addRecipe( builder.build() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Describes an optional result of a grinder recipe.
|
||||
*/
|
||||
public class GrinderOptionalResult {
|
||||
private final float chance;
|
||||
private final ItemStack result;
|
||||
|
||||
public GrinderOptionalResult(float chance, ItemStack result) {
|
||||
this.chance = chance;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chance to occur from 0 (0%) to 1 (100%).
|
||||
*/
|
||||
public float getChance() {
|
||||
return chance;
|
||||
}
|
||||
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GrinderRecipe implements IRecipe<IInventory> {
|
||||
|
||||
public static IRecipeType<GrinderRecipe> TYPE;
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final String group;
|
||||
private final Ingredient ingredient;
|
||||
private final ItemStack result;
|
||||
private final List<GrinderOptionalResult> optionalResults;
|
||||
private final int turns;
|
||||
|
||||
public GrinderRecipe(ResourceLocation id, String group, Ingredient ingredient, ItemStack result, int turns, List<GrinderOptionalResult> optionalResults) {
|
||||
this.id = id;
|
||||
this.group = group;
|
||||
this.ingredient = ingredient;
|
||||
this.result = result;
|
||||
this.turns = turns;
|
||||
this.optionalResults = ImmutableList.copyOf(optionalResults);
|
||||
}
|
||||
@Override
|
||||
public boolean matches(IInventory inv, World worldIn) {
|
||||
return this.ingredient.test(inv.getStackInSlot(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(IInventory inv) {
|
||||
// FIXME: What about secondary output
|
||||
return this.result.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int width, int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return GrinderRecipeSerializer.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeType<?> getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public Ingredient getIngredient() {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
NonNullList<Ingredient> nonnulllist = NonNullList.create();
|
||||
nonnulllist.add(this.ingredient);
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public List<GrinderOptionalResult> getOptionalResults() {
|
||||
return optionalResults;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.ShapedRecipe;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GrinderRecipeSerializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<GrinderRecipe> {
|
||||
|
||||
public static final GrinderRecipeSerializer INSTANCE = new GrinderRecipeSerializer();
|
||||
|
||||
static {
|
||||
INSTANCE.setRegistryName(AppEng.MOD_ID, "grinder");
|
||||
}
|
||||
|
||||
private GrinderRecipeSerializer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrinderRecipe read(ResourceLocation recipeId, JsonObject json) {
|
||||
String group = JSONUtils.getString(json, "group", "");
|
||||
Ingredient ingredient = Ingredient.deserialize(JSONUtils.getJsonObject(json, "input"));
|
||||
|
||||
JsonObject result = JSONUtils.getJsonObject(json, "result");
|
||||
ItemStack primaryResult = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(result, "primary"));
|
||||
JsonArray optionalResultsJson = JSONUtils.getJsonArray(result, "optional", null);
|
||||
List<GrinderOptionalResult> optionalResults = Collections.emptyList();
|
||||
if (optionalResultsJson != null) {
|
||||
optionalResults = new ArrayList<>(optionalResultsJson.size());
|
||||
for (JsonElement optionalResultJson : optionalResultsJson) {
|
||||
if (!optionalResultJson.isJsonObject()) {
|
||||
throw new IllegalStateException("Entry in optional result list should be an object.");
|
||||
}
|
||||
ItemStack optionalResultItem = ShapedRecipe.deserializeItem(optionalResultJson.getAsJsonObject());
|
||||
float optionalChance = JSONUtils.getFloat(optionalResultJson.getAsJsonObject(), "chance", 1.0f);
|
||||
optionalResults.add(new GrinderOptionalResult(optionalChance, optionalResultItem));
|
||||
}
|
||||
}
|
||||
|
||||
int turns = JSONUtils.getInt(json, "turns", 8);
|
||||
|
||||
return new GrinderRecipe(recipeId, group, ingredient, primaryResult, turns, optionalResults);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GrinderRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer, GrinderRecipe recipe) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,70 +2,55 @@
|
||||
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;
|
||||
|
||||
|
||||
public class InscriberHandler implements IAERecipeFactory
|
||||
public class InscriberHandler
|
||||
{
|
||||
|
||||
@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" );
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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] );
|
||||
}
|
||||
|
||||
reg.addRecipe( builder.build() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @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" );
|
||||
//
|
||||
// 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();
|
||||
// }
|
||||
//
|
||||
// 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] );
|
||||
// }
|
||||
//
|
||||
// reg.addRecipe( builder.build() );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import appeng.api.features.InscriberProcessType;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InscriberRecipe implements IRecipe<IInventory> {
|
||||
|
||||
public static IRecipeType<InscriberRecipe> TYPE;
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final String group;
|
||||
|
||||
private List<Ingredient> inputs;
|
||||
private ItemStack output;
|
||||
private ItemStack topOptional;
|
||||
private ItemStack bottomOptional;
|
||||
private InscriberProcessType type;
|
||||
|
||||
public InscriberRecipe(ResourceLocation id, String group, List<Ingredient> inputs, ItemStack output, ItemStack topOptional, ItemStack bottomOptional, InscriberProcessType type) {
|
||||
this.id = id;
|
||||
this.group = group;
|
||||
this.inputs = inputs;
|
||||
this.output = output;
|
||||
this.topOptional = topOptional;
|
||||
this.bottomOptional = bottomOptional;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IInventory inv, World worldIn) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(IInventory inv) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int width, int height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeType<?> getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public List<Ingredient> getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
public ItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
public ItemStack getTopOptional() {
|
||||
return topOptional;
|
||||
}
|
||||
|
||||
public ItemStack getBottomOptional() {
|
||||
return bottomOptional;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user