REI integration
This commit is contained in:
@@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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<CondenserOutputDisplay> {
|
||||
|
||||
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<Widget> setupDisplay(CondenserOutputDisplay recipeDisplay, Rectangle bounds) {
|
||||
|
||||
List<Widget> 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<String> 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<EntryStack> output;
|
||||
|
||||
private final List<EntryStack> viableStorageComponents;
|
||||
|
||||
public CondenserOutputDisplay(CondenserOutput output) {
|
||||
this.type = output;
|
||||
this.output = Collections.singletonList(
|
||||
EntryStack.create(getOutput(type))
|
||||
);
|
||||
this.viableStorageComponents = getViableStorageComponents(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<EntryStack>> getInputEntries() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntryStack> 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<EntryStack> getViableStorageComponents(CondenserOutput condenserOutput) {
|
||||
IMaterials materials = AEApi.instance().definitions().materials();
|
||||
List<EntryStack> 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<EntryStack> 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<EntryStack> getViableStorageComponents() {
|
||||
return viableStorageComponents;
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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<GrinderRecipeWrapper> {
|
||||
|
||||
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<Widget> 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<Widget> widgets = new ArrayList<>();
|
||||
widgets.add(background);
|
||||
|
||||
// Add the input
|
||||
List<EntryStack> 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<EntryStack> output = recipe.getOutputEntries();
|
||||
List<Double> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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<List<EntryStack>> input;
|
||||
private final List<EntryStack> outputs;
|
||||
private final List<Double> outputChances;
|
||||
|
||||
public GrinderRecipeWrapper(GrinderRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
this.input = CollectionUtils.map(recipe.getPreviewInputs(), i -> CollectionUtils.map(i.getMatchingStacksClient(), EntryStack::create));
|
||||
|
||||
List<EntryStack> outputs = new ArrayList<>();
|
||||
List<Double> 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<List<EntryStack>> getInputEntries() {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntryStack> getOutputEntries() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
public List<Double> getOutputChances() {
|
||||
return outputChances;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<EntryStack>> getRequiredEntries() {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getRecipeCategory() {
|
||||
return GrinderRecipeCategory.UID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Identifier> getRecipeLocation() {
|
||||
return Optional.of(recipe.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<ScreenHandler> containerInfo, ScreenHandler container) {
|
||||
return input;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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<InscriberRecipeWrapper> {
|
||||
|
||||
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<Widget> setupDisplay(InscriberRecipeWrapper recipeDisplay, Rectangle bounds) {
|
||||
Identifier location = new Identifier(AppEng.MOD_ID, "textures/guis/inscriber.png");
|
||||
|
||||
List<Widget> widgets = new ArrayList<>();
|
||||
widgets.add(Widgets.createTexturedWidget(location, bounds.x, bounds.y, 44, 15, 97, 64));
|
||||
|
||||
List<List<EntryStack>> 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;
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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<EntryStack> middleInput;
|
||||
private final List<EntryStack> topOptional;
|
||||
private final List<EntryStack> 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<List<EntryStack>> getInputEntries() {
|
||||
return ImmutableList.of(
|
||||
topOptional, middleInput, bottomOptional
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntryStack> getOutputEntries() {
|
||||
return ImmutableList.of(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<EntryStack>> getRequiredEntries() {
|
||||
return getInputEntries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getRecipeCategory() {
|
||||
return InscriberRecipeCategory.UID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Identifier> getRecipeLocation() {
|
||||
return Optional.of(recipe.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<ScreenHandler> containerInfo, ScreenHandler container) {
|
||||
return getInputEntries();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.integration.modules.jei;
|
||||
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class RecipeTransferHandler<T extends ScreenHandler> implements AutoTransferHandler {
|
||||
|
||||
private final Class<T> containerClass;
|
||||
|
||||
RecipeTransferHandler(Class<T> containerClass) {
|
||||
this.containerClass = containerClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result handle(Context context) {
|
||||
|
||||
ScreenHandler container = context.getContainerScreen().getScreenHandler();
|
||||
|
||||
if (!containerClass.isInstance(container)) {
|
||||
return Result.createNotApplicable();
|
||||
}
|
||||
|
||||
if (!context.isActuallyCrafting()) {
|
||||
// This is just to check whether the button is enabled
|
||||
return Result.createSuccessful();
|
||||
}
|
||||
|
||||
List<List<EntryStack>> ingredients = context.getRecipe().getInputEntries();
|
||||
|
||||
final CompoundTag recipe = new CompoundTag();
|
||||
|
||||
for (int slotIndex = 0; slotIndex < ingredients.size(); slotIndex++) {
|
||||
List<EntryStack> ingredientEntry = ingredients.get(slotIndex);
|
||||
|
||||
for (final Slot slot : container.slots) {
|
||||
if (slot instanceof CraftingMatrixSlot || slot instanceof FakeCraftingMatrixSlot) {
|
||||
int containerSlotInvIdx = ((SlotMixin) slot).getIndex();
|
||||
if (containerSlotInvIdx == slotIndex) {
|
||||
final ListTag tags = new ListTag();
|
||||
final List<ItemStack> list = new ArrayList<>();
|
||||
|
||||
// prefer pure crystals.
|
||||
for (EntryStack stack : ingredientEntry) {
|
||||
if (Platform.isRecipePrioritized(stack.getItemStack())) {
|
||||
list.add(0, stack.getItemStack());
|
||||
} else {
|
||||
list.add(stack.getItemStack());
|
||||
}
|
||||
}
|
||||
|
||||
for (final ItemStack is : list) {
|
||||
final CompoundTag tag = new CompoundTag();
|
||||
is.toTag(tag);
|
||||
tags.add(tag);
|
||||
}
|
||||
|
||||
recipe.put("#" + containerSlotInvIdx, tags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NetworkHandler.instance().sendToServer(new JEIRecipePacket(recipe));
|
||||
|
||||
return Result.createFailed(""); // this will return to the screen
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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<Item> 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<ItemStack> 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 }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user