Moving to source sets
This commit is contained in:
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.recipes.game;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.item.crafting.SpecialRecipe;
|
||||
import net.minecraft.item.crafting.SpecialRecipeSerializer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
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 appeng.core.AppEng;
|
||||
|
||||
public final class DisassembleRecipe extends SpecialRecipe {
|
||||
public static final RecipeSerializer<DisassembleRecipe> SERIALIZER = new SpecialRecipeSerializer<>(
|
||||
DisassembleRecipe::new);
|
||||
|
||||
static {
|
||||
SERIALIZER.setRegistryName(new Identifier(AppEng.MOD_ID, "disassemble"));
|
||||
}
|
||||
|
||||
private static final ItemStack MISMATCHED_STACK = ItemStack.EMPTY;
|
||||
|
||||
private final Map<IItemDefinition, IItemDefinition> cellMappings;
|
||||
private final Map<IItemDefinition, IItemDefinition> nonCellMappings;
|
||||
|
||||
public DisassembleRecipe(Identifier id) {
|
||||
super(id);
|
||||
|
||||
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.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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nonnull final CraftingInventory inv, @Nonnull final World w) {
|
||||
return !this.getOutput(inv).isEmpty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private ItemStack getOutput(final Inventory inventory) {
|
||||
int itemCount = 0;
|
||||
ItemStack output = MISMATCHED_STACK;
|
||||
|
||||
for (int slotIndex = 0; slotIndex < inventory.size(); slotIndex++) {
|
||||
final ItemStack stackInSlot = inventory.getStack(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;
|
||||
}
|
||||
}
|
||||
|
||||
output = storageCellStack;
|
||||
}
|
||||
|
||||
// handle crafting storage blocks
|
||||
output = this.getNonCellOutput(stackInSlot).orElse(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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack craft(@Nonnull final CraftingInventory inv) {
|
||||
return this.getOutput(inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int i, int i1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<DisassembleRecipe> getSerializer() {
|
||||
return SERIALIZER;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.recipes.game;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.item.crafting.SpecialRecipe;
|
||||
import net.minecraft.item.crafting.SpecialRecipeSerializer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IComparableDefinition;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.items.parts.FacadeItem;
|
||||
|
||||
public final class FacadeRecipe extends SpecialRecipe {
|
||||
public static SpecialRecipeSerializer<FacadeRecipe> SERIALIZER = null;
|
||||
|
||||
private final IComparableDefinition anchor;
|
||||
private final FacadeItem facade;
|
||||
|
||||
public FacadeRecipe(Identifier id, FacadeItem facade) {
|
||||
super(id);
|
||||
this.facade = facade;
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
|
||||
this.anchor = definitions.parts().cableAnchor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nonnull final CraftingInventory inv, @Nonnull final World w) {
|
||||
return !this.getOutput(inv, false).isEmpty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private ItemStack getOutput(final Inventory inv, final boolean 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);
|
||||
}
|
||||
return facades;
|
||||
}
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(@Nonnull final CraftingInventory inv) {
|
||||
return this.getOutput(inv, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int i, int i1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public RecipeSerializer<FacadeRecipe> getSerializer() {
|
||||
return getSerializer(facade);
|
||||
}
|
||||
|
||||
public static RecipeSerializer<FacadeRecipe> getSerializer(FacadeItem facade) {
|
||||
if (SERIALIZER == null) {
|
||||
SERIALIZER = new SpecialRecipeSerializer<>(id -> new FacadeRecipe(id, facade));
|
||||
SERIALIZER.setRegistryName(new Identifier(AppEng.MOD_ID, "facade"));
|
||||
}
|
||||
return SERIALIZER;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,104 @@
|
||||
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.getStack(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(Inventory inv) {
|
||||
// FIXME: What about secondary output
|
||||
return this.result.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fits(int width, int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput() {
|
||||
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> getPreviewInputs() {
|
||||
DefaultedList<Ingredient> nonnulllist = DefaultedList.of();
|
||||
nonnulllist.add(this.ingredient);
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public List<GrinderOptionalResult> getOptionalResults() {
|
||||
return optionalResults;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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.recipe.ShapedRecipe;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
|
||||
import appeng.core.AEConfig;
|
||||
|
||||
public class GrinderRecipeSerializer implements RecipeSerializer<GrinderRecipe> {
|
||||
|
||||
public static final GrinderRecipeSerializer INSTANCE = new GrinderRecipeSerializer();
|
||||
|
||||
private GrinderRecipeSerializer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrinderRecipe read(Identifier recipeId, JsonObject json) {
|
||||
String group = JsonHelper.getString(json, "group", "");
|
||||
JsonObject inputObj = JsonHelper.getObject(json, "input");
|
||||
Ingredient ingredient = Ingredient.fromJson(inputObj);
|
||||
int ingredientCount = 1;
|
||||
if (inputObj.has("count")) {
|
||||
ingredientCount = inputObj.get("count").getAsInt();
|
||||
}
|
||||
|
||||
JsonObject result = JsonHelper.getObject(json, "result");
|
||||
ItemStack primaryResult = ShapedRecipe.getItemStack(JsonHelper.getObject(result, "primary"));
|
||||
JsonArray optionalResultsJson = JsonHelper.getArray(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.getItemStack(optionalResultJson.getAsJsonObject());
|
||||
float optionalChance = JsonHelper.getFloat(optionalResultJson.getAsJsonObject(), "percentageChance",
|
||||
AEConfig.instance().getOreDoublePercentage()) / 100.0f;
|
||||
optionalResults.add(new GrinderOptionalResult(optionalChance, optionalResultItem));
|
||||
}
|
||||
}
|
||||
|
||||
int turns = JsonHelper.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.fromPacket(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.getOutput());
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
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) {
|
||||
// FIXME: this is slow, this creates a full copy of the list everytime
|
||||
List<GrinderRecipe> grinderRecipes = world.getRecipeManager().method_30027(GrinderRecipe.TYPE);
|
||||
for (GrinderRecipe recipe : grinderRecipes) {
|
||||
if (recipe.getIngredient().test(input) && input.getCount() >= recipe.getIngredientCount()) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
// FIXME: this is slow, this creates a full copy of the list everytime
|
||||
List<GrinderRecipe> grinderRecipes = world.getRecipeManager().method_30027(GrinderRecipe.TYPE);
|
||||
for (GrinderRecipe recipe : grinderRecipes) {
|
||||
if (recipe.getIngredient().test(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
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 fits(int width, int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput() {
|
||||
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> getPreviewInputs() {
|
||||
DefaultedList<Ingredient> nonnulllist = DefaultedList.of();
|
||||
nonnulllist.add(this.topOptional);
|
||||
nonnulllist.add(this.middleInput);
|
||||
nonnulllist.add(this.bottomOptional);
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
public Ingredient getMiddleInput() {
|
||||
return middleInput;
|
||||
}
|
||||
|
||||
public Ingredient getTopOptional() {
|
||||
return topOptional;
|
||||
}
|
||||
|
||||
public Ingredient getBottomOptional() {
|
||||
return bottomOptional;
|
||||
}
|
||||
|
||||
public InscriberProcessType getProcessType() {
|
||||
return processType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
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.recipe.ShapedRecipe;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
|
||||
import appeng.api.features.InscriberProcessType;
|
||||
|
||||
public class InscriberRecipeSerializer implements RecipeSerializer<InscriberRecipe> {
|
||||
|
||||
public static final InscriberRecipeSerializer INSTANCE = new InscriberRecipeSerializer();
|
||||
|
||||
private InscriberRecipeSerializer() {
|
||||
}
|
||||
|
||||
private static InscriberProcessType getMode(JsonObject json) {
|
||||
String mode = JsonHelper.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 = JsonHelper.getString(json, "group", "");
|
||||
ItemStack result = ShapedRecipe.getItemStack(JsonHelper.getObject(json, "result"));
|
||||
|
||||
// Deserialize the three parts of the input
|
||||
JsonObject ingredients = JsonHelper.getObject(json, "ingredients");
|
||||
Ingredient middle = Ingredient.fromJson(ingredients.get("middle"));
|
||||
Ingredient top = Ingredient.EMPTY;
|
||||
if (ingredients.has("top")) {
|
||||
top = Ingredient.fromJson(ingredients.get("top"));
|
||||
}
|
||||
Ingredient bottom = Ingredient.EMPTY;
|
||||
if (ingredients.has("bottom")) {
|
||||
bottom = Ingredient.fromJson(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.fromPacket(buffer);
|
||||
ItemStack result = buffer.readItemStack();
|
||||
Ingredient top = Ingredient.fromPacket(buffer);
|
||||
Ingredient bottom = Ingredient.fromPacket(buffer);
|
||||
InscriberProcessType mode = buffer.readEnumConstant(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.getOutput());
|
||||
recipe.getTopOptional().write(buffer);
|
||||
recipe.getBottomOptional().write(buffer);
|
||||
buffer.writeEnumConstant(recipe.getProcessType());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import appeng.items.tools.quartz.QuartzCuttingKnifeItem;
|
||||
import appeng.mixins.ShapelessRecipeMixin;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.ShapelessRecipe;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
|
||||
/**
|
||||
* An extended version of ShapelessRecipe to support damaging the QuartzKnife whenever it is used to craft something.
|
||||
*/
|
||||
public class QuartzKnifeRecipe extends ShapelessRecipe {
|
||||
|
||||
public QuartzKnifeRecipe(ShapelessRecipe original) {
|
||||
super(
|
||||
original.getId(),
|
||||
((ShapelessRecipeMixin) original).getGroup(),
|
||||
original.getOutput(),
|
||||
original.getPreviewInputs()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return QuartzKnifeRecipeSerializer.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultedList<ItemStack> getRemainingStacks(CraftingInventory inventory) {
|
||||
DefaultedList<ItemStack> defaultedList = DefaultedList.ofSize(inventory.size(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < defaultedList.size(); ++i) {
|
||||
ItemStack stack = inventory.getStack(i);
|
||||
Item item = stack.getItem();
|
||||
if (item instanceof QuartzCuttingKnifeItem) {
|
||||
// If it still has durability left, put a more damaged one back, otherwise consume
|
||||
int newDamage = stack.getDamage() + 1;
|
||||
if (newDamage < stack.getMaxDamage()) {
|
||||
stack = stack.copy();
|
||||
stack.setDamage(newDamage);
|
||||
defaultedList.set(i, stack);
|
||||
}
|
||||
} else if (item.hasRecipeRemainder()) {
|
||||
defaultedList.set(i, new ItemStack(item.getRecipeRemainder()));
|
||||
}
|
||||
}
|
||||
|
||||
return defaultedList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package appeng.recipes.handlers;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.recipe.ShapelessRecipe;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class QuartzKnifeRecipeSerializer extends ShapelessRecipe.Serializer {
|
||||
|
||||
public static final QuartzKnifeRecipeSerializer INSTANCE = new QuartzKnifeRecipeSerializer();
|
||||
|
||||
@Override
|
||||
public ShapelessRecipe read(Identifier identifier, JsonObject jsonObject) {
|
||||
return new QuartzKnifeRecipe(super.read(identifier, jsonObject));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapelessRecipe read(Identifier identifier, PacketByteBuf packetByteBuf) {
|
||||
return new QuartzKnifeRecipe(super.read(identifier, packetByteBuf));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user