Anvil crafting

This commit is contained in:
Aleksey 2020-10-06 17:59:23 +03:00
parent 1ceb433a61
commit 115ce76b5a
12 changed files with 270 additions and 61 deletions

View file

@ -99,7 +99,7 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay {
@Override
public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<ScreenHandler> containerInfo, ScreenHandler container) {
return input;
return this.input;
}
static {

View file

@ -0,0 +1,85 @@
package ru.betterend.compat;
import java.util.Collections;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.ints.IntList;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.TransferRecipeCategory;
import me.shedaniel.rei.api.widgets.Widgets;
import me.shedaniel.rei.gui.entries.RecipeEntry;
import me.shedaniel.rei.gui.entries.SimpleRecipeEntry;
import me.shedaniel.rei.gui.widget.Widget;
import net.minecraft.block.Blocks;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import ru.betterend.recipe.AnvilSmithingRecipe;
import ru.betterend.util.LangUtil;
public class REIAnvilCategory implements TransferRecipeCategory<REIAnvilDisplay> {
@Override
public @NotNull Identifier getIdentifier() {
return AnvilSmithingRecipe.ID;
}
@Override
public @NotNull String getCategoryName() {
return LangUtil.translate(Blocks.ANVIL.getTranslationKey());
}
@Override
public @NotNull EntryStack getLogo() {
return REIPlugin.ANVIL;
}
@Override
public @NotNull List<Widget> setupDisplay(REIAnvilDisplay display, Rectangle bounds) {
Point startPoint = new Point(bounds.getCenterX() - 41, bounds.y + 10);
List<Widget> widgets = Lists.newArrayList();
widgets.add(Widgets.createRecipeBase(bounds));
int x = startPoint.x + 10;
int y = startPoint.y;
widgets.add(Widgets.createResultSlotBackground(new Point(x + 61, y + 9)));
List<List<EntryStack>> inputEntries = display.getInputEntries();
widgets.add(Widgets.createArrow(new Point(x + 24, y + 8)));
widgets.add(Widgets.createSlot(new Point(x - 20, y + 8)).entries(inputEntries.get(0)).markInput());
widgets.add(Widgets.createSlot(new Point(x + 1, y + 8)).entries(inputEntries.get(1)).markInput());
widgets.add(Widgets.createSlot(new Point(x + 61, y + 9)).entries(display.getResultingEntries().get(0)).disableBackground().markOutput());
return widgets;
}
@Override
public void renderRedSlots(MatrixStack matrices, List<Widget> widgets, Rectangle bounds, REIAnvilDisplay display,
IntList redSlots) {
Point startPoint = new Point(bounds.getCenterX() - 41, bounds.getCenterY() - 27);
matrices.push();
matrices.translate(0, 0, 400);
if (redSlots.contains(0)) {
DrawableHelper.fill(matrices, startPoint.x - 20, startPoint.y + 8, startPoint.x - 20 + 16, startPoint.y + 8 + 16, 1090453504);
DrawableHelper.fill(matrices, startPoint.x + 1, startPoint.y + 8, startPoint.x + 1 + 16, startPoint.y + 8 + 16, 1090453504);
}
matrices.pop();
}
@Override
public @NotNull RecipeEntry getSimpleRenderer(REIAnvilDisplay recipe) {
return SimpleRecipeEntry.from(Collections.singletonList(recipe.getInputEntries().get(0)), recipe.getResultingEntries());
}
@Override
public int getDisplayHeight() {
return 49;
}
}

View file

@ -0,0 +1,71 @@
package ru.betterend.compat;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.jetbrains.annotations.NotNull;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.TransferRecipeDisplay;
import me.shedaniel.rei.server.ContainerInfo;
import net.minecraft.recipe.Recipe;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.Identifier;
import ru.betterend.recipe.AnvilSmithingRecipe;
public class REIAnvilDisplay implements TransferRecipeDisplay {
private AnvilSmithingRecipe recipe;
private List<List<EntryStack>> input;
private List<EntryStack> output;
public REIAnvilDisplay(AnvilSmithingRecipe recipe) {
this.recipe = recipe;
this.input = EntryStack.ofIngredients(recipe.getPreviewInputs());
this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
}
@Override
public @NotNull Optional<Identifier> getRecipeLocation() {
return Optional.ofNullable(recipe).map(Recipe::getId);
}
@Override
public @NotNull List<List<EntryStack>> getInputEntries() {
return this.input;
}
@Override
public @NotNull List<List<EntryStack>> getResultingEntries() {
return Collections.singletonList(output);
}
@Override
public @NotNull Identifier getRecipeCategory() {
return AnvilSmithingRecipe.ID;
}
@Override
public @NotNull List<List<EntryStack>> getRequiredEntries() {
return this.input;
}
@Override
public int getWidth() {
return 2;
}
@Override
public int getHeight() {
return 1;
}
@Override
public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<ScreenHandler> containerInfo,
ScreenHandler container) {
return this.input;
}
}

View file

@ -11,5 +11,4 @@ public class REIContainer implements Runnable {
public void run() {
ContainerInfoHandler.registerContainerInfo(AlloyingRecipe.ID, CraftingContainerInfoWrapper.create(EndStoneSmelterScreenHandler.class));
}
}

View file

@ -3,19 +3,28 @@ package ru.betterend.compat;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeHelper;
import me.shedaniel.rei.api.plugins.REIPluginV0;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Blocks;
import net.minecraft.recipe.BlastingRecipe;
import net.minecraft.util.Identifier;
import ru.betterend.BetterEnd;
import ru.betterend.recipe.AlloyingRecipe;
import ru.betterend.recipe.AnvilSmithingRecipe;
import ru.betterend.registry.BlockRegistry;
@Environment(EnvType.CLIENT)
public class REIPlugin implements REIPluginV0 {
public final static Identifier PLUGIN_ID = BetterEnd.makeID("rei_plugin");
public final static Identifier ALLOING = AlloyingRecipe.ID;
public final static Identifier SMITHING = AlloyingRecipe.ID;
public final static EntryStack END_STONE_SMELTER = EntryStack.create(BlockRegistry.END_STONE_SMELTER);
public final static EntryStack ANVIL = EntryStack.create(Blocks.ANVIL);
@Override
public Identifier getPluginIdentifier() {
@ -24,17 +33,21 @@ public class REIPlugin implements REIPluginV0 {
@Override
public void registerRecipeDisplays(RecipeHelper recipeHelper) {
recipeHelper.registerRecipes(AlloyingRecipe.ID, AlloyingRecipe.class, REIAlloyingDisplay::new);
recipeHelper.registerRecipes(AlloyingRecipe.ID, BlastingRecipe.class, REIAlloyingDisplay::new);
recipeHelper.registerRecipes(ALLOING, AlloyingRecipe.class, REIAlloyingDisplay::new);
recipeHelper.registerRecipes(ALLOING, BlastingRecipe.class, REIAlloyingDisplay::new);
recipeHelper.registerRecipes(SMITHING, AnvilSmithingRecipe.class, REIAnvilDisplay::new);
}
@Override
public void registerOthers(RecipeHelper recipeHelper) {
recipeHelper.registerWorkingStations(AlloyingRecipe.ID, END_STONE_SMELTER);
recipeHelper.registerWorkingStations(ALLOING, END_STONE_SMELTER);
recipeHelper.registerWorkingStations(SMITHING, ANVIL);
recipeHelper.removeAutoCraftButton(SMITHING);
}
@Override
public void registerPluginCategories(RecipeHelper recipeHelper) {
recipeHelper.registerCategory(new REIAlloyingCategory());
recipeHelper.registerCategories(new REIAlloyingCategory(),
new REIAnvilCategory());
}
}