From 62b02d3faf36ef68d8d654e6b3b6cec44e5312b7 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Mon, 13 Jul 2020 13:02:11 +0200 Subject: [PATCH] REI integration --- .../client/render/cablebus/QuadRotator.java | 9 +- .../modules/jei/CondenserCategory.java | 149 +++++++++++++ .../modules/jei/CondenserOutputDisplay.java | 86 ++++++++ .../modules/jei/GrinderRecipeCategory.java | 114 ++++++++++ .../modules/jei/GrinderRecipeWrapper.java | 104 +++++++++ .../modules/jei/InscriberRecipeCategory.java | 108 +++++++++ .../modules/jei/InscriberRecipeWrapper.java | 91 ++++++++ .../modules/jei/RecipeTransferHandler.java | 85 +++---- .../integration/modules/jei/ReiPlugin.java | 203 +++++++++++++++++ .../recipes/handlers/GrinderRecipe.java | 5 + .../recipes/handlers/InscriberRecipe.java | 6 + src/main/resources/fabric.mod.json | 3 + .../modules/jei/CondenserCategory.java | 208 ------------------ .../modules/jei/GrinderRecipeCategory.java | 142 ------------ .../modules/jei/InscriberRecipeCategory.java | 115 ---------- .../integration/modules/jei/JEIPlugin.java | 208 ------------------ 16 files changed, 908 insertions(+), 728 deletions(-) create mode 100644 src/main/java/appeng/integration/modules/jei/CondenserCategory.java create mode 100644 src/main/java/appeng/integration/modules/jei/CondenserOutputDisplay.java create mode 100644 src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java create mode 100644 src/main/java/appeng/integration/modules/jei/GrinderRecipeWrapper.java create mode 100644 src/main/java/appeng/integration/modules/jei/InscriberRecipeCategory.java create mode 100644 src/main/java/appeng/integration/modules/jei/InscriberRecipeWrapper.java rename src/{unported => main}/java/appeng/integration/modules/jei/RecipeTransferHandler.java (59%) create mode 100644 src/main/java/appeng/integration/modules/jei/ReiPlugin.java delete mode 100644 src/unported/java/appeng/integration/modules/jei/CondenserCategory.java delete mode 100644 src/unported/java/appeng/integration/modules/jei/GrinderRecipeCategory.java delete mode 100644 src/unported/java/appeng/integration/modules/jei/InscriberRecipeCategory.java delete mode 100644 src/unported/java/appeng/integration/modules/jei/JEIPlugin.java diff --git a/src/main/java/appeng/client/render/cablebus/QuadRotator.java b/src/main/java/appeng/client/render/cablebus/QuadRotator.java index 7c8398112..217cbf05b 100644 --- a/src/main/java/appeng/client/render/cablebus/QuadRotator.java +++ b/src/main/java/appeng/client/render/cablebus/QuadRotator.java @@ -73,7 +73,6 @@ public class QuadRotator implements RenderContext.QuadTransform { @Override public boolean transform(MutableQuadView quad) { - Vector3f tmp = new Vector3f(); for (int i = 0; i < 4; i++) { @@ -85,9 +84,11 @@ public class QuadRotator implements RenderContext.QuadTransform { quad.pos(i, tmp); // Transform the normal - quad.copyNormal(i, tmp); - tmp.rotate(quaternion); - quad.normal(i, tmp); + if (quad.hasNormal(i)) { + quad.copyNormal(i, tmp); + tmp.rotate(quaternion); + quad.normal(i, tmp); + } } // Transform the nominal face diff --git a/src/main/java/appeng/integration/modules/jei/CondenserCategory.java b/src/main/java/appeng/integration/modules/jei/CondenserCategory.java new file mode 100644 index 000000000..07c65f91a --- /dev/null +++ b/src/main/java/appeng/integration/modules/jei/CondenserCategory.java @@ -0,0 +1,149 @@ +/* + * 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 . + */ + +package appeng.integration.modules.jei; + +import appeng.api.config.CondenserOutput; +import appeng.core.Api; +import appeng.core.AppEng; +import com.google.common.base.Splitter; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.widgets.Slot; +import me.shedaniel.rei.api.widgets.Tooltip; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.widget.Widget; +import net.minecraft.text.LiteralText; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Identifier; +import net.minecraft.util.Language; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +class CondenserCategory implements RecipeCategory { + + private static final int PADDING = 7; + + public static final Identifier UID = new Identifier(AppEng.MOD_ID, "condenser"); + + private final String localizedName; + + private final EntryStack icon; + + public CondenserCategory() { + this.localizedName = Language.getInstance().get("gui.appliedenergistics2.Condenser"); + this.icon = EntryStack.create(Api.INSTANCE.definitions().blocks().condenser().stack(1)); + } + + @Override + public Identifier getIdentifier() { + return UID; + } + + @Override + public String getCategoryName() { + return localizedName; + } + + @Override + public EntryStack getLogo() { + return icon; + } + + @Override + public List setupDisplay(CondenserOutputDisplay recipeDisplay, Rectangle bounds) { + + List widgets = new ArrayList<>(); + widgets.add(Widgets.createRecipeBase(bounds)); + + Point origin = new Point(bounds.x + PADDING, bounds.y + PADDING); + + Identifier location = new Identifier(AppEng.MOD_ID, "textures/guis/condenser.png"); + widgets.add(Widgets.createTexturedWidget(location, origin.x, origin.y, 50, 25, 94, 48)); + + Identifier statesLocation = new Identifier(AppEng.MOD_ID, "textures/guis/states.png"); + widgets.add(Widgets.createTexturedWidget(statesLocation, origin.x + 2, origin.y + 28, 241, 81, 14, 14)); + widgets.add(Widgets.createTexturedWidget(statesLocation, origin.x + 78, origin.y + 28, 240, 240, 16, 16)); + + // FIXME IDrawableStatic progressDrawable = guiHelper.drawableBuilder(location, 178, 25, 6, 18).addPadding(0, 0, 70, 0) + // FIXME .build(); + // FIXME this.progress = guiHelper.createAnimatedDrawable(progressDrawable, 40, IDrawableAnimated.StartDirection.BOTTOM, + // FIXME false); + + if (recipeDisplay.getType() == CondenserOutput.MATTER_BALLS) { + widgets.add(Widgets.createTexturedWidget(statesLocation, origin.x + 78, origin.y + 28, 16, 112, 14, 14)); + } else if (recipeDisplay.getType() == CondenserOutput.SINGULARITY) { + widgets.add(Widgets.createTexturedWidget(statesLocation, origin.x + 78, origin.y + 28, 32, 112, 14, 14)); + } + widgets.add(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { + Rectangle rect = new Rectangle(origin.x + 78, origin.y + 28, 16, 16); + if (rect.contains(mouseX, mouseY)) { + Tooltip.create(getTooltip(recipeDisplay.getType()).stream().map(LiteralText::new).collect(Collectors.toList())) + .queue(); + } + })); + + Slot outputSlot = Widgets.createSlot(new Point(origin.x + 55, origin.y + 27)) + .disableBackground() + .markOutput() + .entries(recipeDisplay.getOutputEntries()); + widgets.add(outputSlot); + + Slot storageCellSlot = Widgets.createSlot(new Point(origin.x + 51, origin.y + 1)) + .disableBackground() + .markInput() + .entries(recipeDisplay.getViableStorageComponents()); + widgets.add(storageCellSlot); + + return widgets; + + } + + + @Override + public int getDisplayWidth(CondenserOutputDisplay display) { + return 94 + 2 * PADDING; + } + + @Override + public int getDisplayHeight() { + return 48 + 2 * PADDING; + } + + private List getTooltip(CondenserOutput type) { + String key; + switch (type) { + case MATTER_BALLS: + key = "gui.tooltips.appliedenergistics2.MatterBalls"; + break; + case SINGULARITY: + key = "gui.tooltips.appliedenergistics2.Singularity"; + break; + default: + return Collections.emptyList(); + } + + return Splitter.on("\n").splitToList(new TranslatableText(key, type.requiredPower).getString()); + } + +} diff --git a/src/main/java/appeng/integration/modules/jei/CondenserOutputDisplay.java b/src/main/java/appeng/integration/modules/jei/CondenserOutputDisplay.java new file mode 100644 index 000000000..5efd85cc0 --- /dev/null +++ b/src/main/java/appeng/integration/modules/jei/CondenserOutputDisplay.java @@ -0,0 +1,86 @@ +package appeng.integration.modules.jei; + +import appeng.api.AEApi; +import appeng.api.config.CondenserOutput; +import appeng.api.definitions.IMaterials; +import appeng.api.implementations.items.IStorageComponent; +import appeng.core.Api; +import appeng.tile.misc.CondenserBlockEntity; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.RecipeDisplay; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class CondenserOutputDisplay implements RecipeDisplay { + + private final CondenserOutput type; + + private final List output; + + private final List viableStorageComponents; + + public CondenserOutputDisplay(CondenserOutput output) { + this.type = output; + this.output = Collections.singletonList( + EntryStack.create(getOutput(type)) + ); + this.viableStorageComponents = getViableStorageComponents(output); + } + + @Override + public List> getInputEntries() { + return Collections.emptyList(); + } + + @Override + public List getOutputEntries() { + return output; + } + + @Override + public Identifier getRecipeCategory() { + return CondenserCategory.UID; + } + + public CondenserOutput getType() { + return type; + } + + private static ItemStack getOutput(CondenserOutput recipe) { + switch (recipe) { + case MATTER_BALLS: + return Api.INSTANCE.definitions().materials().matterBall().stack(1); + case SINGULARITY: + return Api.INSTANCE.definitions().materials().singularity().stack(1); + default: + return ItemStack.EMPTY; + } + } + + private List getViableStorageComponents(CondenserOutput condenserOutput) { + IMaterials materials = AEApi.instance().definitions().materials(); + List viableComponents = new ArrayList<>(); + this.addViableComponent(condenserOutput, viableComponents, materials.cell1kPart().stack(1)); + this.addViableComponent(condenserOutput, viableComponents, materials.cell4kPart().stack(1)); + this.addViableComponent(condenserOutput, viableComponents, materials.cell16kPart().stack(1)); + this.addViableComponent(condenserOutput, viableComponents, materials.cell64kPart().stack(1)); + return viableComponents; + } + + private void addViableComponent(CondenserOutput condenserOutput, List viableComponents, + ItemStack itemStack) { + IStorageComponent comp = (IStorageComponent) itemStack.getItem(); + int storage = comp.getBytes(itemStack) * CondenserBlockEntity.BYTE_MULTIPLIER; + if (storage >= condenserOutput.requiredPower) { + viableComponents.add(EntryStack.create(itemStack)); + } + } + + public List getViableStorageComponents() { + return viableStorageComponents; + } +} diff --git a/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java b/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java new file mode 100644 index 000000000..04a601d43 --- /dev/null +++ b/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java @@ -0,0 +1,114 @@ +/* + * 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 . + */ + +package appeng.integration.modules.jei; + +import appeng.core.Api; +import appeng.core.AppEng; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.widgets.Slot; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.widget.Widget; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Identifier; +import net.minecraft.util.Language; + +import java.awt.*; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; + +class GrinderRecipeCategory implements RecipeCategory { + + public static final Identifier UID = new Identifier(AppEng.MOD_ID, "grinder"); + + private final String localizedName; + + private final EntryStack icon; + + public GrinderRecipeCategory() { + this.localizedName = Language.getInstance().get("block.appliedenergistics2.grindstone"); + this.icon = EntryStack.create(Api.INSTANCE.definitions().blocks().grindstone().stack(1)); + } + + @Override + public Identifier getIdentifier() { + return GrinderRecipeCategory.UID; + } + + @Override + public String getCategoryName() { + return this.localizedName; + } + + @Override + public int getDisplayHeight() { + return 70; // Padded to avoid the "+" button overlapping the UI + } + + @Override + public int getDisplayWidth(GrinderRecipeWrapper display) { + return 154; + } + + @Override + public EntryStack getLogo() { + return icon; + } + + @Override + public List setupDisplay(GrinderRecipeWrapper recipe, Rectangle bounds) { + + Identifier location = new Identifier(AppEng.MOD_ID, "textures/guis/grinder.png"); + Widget background = Widgets.createTexturedWidget(location, bounds.x, bounds.y, 11, 16, 154, 70); + + List widgets = new ArrayList<>(); + widgets.add(background); + + // Add the input + List input = recipe.getInputEntries().get(0); + widgets.add(Widgets.createSlot(new Point(bounds.x + 1, bounds.y + 1)).backgroundEnabled(false).markInput().entries(input)); + + // Add the output slots and their chances (if <100%) + List output = recipe.getOutputEntries(); + List outputChances = recipe.getOutputChances(); + DecimalFormat df = new DecimalFormat("###.##"); + int offset = bounds.x + 101; + for (int i = 0; i < output.size(); i++) { + Slot slot = Widgets.createSlot(new Point(offset, bounds.y + 47)) + .backgroundEnabled(false) + .entry(output.get(i)); + widgets.add(slot); + + double chance = outputChances.get(i); + if (chance < 100) { + Point p = new Point(slot.getBounds().getCenterX(), slot.getBounds().getMaxY() + 2); + widgets.add(Widgets.createLabel(p, new LiteralText(df.format(chance) + "%")) + .shadow(false) + .color(Color.gray.getRGB())); + } + offset += 18; + } + + return widgets; + } + +} diff --git a/src/main/java/appeng/integration/modules/jei/GrinderRecipeWrapper.java b/src/main/java/appeng/integration/modules/jei/GrinderRecipeWrapper.java new file mode 100644 index 000000000..281d671ab --- /dev/null +++ b/src/main/java/appeng/integration/modules/jei/GrinderRecipeWrapper.java @@ -0,0 +1,104 @@ +/* + * 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 . + */ + +package appeng.integration.modules.jei; + +import appeng.recipes.handlers.GrinderOptionalResult; +import appeng.recipes.handlers.GrinderRecipe; +import com.google.common.collect.ImmutableList; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.TransferRecipeDisplay; +import me.shedaniel.rei.server.ContainerInfo; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.util.Identifier; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +class GrinderRecipeWrapper implements TransferRecipeDisplay { + + private final GrinderRecipe recipe; + private final List> input; + private final List outputs; + private final List outputChances; + + public GrinderRecipeWrapper(GrinderRecipe recipe) { + this.recipe = recipe; + this.input = CollectionUtils.map(recipe.getPreviewInputs(), i -> CollectionUtils.map(i.getMatchingStacksClient(), EntryStack::create)); + + List outputs = new ArrayList<>(); + List outputChances = new ArrayList<>(); + outputs.add(EntryStack.create(recipe.getOutput())); + outputChances.add(100.0); // Primary output is guaranteed + + for (GrinderOptionalResult optionalResult : recipe.getOptionalResults()) { + outputs.add(EntryStack.create(optionalResult.getResult())); + outputChances.add(optionalResult.getChance() * 100.0); + } + this.outputs = ImmutableList.copyOf(outputs); + this.outputChances = ImmutableList.copyOf(outputChances); + } + + @Override + public List> getInputEntries() { + return input; + } + + @Override + public List getOutputEntries() { + return outputs; + } + + public List getOutputChances() { + return outputChances; + } + + @Override + public List> getRequiredEntries() { + return input; + } + + @Override + public Identifier getRecipeCategory() { + return GrinderRecipeCategory.UID; + } + + @Override + public Optional getRecipeLocation() { + return Optional.of(recipe.getId()); + } + + @Override + public int getWidth() { + return 1; + } + + @Override + public int getHeight() { + return 1; + } + + @Override + public List> getOrganisedInputEntries(ContainerInfo containerInfo, ScreenHandler container) { + return input; + } + +} diff --git a/src/main/java/appeng/integration/modules/jei/InscriberRecipeCategory.java b/src/main/java/appeng/integration/modules/jei/InscriberRecipeCategory.java new file mode 100644 index 000000000..7be909ea0 --- /dev/null +++ b/src/main/java/appeng/integration/modules/jei/InscriberRecipeCategory.java @@ -0,0 +1,108 @@ +/* + * 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 . + */ + +package appeng.integration.modules.jei; + +import appeng.core.Api; +import appeng.core.AppEng; +import com.google.common.collect.ImmutableList; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.widget.Widget; +import net.minecraft.util.Identifier; +import net.minecraft.util.Language; + +import java.util.ArrayList; +import java.util.List; + +class InscriberRecipeCategory implements RecipeCategory { + + private static final int SLOT_INPUT_TOP = 0; + private static final int SLOT_INPUT_MIDDLE = 1; + private static final int SLOT_INPUT_BOTTOM = 2; + private static final int SLOT_OUTPUT = 3; + + static final Identifier UID = new Identifier(AppEng.MOD_ID, "appliedenergistics2.inscriber"); + + private final String localizedName; + + private final EntryStack icon; + + public InscriberRecipeCategory() { + this.localizedName = Language.getInstance().get("block.appliedenergistics2.inscriber"); + this.icon = EntryStack.create(Api.INSTANCE.definitions().blocks().inscriber().stack(1)); + } + + @Override + public Identifier getIdentifier() { + return UID; + } + + @Override + public String getCategoryName() { + return localizedName; + } + + @Override + public EntryStack getLogo() { + return icon; + } + + @Override + public List setupDisplay(InscriberRecipeWrapper recipeDisplay, Rectangle bounds) { + Identifier location = new Identifier(AppEng.MOD_ID, "textures/guis/inscriber.png"); + + List widgets = new ArrayList<>(); + widgets.add(Widgets.createTexturedWidget(location, bounds.x, bounds.y, 44, 15, 97, 64)); + + List> ingredients = recipeDisplay.getInputEntries(); + EntryStack output = recipeDisplay.getOutputEntries().get(0); + + widgets.add(Widgets.createSlot(new Point(bounds.x + 1, bounds.y + 1)) + .disableBackground() + .markInput() + .entries(ingredients.get(SLOT_INPUT_TOP))); + widgets.add(Widgets.createSlot(new Point(bounds.x + 19, bounds.y + 24)) + .disableBackground() + .markInput() + .entries(ingredients.get(SLOT_INPUT_MIDDLE))); + widgets.add(Widgets.createSlot(new Point(bounds.x + 1, bounds.y + 47)) + .disableBackground() + .markInput() + .entries(ingredients.get(SLOT_INPUT_BOTTOM))); + widgets.add(Widgets.createSlot(new Point(bounds.x + 69, bounds.y + 25)) + .disableBackground() + .markOutput() + .entry(output)); + + return widgets; + } + + @Override + public int getDisplayHeight() { + return 64; + } + + @Override + public int getDisplayWidth(InscriberRecipeWrapper display) { + return 97; + } +} diff --git a/src/main/java/appeng/integration/modules/jei/InscriberRecipeWrapper.java b/src/main/java/appeng/integration/modules/jei/InscriberRecipeWrapper.java new file mode 100644 index 000000000..54402b0b5 --- /dev/null +++ b/src/main/java/appeng/integration/modules/jei/InscriberRecipeWrapper.java @@ -0,0 +1,91 @@ +/* + * 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 . + */ + +package appeng.integration.modules.jei; + +import appeng.recipes.handlers.InscriberRecipe; +import com.google.common.collect.ImmutableList; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.TransferRecipeDisplay; +import me.shedaniel.rei.server.ContainerInfo; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.util.Identifier; + +import java.util.List; +import java.util.Optional; + +class InscriberRecipeWrapper implements TransferRecipeDisplay { + + private final InscriberRecipe recipe; + private final List middleInput; + private final List topOptional; + private final List bottomOptional; + private final EntryStack output; + + public InscriberRecipeWrapper(InscriberRecipe recipe) { + this.recipe = recipe; + this.topOptional = CollectionUtils.map(recipe.getTopOptional().getMatchingStacksClient(), EntryStack::create); + this.middleInput = CollectionUtils.map(recipe.getMiddleInput().getMatchingStacksClient(), EntryStack::create); + this.bottomOptional = CollectionUtils.map(recipe.getBottomOptional().getMatchingStacksClient(), EntryStack::create); + this.output = EntryStack.create(recipe.getOutput()); + } + + @Override + public List> getInputEntries() { + return ImmutableList.of( + topOptional, middleInput, bottomOptional + ); + } + + @Override + public List getOutputEntries() { + return ImmutableList.of(output); + } + + @Override + public List> getRequiredEntries() { + return getInputEntries(); + } + + @Override + public Identifier getRecipeCategory() { + return InscriberRecipeCategory.UID; + } + + @Override + public Optional getRecipeLocation() { + return Optional.of(recipe.getId()); + } + + @Override + public int getWidth() { + return 1; + } + + @Override + public int getHeight() { + return 3; + } + + @Override + public List> getOrganisedInputEntries(ContainerInfo containerInfo, ScreenHandler container) { + return getInputEntries(); + } + +} diff --git a/src/unported/java/appeng/integration/modules/jei/RecipeTransferHandler.java b/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java similarity index 59% rename from src/unported/java/appeng/integration/modules/jei/RecipeTransferHandler.java rename to src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java index 2957bae1d..63b812001 100644 --- a/src/unported/java/appeng/integration/modules/jei/RecipeTransferHandler.java +++ b/src/main/java/appeng/integration/modules/jei/RecipeTransferHandler.java @@ -18,31 +18,24 @@ package appeng.integration.modules.jei; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.annotation.Nullable; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; - -import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.ingredient.IGuiIngredient; -import mezz.jei.api.recipe.transfer.IRecipeTransferError; -import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; - import appeng.container.slot.CraftingMatrixSlot; import appeng.container.slot.FakeCraftingMatrixSlot; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.JEIRecipePacket; +import appeng.mixins.SlotMixin; import appeng.util.Platform; +import me.shedaniel.rei.api.AutoTransferHandler; +import me.shedaniel.rei.api.EntryStack; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.slot.Slot; -class RecipeTransferHandler implements IRecipeTransferHandler { +import java.util.ArrayList; +import java.util.List; + +class RecipeTransferHandler implements AutoTransferHandler { private final Class containerClass; @@ -51,48 +44,39 @@ class RecipeTransferHandler implements IRecipeTransferH } @Override - public Class getContainerClass() { - return this.containerClass; - } + public Result handle(Context context) { - @Nullable - @Override - public IRecipeTransferError transferRecipe(T container, IRecipeLayout recipeLayout, PlayerEntity player, - boolean maxTransfer, boolean doTransfer) { - if (!doTransfer) { - return null; + ScreenHandler container = context.getContainerScreen().getScreenHandler(); + + if (!containerClass.isInstance(container)) { + return Result.createNotApplicable(); } - Map> ingredients = recipeLayout.getItemStacks() - .getGuiIngredients(); + if (!context.isActuallyCrafting()) { + // This is just to check whether the button is enabled + return Result.createSuccessful(); + } + + List> ingredients = context.getRecipe().getInputEntries(); final CompoundTag recipe = new CompoundTag(); - int slotIndex = 0; - for (Map.Entry> ingredientEntry : ingredients.entrySet()) { - IGuiIngredient ingredient = ingredientEntry.getValue(); - if (!ingredient.isInput()) { - continue; - } + for (int slotIndex = 0; slotIndex < ingredients.size(); slotIndex++) { + List ingredientEntry = ingredients.get(slotIndex); for (final Slot slot : container.slots) { if (slot instanceof CraftingMatrixSlot || slot instanceof FakeCraftingMatrixSlot) { - if (slot.getSlotIndex() == slotIndex) { + int containerSlotInvIdx = ((SlotMixin) slot).getIndex(); + if (containerSlotInvIdx == slotIndex) { final ListTag tags = new ListTag(); final List list = new ArrayList<>(); - final ItemStack displayed = ingredient.getDisplayedIngredient(); - - // prefer currently displayed item - if (displayed != null && !displayed.isEmpty()) { - list.add(displayed); - } // prefer pure crystals. - for (ItemStack stack : ingredient.getAllIngredients()) { - if (Platform.isRecipePrioritized(stack)) { - list.add(0, stack); + for (EntryStack stack : ingredientEntry) { + if (Platform.isRecipePrioritized(stack.getItemStack())) { + list.add(0, stack.getItemStack()); } else { - list.add(stack); + list.add(stack.getItemStack()); } } @@ -102,17 +86,16 @@ class RecipeTransferHandler implements IRecipeTransferH tags.add(tag); } - recipe.put("#" + slot.getSlotIndex(), tags); + recipe.put("#" + containerSlotInvIdx, tags); break; } } } - - slotIndex++; } NetworkHandler.instance().sendToServer(new JEIRecipePacket(recipe)); - return null; + return Result.createFailed(""); // this will return to the screen } + } diff --git a/src/main/java/appeng/integration/modules/jei/ReiPlugin.java b/src/main/java/appeng/integration/modules/jei/ReiPlugin.java new file mode 100644 index 000000000..adb508b2d --- /dev/null +++ b/src/main/java/appeng/integration/modules/jei/ReiPlugin.java @@ -0,0 +1,203 @@ +/* + * 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 . + */ + +package appeng.integration.modules.jei; + +import appeng.api.AEApi; +import appeng.api.config.CondenserOutput; +import appeng.api.definitions.IDefinitions; +import appeng.api.definitions.IItemDefinition; +import appeng.api.definitions.IMaterials; +import appeng.api.features.AEFeature; +import appeng.container.implementations.CraftingTermContainer; +import appeng.container.implementations.PatternTermContainer; +import appeng.core.AEConfig; +import appeng.core.AppEng; +import appeng.core.localization.GuiText; +import appeng.recipes.handlers.GrinderRecipe; +import appeng.recipes.handlers.InscriberRecipe; +import com.google.common.collect.ImmutableList; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.api.plugins.REIPluginV0; +import me.shedaniel.rei.plugin.information.DefaultInformationDisplay; +import net.minecraft.client.MinecraftClient; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.RecipeManager; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Identifier; + +import java.util.Arrays; +import java.util.stream.Collectors; + +public class ReiPlugin implements REIPluginV0 { + private static final Identifier ID = new Identifier(AppEng.MOD_ID, "core"); + + @Override + public Identifier getPluginIdentifier() { + return ID; + } + + // FIXME FABRIC @Override + // FIXME FABRIC public void registerItemSubtypes(ISubtypeRegistration subtypeRegistry) { + // FIXME FABRIC final Optional maybeFacade = AEApi.instance().definitions().items().facade().maybeItem(); + // FIXME FABRIC maybeFacade.ifPresent(subtypeRegistry::useNbtForSubtypes); + // FIXME FABRIC } + + + @Override + public void registerPluginCategories(RecipeHelper recipeHelper) { + recipeHelper.registerCategory(new GrinderRecipeCategory()); + recipeHelper.registerCategory(new CondenserCategory()); + recipeHelper.registerCategory(new InscriberRecipeCategory()); + } + + @Override + public void registerRecipeDisplays(RecipeHelper recipeHelper) { + recipeHelper.registerRecipes(GrinderRecipeCategory.UID, GrinderRecipe.class, GrinderRecipeWrapper::new); + recipeHelper.registerRecipes(InscriberRecipeCategory.UID, InscriberRecipe.class, InscriberRecipeWrapper::new); + + recipeHelper.registerDisplay(new CondenserOutputDisplay(CondenserOutput.MATTER_BALLS)); + recipeHelper.registerDisplay(new CondenserOutputDisplay(CondenserOutput.SINGULARITY)); + } + + @Override + public void registerOthers(RecipeHelper recipeHelper) { + // Allow recipe transfer from JEI to crafting and pattern terminal + recipeHelper.registerAutoCraftingHandler(new RecipeTransferHandler<>(CraftingTermContainer.class)); + recipeHelper.registerAutoCraftingHandler(new RecipeTransferHandler<>(PatternTermContainer.class)); + + recipeHelper.removeAutoCraftButton(GrinderRecipeCategory.UID); + recipeHelper.removeAutoCraftButton(InscriberRecipeCategory.UID); + recipeHelper.removeAutoCraftButton(CondenserCategory.UID); + + registerWorkingStations(recipeHelper); + } + + @Override + public void postRegister() { + IDefinitions definitions = AEApi.instance().definitions(); + registerDescriptions(definitions); + } + + private void registerWorkingStations(RecipeHelper registration) { + IDefinitions definitions = AEApi.instance().definitions(); + + ItemStack grindstone = definitions.blocks().grindstone().stack(1); + registration.registerWorkingStations(GrinderRecipeCategory.UID, EntryStack.create(grindstone)); + + ItemStack condenser = definitions.blocks().condenser().stack(1); + registration.registerWorkingStations(CondenserCategory.UID, EntryStack.create(condenser)); + + ItemStack inscriber = definitions.blocks().inscriber().stack(1); + registration.registerWorkingStations(InscriberRecipeCategory.UID, EntryStack.create(inscriber)); + } + + private void registerDescriptions(IDefinitions definitions) { + IMaterials materials = definitions.materials(); + + final String[] message; + if (AEConfig.instance().isFeatureEnabled(AEFeature.CERTUS_QUARTZ_WORLD_GEN)) { + message = new String[]{GuiText.ChargedQuartz.getTranslationKey(), "", + GuiText.ChargedQuartzFind.getTranslationKey()}; + } else { + message = new String[]{GuiText.ChargedQuartzFind.getTranslationKey()}; + } + addDescription(materials.certusQuartzCrystalCharged(), message); + + if (AEConfig.instance().isFeatureEnabled(AEFeature.METEORITE_WORLD_GEN)) { + addDescription(materials.logicProcessorPress(), + GuiText.inWorldCraftingPresses.getTranslationKey()); + addDescription(materials.calcProcessorPress(), + GuiText.inWorldCraftingPresses.getTranslationKey()); + addDescription(materials.engProcessorPress(), + GuiText.inWorldCraftingPresses.getTranslationKey()); + } + + if (AEConfig.instance().isFeatureEnabled(AEFeature.IN_WORLD_FLUIX)) { + addDescription(materials.fluixCrystal(), GuiText.inWorldFluix.getTranslationKey()); + } + + if (AEConfig.instance().isFeatureEnabled(AEFeature.IN_WORLD_SINGULARITY)) { + addDescription(materials.qESingularity(), GuiText.inWorldSingularity.getTranslationKey()); + } + + if (AEConfig.instance().isFeatureEnabled(AEFeature.IN_WORLD_PURIFICATION)) { + addDescription(materials.purifiedCertusQuartzCrystal(), + GuiText.inWorldPurificationCertus.getTranslationKey()); + addDescription(materials.purifiedNetherQuartzCrystal(), + GuiText.inWorldPurificationNether.getTranslationKey()); + addDescription(materials.purifiedFluixCrystal(), + GuiText.inWorldPurificationFluix.getTranslationKey()); + } + + } + + private static void addDescription(IItemDefinition itemDefinition, String... message) { + DefaultInformationDisplay info = DefaultInformationDisplay.createFromEntry( + EntryStack.create(itemDefinition), + itemDefinition.item().getName() + ); + info.lines(Arrays.stream(message).map(TranslatableText::new).collect(Collectors.toList())); + RecipeHelper.getInstance().registerDisplay(info); + } + +// FIXME FABRIC @Override +// FIXME FABRIC public void registerAdvanced(IAdvancedRegistration registration) { +// FIXME FABRIC +// FIXME FABRIC IDefinitions definitions = AEApi.instance().definitions(); +// FIXME FABRIC +// FIXME FABRIC if (AEConfig.instance().isFeatureEnabled(AEFeature.ENABLE_FACADE_CRAFTING)) { +// FIXME FABRIC FacadeItem itemFacade = (FacadeItem) definitions.items().facade().item(); +// FIXME FABRIC ItemStack cableAnchor = definitions.parts().cableAnchor().stack(1); +// FIXME FABRIC registration.addRecipeManagerPlugin(new FacadeRegistryPlugin(itemFacade, cableAnchor)); +// FIXME FABRIC } +// FIXME FABRIC } +// FIXME FABRIC +// FIXME FABRIC @Override +// FIXME FABRIC public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { +// FIXME FABRIC JEIFacade.setInstance(new JeiRuntimeAdapter(jeiRuntime)); +// FIXME FABRIC this.hideDebugTools(jeiRuntime); +// FIXME FABRIC +// FIXME FABRIC } +// FIXME FABRIC +// FIXME FABRIC private void hideDebugTools(IJeiRuntime jeiRuntime) { +// FIXME FABRIC Collection toRemove = new ArrayList<>(); +// FIXME FABRIC +// FIXME FABRIC // We use the internal API here as exception as debug tools are not part of the +// FIXME FABRIC // public one by design. +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack(1).orElse(null)); +// FIXME FABRIC +// FIXME FABRIC if (!AEConfig.instance().isFeatureEnabled(AEFeature.UNSUPPORTED_DEVELOPER_TOOLS)) { +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().blocks().cubeGenerator().maybeStack(1).orElse(null)); +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().blocks().chunkLoader().maybeStack(1).orElse(null)); +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().blocks().energyGenerator().maybeStack(1).orElse(null)); +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().blocks().itemGen().maybeStack(1).orElse(null)); +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().blocks().phantomNode().maybeStack(1).orElse(null)); +// FIXME FABRIC +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().items().toolDebugCard().maybeStack(1).orElse(null)); +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().items().toolEraser().maybeStack(1).orElse(null)); +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().items().toolMeteoritePlacer().maybeStack(1).orElse(null)); +// FIXME FABRIC toRemove.add(Api.INSTANCE.definitions().items().toolReplicatorCard().maybeStack(1).orElse(null)); +// FIXME FABRIC } +// FIXME FABRIC +// FIXME FABRIC jeiRuntime.getIngredientManager().removeIngredientsAtRuntime(mezz.jei.api.constants.VanillaTypes.ITEM, +// FIXME FABRIC toRemove); +// FIXME FABRIC } + +} diff --git a/src/main/java/appeng/recipes/handlers/GrinderRecipe.java b/src/main/java/appeng/recipes/handlers/GrinderRecipe.java index 3f3ea4812..07c64950b 100644 --- a/src/main/java/appeng/recipes/handlers/GrinderRecipe.java +++ b/src/main/java/appeng/recipes/handlers/GrinderRecipe.java @@ -101,4 +101,9 @@ public class GrinderRecipe implements Recipe { return optionalResults; } + @Override + public boolean isIgnoredInRecipeBook() { + return true; + } + } diff --git a/src/main/java/appeng/recipes/handlers/InscriberRecipe.java b/src/main/java/appeng/recipes/handlers/InscriberRecipe.java index 0b46718ff..47de892bd 100644 --- a/src/main/java/appeng/recipes/handlers/InscriberRecipe.java +++ b/src/main/java/appeng/recipes/handlers/InscriberRecipe.java @@ -99,4 +99,10 @@ public class InscriberRecipe implements Recipe { public String getGroup() { return group; } + + @Override + public boolean isIgnoredInRecipeBook() { + return true; + } + } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 81e19af4f..f485e0026 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,6 +22,9 @@ ], "client": [ "appeng.core.AppEngClientStartup" + ], + "rei_plugins": [ + "appeng.integration.modules.jei.ReiPlugin" ] }, "mixins": [ diff --git a/src/unported/java/appeng/integration/modules/jei/CondenserCategory.java b/src/unported/java/appeng/integration/modules/jei/CondenserCategory.java deleted file mode 100644 index 21a744bfa..000000000 --- a/src/unported/java/appeng/integration/modules/jei/CondenserCategory.java +++ /dev/null @@ -1,208 +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 . - */ - -package appeng.integration.modules.jei; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; - -import com.google.common.base.Splitter; - -import net.minecraft.client.resources.I18n; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; -import net.minecraftforge.fml.client.gui.HoverChecker; - -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; -import mezz.jei.api.gui.drawable.IDrawableStatic; -import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; -import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; - -import appeng.api.AEApi; -import appeng.api.config.CondenserOutput; -import appeng.api.definitions.IMaterials; -import appeng.api.implementations.items.IStorageComponent; -import appeng.core.Api; -import appeng.core.AppEng; -import appeng.tile.misc.CondenserBlockEntity; - -class CondenserCategory implements IRecipeCategory { - - public static final Identifier UID = new Identifier(AppEng.MOD_ID, "condenser"); - - private final String localizedName; - - private final IDrawable background; - - private final IDrawable iconTrash; - - private final IDrawableAnimated progress; - - private final IDrawable iconButton; - - private final IDrawable icon; - - private final HoverChecker buttonHoverChecker; - - private final Map buttonIcons; - - public CondenserCategory(IGuiHelper guiHelper) { - this.localizedName = I18n.format("gui.appliedenergistics2.Condenser"); - this.icon = guiHelper.createDrawableIngredient(Api.INSTANCE.definitions().blocks().condenser().stack(1)); - - Identifier location = new Identifier(AppEng.MOD_ID, "textures/guis/condenser.png"); - this.background = guiHelper.createDrawable(location, 50, 25, 94, 48); - - Identifier statesLocation = new Identifier(AppEng.MOD_ID, "textures/guis/states.png"); - this.iconTrash = guiHelper.drawableBuilder(statesLocation, 241, 81, 14, 14).addPadding(28, 0, 2, 0).build(); - this.iconButton = guiHelper.drawableBuilder(statesLocation, 240, 240, 16, 16).addPadding(28, 0, 78, 0).build(); - - IDrawableStatic progressDrawable = guiHelper.drawableBuilder(location, 178, 25, 6, 18).addPadding(0, 0, 70, 0) - .build(); - this.progress = guiHelper.createAnimatedDrawable(progressDrawable, 40, IDrawableAnimated.StartDirection.BOTTOM, - false); - - this.buttonIcons = new EnumMap<>(CondenserOutput.class); - - this.buttonIcons.put(CondenserOutput.MATTER_BALLS, - guiHelper.drawableBuilder(statesLocation, 16, 112, 14, 14).addPadding(28, 0, 78, 0).build()); - this.buttonIcons.put(CondenserOutput.SINGULARITY, - guiHelper.drawableBuilder(statesLocation, 32, 112, 14, 14).addPadding(28, 0, 78, 0).build()); - this.buttonHoverChecker = new HoverChecker(28, 28 + 16, 78, 78 + 16, 0); - } - - private ItemStack getOutput(CondenserOutput recipe) { - switch (recipe) { - case MATTER_BALLS: - return Api.INSTANCE.definitions().materials().matterBall().stack(1); - case SINGULARITY: - return Api.INSTANCE.definitions().materials().singularity().stack(1); - default: - return ItemStack.EMPTY; - } - } - - @Override - public Identifier getUid() { - return CondenserCategory.UID; - } - - @Override - public Class getRecipeClass() { - return CondenserOutput.class; - } - - @Override - public String getTitle() { - return this.localizedName; - } - - @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public void setIngredients(CondenserOutput recipe, IIngredients ingredients) { - ingredients.setOutput(VanillaTypes.ITEM, getOutput(recipe)); - } - - @Override - public void draw(CondenserOutput recipe, double mouseX, double mouseY) { - this.progress.draw(); - this.iconTrash.draw(); - this.iconButton.draw(); - - IDrawable buttonIcon = this.buttonIcons.get(recipe); - if (buttonIcon != null) { - buttonIcon.draw(); - } - } - - @Override - public void setRecipe(IRecipeLayout recipeLayout, CondenserOutput output, IIngredients ingredients) { - IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); - itemStacks.init(0, false, 54, 26); - - // Get all storage cells and cycle them through a fake input slot - itemStacks.init(1, true, 50, 0); - itemStacks.set(1, this.getViableStorageComponents(output)); - - // This only sets the output - itemStacks.set(ingredients); - } - - private List getViableStorageComponents(CondenserOutput condenserOutput) { - IMaterials materials = AEApi.instance().definitions().materials(); - List viableComponents = new ArrayList<>(); - materials.cell1kPart().maybeStack(1) - .ifPresent(itemStack -> this.addViableComponent(condenserOutput, viableComponents, itemStack)); - materials.cell4kPart().maybeStack(1) - .ifPresent(itemStack -> this.addViableComponent(condenserOutput, viableComponents, itemStack)); - materials.cell16kPart().maybeStack(1) - .ifPresent(itemStack -> this.addViableComponent(condenserOutput, viableComponents, itemStack)); - materials.cell64kPart().maybeStack(1) - .ifPresent(itemStack -> this.addViableComponent(condenserOutput, viableComponents, itemStack)); - return viableComponents; - } - - private void addViableComponent(CondenserOutput condenserOutput, List viableComponents, - ItemStack itemStack) { - IStorageComponent comp = (IStorageComponent) itemStack.getItem(); - int storage = comp.getBytes(itemStack) * CondenserBlockEntity.BYTE_MULTIPLIER; - if (storage >= condenserOutput.requiredPower) { - viableComponents.add(itemStack); - } - } - - @Override - public List getTooltipStrings(CondenserOutput output, double mouseX, double mouseY) { - - if (this.buttonHoverChecker.checkHover((int) mouseX, (int) mouseY)) { - String key; - - switch (output) { - case MATTER_BALLS: - key = "gui.tooltips.appliedenergistics2.MatterBalls"; - break; - case SINGULARITY: - key = "gui.tooltips.appliedenergistics2.Singularity"; - break; - default: - return Collections.emptyList(); - } - - return Splitter.on("\\n").splitToList(I18n.format(key, output.requiredPower)); - } - return Collections.emptyList(); - } - -} diff --git a/src/unported/java/appeng/integration/modules/jei/GrinderRecipeCategory.java b/src/unported/java/appeng/integration/modules/jei/GrinderRecipeCategory.java deleted file mode 100644 index f814bb322..000000000 --- a/src/unported/java/appeng/integration/modules/jei/GrinderRecipeCategory.java +++ /dev/null @@ -1,142 +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 . - */ - -package appeng.integration.modules.jei; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import net.minecraft.client.resources.I18n; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; - -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; -import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; - -import appeng.core.Api; -import appeng.core.AppEng; -import appeng.recipes.handlers.GrinderOptionalResult; -import appeng.recipes.handlers.GrinderRecipe; - -class GrinderRecipeCategory implements IRecipeCategory { - - public static final Identifier UID = new Identifier(AppEng.MOD_ID, "grinder"); - - private final String localizedName; - - private final IDrawable background; - - private final IDrawable icon; - - public GrinderRecipeCategory(IGuiHelper guiHelper) { - this.localizedName = I18n.format("block.appliedenergistics2.grindstone"); - - Identifier location = new Identifier(AppEng.MOD_ID, "textures/guis/grinder.png"); - this.background = guiHelper.createDrawable(location, 11, 16, 154, 70); - - this.icon = guiHelper.createDrawableIngredient(Api.INSTANCE.definitions().blocks().grindstone().stack(1)); - } - - @Override - public Identifier getUid() { - return GrinderRecipeCategory.UID; - } - - @Override - public String getTitle() { - return this.localizedName; - } - - @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public void setRecipe(IRecipeLayout recipeLayout, GrinderRecipe recipe, IIngredients ingredients) { - IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); - - itemStacks.init(0, true, 0, 0); - itemStacks.init(1, false, 100, 46); - itemStacks.init(2, false, 118, 46); - itemStacks.init(3, false, 136, 46); - - itemStacks.set(ingredients); - } - - @Override - public Class getRecipeClass() { - return GrinderRecipe.class; - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public void setIngredients(GrinderRecipe recipe, IIngredients ingredients) { - ingredients.setInputIngredients(Collections.singletonList(recipe.getIngredient())); - List outputs = new ArrayList<>(3); - outputs.add(recipe.getOutput()); - for (GrinderOptionalResult optionalResult : recipe.getOptionalResults()) { - outputs.add(optionalResult.getResult()); - } - ingredients.setOutputs(VanillaTypes.ITEM, outputs); - } - -// FIXME USE SPECIAL INGREDIENT TYPE -// FIXME @Override -// FIXME public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY ) -// FIXME { -// FIXME -// FIXME FontRenderer fr = Minecraft.getMinecraft().fontRenderer; -// FIXME -// FIXME int x = 118; -// FIXME -// FIXME final float scale = 0.85f; -// FIXME final float invScale = 1 / scale; -// FIXME GlStateManager.scale( scale, scale, 1 ); -// FIXME -// FIXME if( this.recipe.getOptionalOutput() != null ) -// FIXME { -// FIXME String text = String.format( "%d%%", (int) ( this.recipe.getOptionalChance() * 100 ) ); -// FIXME float width = fr.getWidth( text ) * scale; -// FIXME int xScaled = Math.round( ( x + ( 18 - width ) / 2 ) * invScale ); -// FIXME fr.drawString( text, xScaled, (int) ( 65 * invScale ), Color.gray.getRGB() ); -// FIXME x += 18; -// FIXME } -// FIXME -// FIXME if( this.recipe.getSecondOptionalOutput() != null ) -// FIXME { -// FIXME String text = String.format( "%d%%", (int) ( this.recipe.getSecondOptionalChance() * 100 ) ); -// FIXME float width = fr.getWidth( text ) * scale; -// FIXME int xScaled = Math.round( ( x + ( 18 - width ) / 2 ) * invScale ); -// FIXME fr.drawString( text, xScaled, (int) ( 65 * invScale ), Color.gray.getRGB() ); -// FIXME } -// FIXME -// FIXME GlStateManager.scale( invScale, invScale, 1 ); -// FIXME } - -} diff --git a/src/unported/java/appeng/integration/modules/jei/InscriberRecipeCategory.java b/src/unported/java/appeng/integration/modules/jei/InscriberRecipeCategory.java deleted file mode 100644 index 2c55e6e1a..000000000 --- a/src/unported/java/appeng/integration/modules/jei/InscriberRecipeCategory.java +++ /dev/null @@ -1,115 +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 . - */ - -package appeng.integration.modules.jei; - -import net.minecraft.client.resources.I18n; -import net.minecraft.util.Identifier; - -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; -import mezz.jei.api.gui.drawable.IDrawableStatic; -import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; -import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; - -import appeng.core.Api; -import appeng.core.AppEng; -import appeng.recipes.handlers.InscriberRecipe; - -class InscriberRecipeCategory implements IRecipeCategory { - - private static final int SLOT_INPUT_TOP = 0; - private static final int SLOT_INPUT_MIDDLE = 1; - private static final int SLOT_INPUT_BOTTOM = 2; - private static final int SLOT_OUTPUT = 3; - - static final Identifier UID = new Identifier(AppEng.MOD_ID, "appliedenergistics2.inscriber"); - - private final IDrawable background; - - private final String localizedName; - - private final IDrawableAnimated progress; - - private final IDrawable icon; - - public InscriberRecipeCategory(IGuiHelper guiHelper) { - Identifier location = new Identifier(AppEng.MOD_ID, "textures/guis/inscriber.png"); - this.background = guiHelper.createDrawable(location, 44, 15, 97, 64); - this.localizedName = I18n.format("block.appliedenergistics2.inscriber"); - - IDrawableStatic progressDrawable = guiHelper.drawableBuilder(location, 135, 177, 6, 18).addPadding(24, 0, 91, 0) - .build(); - this.progress = guiHelper.createAnimatedDrawable(progressDrawable, 40, IDrawableAnimated.StartDirection.BOTTOM, - false); - - this.icon = guiHelper.createDrawableIngredient(Api.INSTANCE.definitions().blocks().inscriber().stack(1)); - } - - @Override - public Identifier getUid() { - return UID; - } - - @Override - public String getTitle() { - return this.localizedName; - } - - @Override - public IDrawable getBackground() { - return this.background; - } - - @Override - public void setRecipe(IRecipeLayout recipeLayout, InscriberRecipe recipeWrapper, IIngredients ingredients) { - IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); - - itemStacks.init(SLOT_INPUT_TOP, true, 0, 0); - itemStacks.init(SLOT_INPUT_MIDDLE, true, 18, 23); - itemStacks.init(SLOT_INPUT_BOTTOM, true, 0, 46); - itemStacks.init(SLOT_OUTPUT, false, 68, 24); - - itemStacks.set(ingredients); - } - - @Override - public Class getRecipeClass() { - return InscriberRecipe.class; - } - - @Override - public IDrawable getIcon() { - return this.icon; - } - - @Override - public void setIngredients(InscriberRecipe recipe, IIngredients ingredients) { - ingredients.setInputIngredients(recipe.getIngredients()); - ingredients.setOutput(VanillaTypes.ITEM, recipe.getOutput()); - } - - @Override - public void draw(InscriberRecipe recipe, double mouseX, double mouseY) { - this.progress.draw(); - } -} diff --git a/src/unported/java/appeng/integration/modules/jei/JEIPlugin.java b/src/unported/java/appeng/integration/modules/jei/JEIPlugin.java deleted file mode 100644 index 2fbca9d0e..000000000 --- a/src/unported/java/appeng/integration/modules/jei/JEIPlugin.java +++ /dev/null @@ -1,208 +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 . - */ - -package appeng.integration.modules.jei; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Optional; - -import com.google.common.collect.ImmutableList; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.RecipeManager; -import net.minecraft.util.Identifier; - -import mezz.jei.api.IModPlugin; -import mezz.jei.api.JeiPlugin; -import mezz.jei.api.constants.VanillaRecipeCategoryUid; -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.registration.IAdvancedRegistration; -import mezz.jei.api.registration.IRecipeCatalystRegistration; -import mezz.jei.api.registration.IRecipeCategoryRegistration; -import mezz.jei.api.registration.IRecipeRegistration; -import mezz.jei.api.registration.IRecipeTransferRegistration; -import mezz.jei.api.registration.ISubtypeRegistration; -import mezz.jei.api.runtime.IJeiRuntime; - -import appeng.api.AEApi; -import appeng.api.config.CondenserOutput; -import appeng.api.definitions.IDefinitions; -import appeng.api.definitions.IItemDefinition; -import appeng.api.definitions.IMaterials; -import appeng.api.features.AEFeature; -import appeng.container.implementations.CraftingTermContainer; -import appeng.container.implementations.PatternTermContainer; -import appeng.core.AEConfig; -import appeng.core.Api; -import appeng.core.AppEng; -import appeng.core.localization.GuiText; -import appeng.integration.abstraction.JEIFacade; -import appeng.items.parts.FacadeItem; -import appeng.recipes.handlers.GrinderRecipe; -import appeng.recipes.handlers.InscriberRecipe; - -@JeiPlugin -public class JEIPlugin implements IModPlugin { - private static final Identifier ID = new Identifier(AppEng.MOD_ID, "core"); - - @Override - public Identifier getPluginUid() { - return ID; - } - - @Override - public void registerItemSubtypes(ISubtypeRegistration subtypeRegistry) { - final Optional maybeFacade = AEApi.instance().definitions().items().facade().maybeItem(); - maybeFacade.ifPresent(subtypeRegistry::useNbtForSubtypes); - } - - @Override - public void registerCategories(IRecipeCategoryRegistration registry) { - registry.addRecipeCategories(new GrinderRecipeCategory(registry.getJeiHelpers().getGuiHelper()), - new CondenserCategory(registry.getJeiHelpers().getGuiHelper()), - new InscriberRecipeCategory(registry.getJeiHelpers().getGuiHelper())); - } - - @Override - public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) { - // Allow recipe transfer from JEI to crafting and pattern terminal - registration.addRecipeTransferHandler(new RecipeTransferHandler<>(CraftingTermContainer.class), - VanillaRecipeCategoryUid.CRAFTING); - registration.addRecipeTransferHandler(new RecipeTransferHandler<>(PatternTermContainer.class), - VanillaRecipeCategoryUid.CRAFTING); - } - - @Override - public void registerRecipes(IRecipeRegistration registration) { - - IDefinitions definitions = AEApi.instance().definitions(); - - RecipeManager recipeManager = MinecraftClient.getInstance().world.getRecipeManager(); - registration.addRecipes(recipeManager.getRecipes(GrinderRecipe.TYPE).values(), GrinderRecipeCategory.UID); - registration.addRecipes(recipeManager.getRecipes(InscriberRecipe.TYPE).values(), InscriberRecipeCategory.UID); - registration.addRecipes(ImmutableList.of(CondenserOutput.MATTER_BALLS, CondenserOutput.SINGULARITY), - CondenserCategory.UID); - - registerDescriptions(definitions, registration); - } - - @Override - public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { - IDefinitions definitions = AEApi.instance().definitions(); - - ItemStack grindstone = definitions.blocks().grindstone().stack(1); - registration.addRecipeCatalyst(grindstone, GrinderRecipeCategory.UID); - - ItemStack condenser = definitions.blocks().condenser().stack(1); - registration.addRecipeCatalyst(condenser, CondenserCategory.UID); - - ItemStack inscriber = definitions.blocks().inscriber().stack(1); - registration.addRecipeCatalyst(inscriber, InscriberRecipeCategory.UID); - } - - private void registerDescriptions(IDefinitions definitions, IRecipeRegistration registry) { - IMaterials materials = definitions.materials(); - - final String[] message; - if (AEConfig.instance().isFeatureEnabled(AEFeature.CERTUS_QUARTZ_WORLD_GEN)) { - message = new String[] { GuiText.ChargedQuartz.getTranslationKey(), "", - GuiText.ChargedQuartzFind.getTranslationKey() }; - } else { - message = new String[] { GuiText.ChargedQuartzFind.getTranslationKey() }; - } - this.addDescription(registry, materials.certusQuartzCrystalCharged(), message); - - if (AEConfig.instance().isFeatureEnabled(AEFeature.METEORITE_WORLD_GEN)) { - this.addDescription(registry, materials.logicProcessorPress(), - GuiText.inWorldCraftingPresses.getTranslationKey()); - this.addDescription(registry, materials.calcProcessorPress(), - GuiText.inWorldCraftingPresses.getTranslationKey()); - this.addDescription(registry, materials.engProcessorPress(), - GuiText.inWorldCraftingPresses.getTranslationKey()); - } - - if (AEConfig.instance().isFeatureEnabled(AEFeature.IN_WORLD_FLUIX)) { - this.addDescription(registry, materials.fluixCrystal(), GuiText.inWorldFluix.getTranslationKey()); - } - - if (AEConfig.instance().isFeatureEnabled(AEFeature.IN_WORLD_SINGULARITY)) { - this.addDescription(registry, materials.qESingularity(), GuiText.inWorldSingularity.getTranslationKey()); - } - - if (AEConfig.instance().isFeatureEnabled(AEFeature.IN_WORLD_PURIFICATION)) { - this.addDescription(registry, materials.purifiedCertusQuartzCrystal(), - GuiText.inWorldPurificationCertus.getTranslationKey()); - this.addDescription(registry, materials.purifiedNetherQuartzCrystal(), - GuiText.inWorldPurificationNether.getTranslationKey()); - this.addDescription(registry, materials.purifiedFluixCrystal(), - GuiText.inWorldPurificationFluix.getTranslationKey()); - } - - } - - private void addDescription(IRecipeRegistration registry, IItemDefinition itemDefinition, String... message) { - registry.addIngredientInfo(itemDefinition.stack(1), VanillaTypes.ITEM, message); - } - - @Override - public void registerAdvanced(IAdvancedRegistration registration) { - - IDefinitions definitions = AEApi.instance().definitions(); - - if (AEConfig.instance().isFeatureEnabled(AEFeature.ENABLE_FACADE_CRAFTING)) { - FacadeItem itemFacade = (FacadeItem) definitions.items().facade().item(); - ItemStack cableAnchor = definitions.parts().cableAnchor().stack(1); - registration.addRecipeManagerPlugin(new FacadeRegistryPlugin(itemFacade, cableAnchor)); - } - } - - @Override - public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { - JEIFacade.setInstance(new JeiRuntimeAdapter(jeiRuntime)); - this.hideDebugTools(jeiRuntime); - - } - - private void hideDebugTools(IJeiRuntime jeiRuntime) { - Collection toRemove = new ArrayList<>(); - - // We use the internal API here as exception as debug tools are not part of the - // public one by design. - toRemove.add(Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack(1).orElse(null)); - - if (!AEConfig.instance().isFeatureEnabled(AEFeature.UNSUPPORTED_DEVELOPER_TOOLS)) { - toRemove.add(Api.INSTANCE.definitions().blocks().cubeGenerator().maybeStack(1).orElse(null)); - toRemove.add(Api.INSTANCE.definitions().blocks().chunkLoader().maybeStack(1).orElse(null)); - toRemove.add(Api.INSTANCE.definitions().blocks().energyGenerator().maybeStack(1).orElse(null)); - toRemove.add(Api.INSTANCE.definitions().blocks().itemGen().maybeStack(1).orElse(null)); - toRemove.add(Api.INSTANCE.definitions().blocks().phantomNode().maybeStack(1).orElse(null)); - - toRemove.add(Api.INSTANCE.definitions().items().toolDebugCard().maybeStack(1).orElse(null)); - toRemove.add(Api.INSTANCE.definitions().items().toolEraser().maybeStack(1).orElse(null)); - toRemove.add(Api.INSTANCE.definitions().items().toolMeteoritePlacer().maybeStack(1).orElse(null)); - toRemove.add(Api.INSTANCE.definitions().items().toolReplicatorCard().maybeStack(1).orElse(null)); - } - - jeiRuntime.getIngredientManager().removeIngredientsAtRuntime(mezz.jei.api.constants.VanillaTypes.ITEM, - toRemove); - } - -}