Added Quartz Tools and Quartz Knife Recipes

This commit is contained in:
Sebastian Hartte
2020-06-30 15:33:53 +02:00
parent c0a4762ffc
commit 529d03fa9e
49 changed files with 329 additions and 233 deletions
@@ -92,7 +92,7 @@ public final class DisassembleRecipe extends SpecialRecipe {
ItemStack output = MISMATCHED_STACK;
for (int slotIndex = 0; slotIndex < inventory.size(); slotIndex++) {
final ItemStack stackInSlot = inventory.getStackInSlot(slotIndex);
final ItemStack stackInSlot = inventory.getStack(slotIndex);
if (!stackInSlot.isEmpty()) {
// needs a single input in the recipe
itemCount++;
@@ -56,11 +56,11 @@ public final class FacadeRecipe extends SpecialRecipe {
@Nonnull
private ItemStack getOutput(final Inventory 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 (inv.getStack(0).isEmpty() && inv.getStack(2).isEmpty() && inv.getStack(6).isEmpty()
&& inv.getStack(8).isEmpty()) {
if (this.anchor.isSameAs(inv.getStack(1)) && this.anchor.isSameAs(inv.getStack(3))
&& this.anchor.isSameAs(inv.getStack(5)) && this.anchor.isSameAs(inv.getStack(7))) {
final ItemStack facades = this.facade.createFacadeForItem(inv.getStack(4), !createFacade);
if (!facades.isEmpty() && createFacade) {
facades.setCount(4);
}
@@ -1,27 +0,0 @@
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;
}
}
@@ -1,104 +0,0 @@
package appeng.recipes.handlers;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World;
public class GrinderRecipe implements Recipe<Inventory> {
public static RecipeType<GrinderRecipe> TYPE;
private final Identifier id;
private final String group;
private final Ingredient ingredient;
private final int ingredientCount;
private final ItemStack result;
private final List<GrinderOptionalResult> optionalResults;
private final int turns;
public GrinderRecipe(Identifier id, String group, Ingredient ingredient, int ingredientCount,
ItemStack result, int turns, List<GrinderOptionalResult> optionalResults) {
this.id = id;
this.group = group;
this.ingredient = ingredient;
this.ingredientCount = ingredientCount;
this.result = result;
this.turns = turns;
this.optionalResults = ImmutableList.copyOf(optionalResults);
}
@Override
public String getGroup() {
return group;
}
@Override
public boolean matches(Inventory inv, World worldIn) {
return this.ingredient.test(inv.getStackInSlot(0));
}
@Override
public ItemStack craft(Inventory 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 Identifier getId() {
return id;
}
@Override
public RecipeSerializer<?> getSerializer() {
return GrinderRecipeSerializer.INSTANCE;
}
@Override
public RecipeType<?> getType() {
return TYPE;
}
public Ingredient getIngredient() {
return ingredient;
}
public int getTurns() {
return turns;
}
public int getIngredientCount() {
return ingredientCount;
}
@Override
public DefaultedList<Ingredient> getIngredients() {
DefaultedList<Ingredient> nonnulllist = DefaultedList.create();
nonnulllist.add(this.ingredient);
return nonnulllist;
}
public List<GrinderOptionalResult> getOptionalResults() {
return optionalResults;
}
}
@@ -1,104 +0,0 @@
package appeng.recipes.handlers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.item.crafting.ShapedRecipe;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.JSONUtils;
import net.minecraftforge.registries.ForgeRegistryEntry;
import appeng.core.AEConfig;
import appeng.core.AppEng;
public class GrinderRecipeSerializer extends ForgeRegistryEntry<RecipeSerializer<?>>
implements RecipeSerializer<GrinderRecipe> {
public static final GrinderRecipeSerializer INSTANCE = new GrinderRecipeSerializer();
static {
INSTANCE.setRegistryName(AppEng.MOD_ID, "grinder");
}
private GrinderRecipeSerializer() {
}
@Override
public GrinderRecipe read(Identifier recipeId, JsonObject json) {
String group = JSONUtils.getString(json, "group", "");
JsonObject inputObj = JSONUtils.getJsonObject(json, "input");
Ingredient ingredient = Ingredient.deserialize(inputObj);
int ingredientCount = 1;
if (inputObj.has("count")) {
ingredientCount = inputObj.get("count").getAsInt();
}
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(), "percentageChance",
AEConfig.instance().getOreDoublePercentage()) / 100.0f;
optionalResults.add(new GrinderOptionalResult(optionalChance, optionalResultItem));
}
}
int turns = JSONUtils.getInt(json, "turns", 8);
return new GrinderRecipe(recipeId, group, ingredient, ingredientCount, primaryResult, turns, optionalResults);
}
@Nullable
@Override
public GrinderRecipe read(Identifier recipeId, PacketByteBuf buffer) {
String group = buffer.readString();
Ingredient ingredient = Ingredient.read(buffer);
int ingredientCount = buffer.readVarInt();
ItemStack result = buffer.readItemStack();
int turns = buffer.readVarInt();
int optionalResultsCount = buffer.readVarInt();
List<GrinderOptionalResult> optionalResults = new ArrayList<>(optionalResultsCount);
for (int i = 0; i < optionalResultsCount; i++) {
float chance = buffer.readFloat();
ItemStack optionalResult = buffer.readItemStack();
optionalResults.add(new GrinderOptionalResult(chance, optionalResult));
}
return new GrinderRecipe(recipeId, group, ingredient, ingredientCount, result, turns, optionalResults);
}
@Override
public void write(PacketByteBuf buffer, GrinderRecipe recipe) {
buffer.writeString(recipe.getGroup());
recipe.getIngredient().write(buffer);
buffer.writeVarInt(recipe.getIngredientCount());
buffer.writeItemStack(recipe.getRecipeOutput());
buffer.writeVarInt(recipe.getTurns());
List<GrinderOptionalResult> optionalResults = recipe.getOptionalResults();
buffer.writeVarInt(optionalResults.size());
for (GrinderOptionalResult optionalResult : optionalResults) {
buffer.writeFloat(optionalResult.getChance());
buffer.writeItemStack(optionalResult.getResult());
}
}
}
@@ -1,43 +0,0 @@
package appeng.recipes.handlers;
import javax.annotation.Nullable;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Recipe;
import net.minecraft.world.World;
public final class GrinderRecipes {
private GrinderRecipes() {
}
/**
* Search all available Grinder recipes for a recipe matching the given input or
* null;
*/
@Nullable
public static GrinderRecipe findForInput(World world, ItemStack input) {
for (Recipe<Inventory> recipe : world.getRecipeManager().getRecipes(GrinderRecipe.TYPE).values()) {
GrinderRecipe grinderRecipe = (GrinderRecipe) recipe;
if (grinderRecipe.getIngredient().test(input) && input.getCount() >= grinderRecipe.getIngredientCount()) {
return grinderRecipe;
}
}
return null;
}
/**
* Checks if the given item stack is an ingredient in any grinder recipe,
* disregarding its current size.
*/
public static boolean isValidIngredient(World world, ItemStack stack) {
for (Recipe<Inventory> recipe : world.getRecipeManager().getRecipes(GrinderRecipe.TYPE).values()) {
GrinderRecipe grinderRecipe = (GrinderRecipe) recipe;
if (grinderRecipe.getIngredient().test(stack)) {
return true;
}
}
return false;
}
}
@@ -1,106 +0,0 @@
package appeng.recipes.handlers;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.*;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.Recipe;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import appeng.api.features.InscriberProcessType;
public class InscriberRecipe implements Recipe<Inventory> {
public static RecipeType<InscriberRecipe> TYPE;
private final Identifier id;
private final String group;
private final Ingredient middleInput;
private final Ingredient topOptional;
private final Ingredient bottomOptional;
private final ItemStack output;
private final InscriberProcessType processType;
public InscriberRecipe(Identifier id, String group, Ingredient middleInput, ItemStack output,
Ingredient topOptional, Ingredient bottomOptional, InscriberProcessType processType) {
this.id = id;
this.group = group;
this.middleInput = middleInput;
this.output = output;
this.topOptional = topOptional;
this.bottomOptional = bottomOptional;
this.processType = processType;
}
@Override
public boolean matches(Inventory inv, World worldIn) {
return false;
}
@Override
public ItemStack craft(Inventory inv) {
return this.output.copy();
}
@Override
public boolean canFit(int width, int height) {
return true;
}
@Override
public ItemStack getRecipeOutput() {
return output;
}
@Override
public Identifier getId() {
return id;
}
@Override
public RecipeSerializer<?> getSerializer() {
return InscriberRecipeSerializer.INSTANCE;
}
@Override
public RecipeType<?> getType() {
return TYPE;
}
@Override
public DefaultedList<Ingredient> getIngredients() {
DefaultedList<Ingredient> nonnulllist = DefaultedList.create();
nonnulllist.add(this.topOptional);
nonnulllist.add(this.middleInput);
nonnulllist.add(this.bottomOptional);
return nonnulllist;
}
public Ingredient getMiddleInput() {
return middleInput;
}
public ItemStack getOutput() {
return output;
}
public Ingredient getTopOptional() {
return topOptional;
}
public Ingredient getBottomOptional() {
return bottomOptional;
}
public InscriberProcessType getProcessType() {
return processType;
}
@Override
public String getGroup() {
return group;
}
}
@@ -1,90 +0,0 @@
package appeng.recipes.handlers;
import javax.annotation.Nullable;
import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.item.crafting.ShapedRecipe;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.JSONUtils;
import net.minecraftforge.registries.ForgeRegistryEntry;
import appeng.api.features.InscriberProcessType;
import appeng.core.AppEng;
public class InscriberRecipeSerializer extends ForgeRegistryEntry<RecipeSerializer<?>>
implements RecipeSerializer<InscriberRecipe> {
public static final InscriberRecipeSerializer INSTANCE = new InscriberRecipeSerializer();
static {
INSTANCE.setRegistryName(AppEng.MOD_ID, "inscriber");
}
private InscriberRecipeSerializer() {
}
private static InscriberProcessType getMode(JsonObject json) {
String mode = JSONUtils.getString(json, "mode", "inscribe");
switch (mode) {
case "inscribe":
return InscriberProcessType.INSCRIBE;
case "press":
return InscriberProcessType.PRESS;
default:
throw new IllegalStateException("Unknown mode for inscriber recipe: " + mode);
}
}
@Override
public InscriberRecipe read(Identifier recipeId, JsonObject json) {
InscriberProcessType mode = getMode(json);
String group = JSONUtils.getString(json, "group", "");
ItemStack result = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "result"));
// Deserialize the three parts of the input
JsonObject ingredients = JSONUtils.getJsonObject(json, "ingredients");
Ingredient middle = Ingredient.deserialize(ingredients.get("middle"));
Ingredient top = Ingredient.EMPTY;
if (ingredients.has("top")) {
top = Ingredient.deserialize(ingredients.get("top"));
}
Ingredient bottom = Ingredient.EMPTY;
if (ingredients.has("bottom")) {
bottom = Ingredient.deserialize(ingredients.get("bottom"));
}
return new InscriberRecipe(recipeId, group, middle, result, top, bottom, mode);
}
@Nullable
@Override
public InscriberRecipe read(Identifier recipeId, PacketByteBuf buffer) {
String group = buffer.readString();
Ingredient middle = Ingredient.read(buffer);
ItemStack result = buffer.readItemStack();
Ingredient top = Ingredient.read(buffer);
Ingredient bottom = Ingredient.read(buffer);
InscriberProcessType mode = buffer.readEnumValue(InscriberProcessType.class);
return new InscriberRecipe(recipeId, group, middle, result, top, bottom, mode);
}
@Override
public void write(PacketByteBuf buffer, InscriberRecipe recipe) {
buffer.writeString(recipe.getGroup());
recipe.getMiddleInput().write(buffer);
buffer.writeItemStack(recipe.getRecipeOutput());
recipe.getTopOptional().write(buffer);
recipe.getBottomOptional().write(buffer);
buffer.writeEnumValue(recipe.getProcessType());
}
}