Start on REI support, very basic right now, but it will help a lot when adding recipes.
This commit is contained in:
parent
a80d2183f9
commit
52da17dfd5
6 changed files with 182 additions and 1 deletions
|
@ -53,6 +53,10 @@ repositories {
|
|||
name = 'sponge'
|
||||
url = 'https://repo.spongepowered.org/maven'
|
||||
}
|
||||
maven {
|
||||
name = 'curseforge'
|
||||
url = 'https://minecraft.curseforge.com/api/maven'
|
||||
}
|
||||
}
|
||||
|
||||
version = "3.0.0"
|
||||
|
@ -86,6 +90,7 @@ dependencies {
|
|||
|
||||
modCompile "io.github.prospector.modmenu:ModMenu:1.5.4-85"
|
||||
modCompile "io.github.prospector.silk:SilkAPI:1.2.4-43"
|
||||
modCompile "me.shedaniel:RoughlyEnoughItems:2.9.7+build.143"
|
||||
|
||||
// modCompile ('RebornCore:RebornCore-1.14:4.0.0.14') {
|
||||
// transitive = false
|
||||
|
|
|
@ -124,7 +124,7 @@ public class BlockCable extends BlockWithEntity {
|
|||
|
||||
private Boolean canConnectTo(IWorld world, BlockPos pos, Direction facing) {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity != null && (blockEntity instanceof EnergyBlockEntity)) {
|
||||
if (blockEntity != null && (blockEntity instanceof EnergyBlockEntity || blockEntity instanceof CableBlockEntity)) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
|
|
71
src/main/java/techreborn/rei/MachineRecipeCategory.java
Normal file
71
src/main/java/techreborn/rei/MachineRecipeCategory.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
package techreborn.rei;
|
||||
|
||||
import me.shedaniel.rei.api.RecipeCategory;
|
||||
import me.shedaniel.rei.api.Renderable;
|
||||
import me.shedaniel.rei.api.Renderer;
|
||||
import me.shedaniel.rei.gui.renderables.RecipeRenderer;
|
||||
import me.shedaniel.rei.gui.widget.RecipeBaseWidget;
|
||||
import me.shedaniel.rei.gui.widget.SlotWidget;
|
||||
import me.shedaniel.rei.gui.widget.Widget;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MachineRecipeCategory<R extends RebornRecipe> implements RecipeCategory<MachineRecipeDisplay<R>> {
|
||||
|
||||
private final RebornRecipeType<R> rebornRecipeType;
|
||||
|
||||
public MachineRecipeCategory(RebornRecipeType<R> rebornRecipeType) {
|
||||
this.rebornRecipeType = rebornRecipeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getIdentifier() {
|
||||
return rebornRecipeType.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategoryName() {
|
||||
return rebornRecipeType.getName().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderer getIcon() {
|
||||
return Renderable.fromItemStack(new ItemStack(ReiPlugin.iconMap.getOrDefault(rebornRecipeType, () -> Items.DIAMOND_SHOVEL).asItem()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeRenderer getSimpleRenderer(MachineRecipeDisplay<R> recipe) {
|
||||
return Renderable.fromRecipe(() -> Collections.singletonList(recipe.getInput().get(0)), recipe::getOutput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Widget> setupDisplay(Supplier<MachineRecipeDisplay<R>> recipeDisplaySupplier, Rectangle bounds) {
|
||||
|
||||
MachineRecipeDisplay<R> machineRecipe = recipeDisplaySupplier.get();
|
||||
|
||||
Point startPoint = new Point((int) bounds.getCenterX() - 41, (int) bounds.getCenterY() - 27);
|
||||
List<Widget> widgets = new LinkedList<>();
|
||||
widgets.add(new RecipeBaseWidget(bounds));
|
||||
|
||||
int i = 0;
|
||||
for (List<ItemStack> inputs : machineRecipe.getInput()){
|
||||
widgets.add(new SlotWidget(startPoint.x + 1, startPoint.y + 1 + (i++ * 20), inputs, true, true, true));
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (ItemStack outputs : machineRecipe.getOutput()){
|
||||
widgets.add(new SlotWidget(startPoint.x + 61, startPoint.y + 1 + (i++ * 20), Collections.singletonList(outputs), true, true, true));
|
||||
}
|
||||
|
||||
return widgets;
|
||||
}
|
||||
}
|
49
src/main/java/techreborn/rei/MachineRecipeDisplay.java
Normal file
49
src/main/java/techreborn/rei/MachineRecipeDisplay.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
package techreborn.rei;
|
||||
|
||||
import me.shedaniel.rei.api.RecipeDisplay;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.crafting.RebornIngredient;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MachineRecipeDisplay<R extends RebornRecipe> implements RecipeDisplay<R> {
|
||||
|
||||
private final R recipe;
|
||||
private List<List<ItemStack>> inputs;
|
||||
private List<ItemStack> outputs;
|
||||
|
||||
public MachineRecipeDisplay(R recipe) {
|
||||
this.recipe = recipe;
|
||||
this.inputs = recipe.getRebornIngredients().stream().map(RebornIngredient::getStacks).collect(Collectors.toList());
|
||||
this.outputs = recipe.getOutputs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<R> getRecipe() {
|
||||
return Optional.ofNullable(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<ItemStack>> getInput() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<ItemStack>> getRequiredItems() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getOutput() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getRecipeCategory() {
|
||||
return recipe.getRebornRecipeType().getName();
|
||||
}
|
||||
}
|
53
src/main/java/techreborn/rei/ReiPlugin.java
Normal file
53
src/main/java/techreborn/rei/ReiPlugin.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package techreborn.rei;
|
||||
|
||||
import me.shedaniel.rei.api.REIPluginEntry;
|
||||
import me.shedaniel.rei.api.RecipeHelper;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.common.crafting.RebornRecipe;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.RecipeManager;
|
||||
import techreborn.init.ModRecipes;
|
||||
import techreborn.init.TRContent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ReiPlugin implements REIPluginEntry {
|
||||
|
||||
public static final Identifier PLUGIN = new Identifier("techreborn", "techreborn_plugin");
|
||||
|
||||
public static final Map<RebornRecipeType<?>, ItemConvertible> iconMap = new HashMap<>();
|
||||
|
||||
public ReiPlugin() {
|
||||
iconMap.put(ModRecipes.ALLOY_SMELTER, TRContent.Machine.ALLOY_SMELTER);
|
||||
iconMap.put(ModRecipes.GRINDER, TRContent.Machine.GRINDER);
|
||||
//TODO add the others here
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getPluginIdentifier() {
|
||||
return PLUGIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPluginCategories(RecipeHelper recipeHelper) {
|
||||
RecipeManager.getRecipeTypes("techreborn").forEach(rebornRecipeType -> recipeHelper.registerCategory(new MachineRecipeCategory(rebornRecipeType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRecipeDisplays(RecipeHelper recipeHelper) {
|
||||
RecipeManager.getRecipeTypes("techreborn").forEach(rebornRecipeType -> registerMachineRecipe(recipeHelper, rebornRecipeType));
|
||||
}
|
||||
|
||||
private <R extends RebornRecipe> void registerMachineRecipe(RecipeHelper recipeHelper, RebornRecipeType<R> recipeType){
|
||||
recipeHelper.registerRecipes(recipeType.getName(), (Predicate<Recipe>) recipe -> {
|
||||
if (recipe instanceof RebornRecipe) {
|
||||
return ((RebornRecipe) recipe).getRebornRecipeType() == recipeType;
|
||||
}
|
||||
return false;
|
||||
}, recipe -> new MachineRecipeDisplay((RebornRecipe) recipe));
|
||||
}
|
||||
}
|
|
@ -11,6 +11,9 @@
|
|||
],
|
||||
"client": [
|
||||
"techreborn.TechRebornClient"
|
||||
],
|
||||
"rei_plugins": [
|
||||
"techreborn.rei.ReiPlugin"
|
||||
]
|
||||
},
|
||||
"requires": {
|
||||
|
|
Loading…
Add table
Reference in a new issue