Some fixes for **rei** 6.x

This commit is contained in:
Frank Bauer 2021-06-24 22:36:27 +02:00
parent 63b524af62
commit aa1b0d87bb
4 changed files with 113 additions and 124 deletions

View file

@ -1,43 +1,42 @@
package ru.betterend.integration.rei; package ru.betterend.integration.rei;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.ints.IntList;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.DisplayRenderer;
import me.shedaniel.rei.api.client.gui.SimpleDisplayRenderer;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.client.registry.display.TransferDisplayCategory;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import org.jetbrains.annotations.NotNull;
import ru.betterend.recipe.builders.AlloyingRecipe;
import ru.betterend.registry.EndBlocks;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.List; import java.util.List;
import org.jetbrains.annotations.NotNull; public class REIAlloyingCategory implements TransferDisplayCategory<REIAlloyingDisplay> {
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
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.client.gui.GuiComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.recipe.builders.AlloyingRecipe;
import ru.betterend.registry.EndBlocks;
import ru.betterend.util.LangUtil;
public class REIAlloyingCategory implements TransferRecipeCategory<REIAlloyingDisplay> {
@Override @Override
public @NotNull ResourceLocation getIdentifier() { public @NotNull CategoryIdentifier getCategoryIdentifier() {
return AlloyingRecipe.ID; return AlloyingRecipe.ID;
} }
@Override @Override
public @NotNull String getCategoryName() { public @NotNull Component getTitle() {
return LangUtil.translate(EndBlocks.END_STONE_SMELTER.getDescriptionId()); return new TranslatableComponent(EndBlocks.END_STONE_SMELTER.getDescriptionId());
} }
@Override @Override
public @NotNull EntryStack getLogo() { public @NotNull EntryStack getIcon() {
return REIPlugin.END_STONE_SMELTER; return REIPlugin.END_STONE_SMELTER;
} }
@ -53,14 +52,14 @@ public class REIAlloyingCategory implements TransferRecipeCategory<REIAlloyingDi
widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 5), widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 5),
new TranslatableComponent("category.rei.cooking.time&xp", df.format(display.getXp()), df.format(smeltTime / 20D))).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB)); new TranslatableComponent("category.rei.cooking.time&xp", df.format(display.getXp()), df.format(smeltTime / 20D))).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB));
widgets.add(Widgets.createArrow(new Point(startPoint.x + 24, startPoint.y + 8)).animationDurationTicks(smeltTime)); widgets.add(Widgets.createArrow(new Point(startPoint.x + 24, startPoint.y + 8)).animationDurationTicks(smeltTime));
List<List<EntryStack>> inputEntries = display.getInputEntries(); List<EntryIngredient> inputEntries = display.getInputEntries();
widgets.add(Widgets.createSlot(new Point(startPoint.x - 20, startPoint.y + 1)).entries(inputEntries.get(0)).markInput()); widgets.add(Widgets.createSlot(new Point(startPoint.x - 20, startPoint.y + 1)).entries(inputEntries.get(0)).markInput());
if (inputEntries.size() > 1) { if (inputEntries.size() > 1) {
widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(inputEntries.get(1)).markInput()); widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(inputEntries.get(1)).markInput());
} else { } else {
widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(Lists.newArrayList()).markInput()); widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(Lists.newArrayList()).markInput());
} }
widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 9)).entries(display.getResultingEntries().get(0)).disableBackground().markOutput()); widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 9)).entries(display.getOutputEntries().get(0)).disableBackground().markOutput());
return widgets; return widgets;
} }
@ -78,8 +77,8 @@ public class REIAlloyingCategory implements TransferRecipeCategory<REIAlloyingDi
} }
@Override @Override
public @NotNull RecipeEntry getSimpleRenderer(REIAlloyingDisplay recipe) { public DisplayRenderer getDisplayRenderer(REIAlloyingDisplay recipe) {
return SimpleRecipeEntry.from(recipe.getInputEntries(), recipe.getResultingEntries()); return SimpleDisplayRenderer.from(recipe.getInputEntries(), recipe.getOutputEntries());
} }
@Override @Override

View file

@ -1,47 +1,52 @@
package ru.betterend.integration.rei; package ru.betterend.integration.rei;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay;
import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.api.common.util.EntryStacks;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.BlastingRecipe;
import net.minecraft.world.item.crafting.Recipe;
import org.jetbrains.annotations.NotNull;
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
import ru.betterend.recipe.builders.AlloyingRecipe;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull; public class REIAlloyingDisplay extends BasicDisplay implements SimpleGridMenuDisplay {
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.TransferRecipeDisplay;
import me.shedaniel.rei.server.ContainerInfo;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.BlastingRecipe;
import net.minecraft.world.item.crafting.Recipe;
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
import ru.betterend.recipe.builders.AlloyingRecipe;
public class REIAlloyingDisplay implements TransferRecipeDisplay {
private static List<EntryStack> fuel; private static List<EntryStack> fuel;
private Recipe<?> recipe; private Recipe<?> recipe;
private List<List<EntryStack>> input;
private List<EntryStack> output;
private float xp; private float xp;
private double smeltTime; private double smeltTime;
public REIAlloyingDisplay(AlloyingRecipe recipe) { public REIAlloyingDisplay(AlloyingRecipe recipe) {
super(
EntryIngredients.ofIngredients(recipe.getIngredients()),
Collections.singletonList(EntryIngredients.of(recipe.getResultItem()))
);
this.recipe = recipe; this.recipe = recipe;
this.input = EntryStack.ofIngredients(recipe.getIngredients());
this.output = Collections.singletonList(EntryStack.create(recipe.getResultItem()));
this.xp = recipe.getExperience(); this.xp = recipe.getExperience();
this.smeltTime = recipe.getSmeltTime(); this.smeltTime = recipe.getSmeltTime();
} }
public REIAlloyingDisplay(BlastingRecipe recipe) { public REIAlloyingDisplay(BlastingRecipe recipe) {
super(
EntryIngredients.ofIngredients(recipe.getIngredients()),
Collections.singletonList(EntryIngredients.of(recipe.getResultItem()))
);
this.recipe = recipe; this.recipe = recipe;
this.input = EntryStack.ofIngredients(recipe.getIngredients());
this.output = Collections.singletonList(EntryStack.create(recipe.getResultItem()));
this.xp = recipe.getExperience(); this.xp = recipe.getExperience();
this.smeltTime = recipe.getCookingTime(); this.smeltTime = recipe.getCookingTime();
} }
@ -51,29 +56,19 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay {
} }
@Override @Override
public @NotNull Optional<ResourceLocation> getRecipeLocation() { public @NotNull Optional<ResourceLocation> getDisplayLocation() {
return Optional.ofNullable(recipe).map(Recipe::getId); 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 @Override
public @NotNull ResourceLocation getRecipeCategory() { public CategoryIdentifier<?> getCategoryIdentifier() {
return AlloyingRecipe.ID; return AlloyingRecipe.ID;
} }
@Override // @Override
public @NotNull List<List<EntryStack>> getRequiredEntries() { // public @NotNull List<List<EntryStack>> getRequiredEntries() {
return this.input; // return this.input;
} // }
public float getXp() { public float getXp() {
return this.xp; return this.xp;
@ -97,14 +92,14 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay {
return 1; return 1;
} }
@Override // @Override
public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<AbstractContainerMenu> containerInfo, AbstractContainerMenu container) { // public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<AbstractContainerMenu> containerInfo, AbstractContainerMenu container) {
return this.input; // return this.input;
} // }
static { static {
fuel = EndStoneSmelterBlockEntity.availableFuels().keySet().stream() fuel = EndStoneSmelterBlockEntity.availableFuels().keySet().stream()
.map(Item::getDefaultInstance).map(EntryStack::create) .map(Item::getDefaultInstance).map(EntryStacks::of)
.map(e -> e.setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, stack -> Collections.singletonList(new TranslatableComponent("category.rei.smelting.fuel") .map(e -> e.setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, stack -> Collections.singletonList(new TranslatableComponent("category.rei.smelting.fuel")
.withStyle(ChatFormatting.YELLOW)))).collect(Collectors.toList()); .withStyle(ChatFormatting.YELLOW)))).collect(Collectors.toList());
} }

View file

@ -1,40 +1,39 @@
package ru.betterend.integration.rei; package ru.betterend.integration.rei;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.DisplayRenderer;
import me.shedaniel.rei.api.client.gui.widgets.Slot;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryStacks;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.item.Items;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.List; import java.util.List;
import org.jetbrains.annotations.NotNull; public class REIAlloyingFuelCategory implements DisplayCategory<REIAlloyingFuelDisplay> {
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
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.entries.RecipeEntry;
import me.shedaniel.rei.gui.widget.Widget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
public class REIAlloyingFuelCategory implements RecipeCategory<REIAlloyingFuelDisplay> {
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##"); private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
@Override @Override
public @NotNull ResourceLocation getIdentifier() { public @NotNull CategoryIdentifier getCategoryIdentifier() {
return REIPlugin.ALLOYING_FUEL; return REIPlugin.ALLOYING_FUEL;
} }
@Override @Override
public @NotNull String getCategoryName() { public @NotNull Component getTitle() {
return I18n.get("category.rei.fuel"); return new TranslatableComponent("category.rei.fuel");
} }
@Override @Override
@ -43,12 +42,12 @@ public class REIAlloyingFuelCategory implements RecipeCategory<REIAlloyingFuelDi
} }
@Override @Override
public @NotNull EntryStack getLogo() { public @NotNull EntryStack getIcon() {
return EntryStack.create(Items.COAL); return EntryStacks.of(Items.COAL);
} }
@Override @Override
public @NotNull List<Widget> setupDisplay(REIAlloyingFuelDisplay recipeDisplay, Rectangle bounds) { public List<Widget> setupDisplay(REIAlloyingFuelDisplay recipeDisplay, Rectangle bounds) {
Point startPoint = new Point(bounds.getCenterX() - 41, bounds.getCenterY() - 17); Point startPoint = new Point(bounds.getCenterX() - 41, bounds.getCenterY() - 17);
String burnTime = DECIMAL_FORMAT.format(recipeDisplay.getFuelTime()); String burnTime = DECIMAL_FORMAT.format(recipeDisplay.getFuelTime());
List<Widget> widgets = Lists.newArrayList(); List<Widget> widgets = Lists.newArrayList();
@ -61,10 +60,10 @@ public class REIAlloyingFuelCategory implements RecipeCategory<REIAlloyingFuelDi
} }
@Override @Override
public @NotNull RecipeEntry getSimpleRenderer(REIAlloyingFuelDisplay recipe) { public DisplayRenderer getDisplayRenderer(REIAlloyingFuelDisplay recipe) {
Slot slot = Widgets.createSlot(new Point(0, 0)).entries(recipe.getInputEntries().get(0)).disableBackground().disableHighlight(); Slot slot = Widgets.createSlot(new Point(0, 0)).entries(recipe.getInputEntries().get(0)).disableBackground().disableHighlight();
String burnItems = DECIMAL_FORMAT.format(recipe.getFuelTime() / 200d); String burnItems = DECIMAL_FORMAT.format(recipe.getFuelTime() / 200d);
return new RecipeEntry() { return new DisplayRenderer() {
private TranslatableComponent text = new TranslatableComponent("category.rei.fuel.time_short.items", burnItems); private TranslatableComponent text = new TranslatableComponent("category.rei.fuel.time_short.items", burnItems);
@Override @Override

View file

@ -1,35 +1,31 @@
package ru.betterend.integration.rei; package ru.betterend.integration.rei;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import net.minecraft.nbt.CompoundTag;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.jetbrains.annotations.NotNull; public class REIAlloyingFuelDisplay extends BasicDisplay {
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeDisplay;
import net.minecraft.resources.ResourceLocation;
public class REIAlloyingFuelDisplay implements RecipeDisplay {
private final EntryStack fuel;
private final int fuelTime; private final int fuelTime;
public REIAlloyingFuelDisplay(EntryStack fuel, int fuelTime) { public REIAlloyingFuelDisplay(List<EntryIngredient> fuel, CompoundTag tag) {
this.fuel = fuel; this(fuel, tag.getInt("fuelTime"));
}
public REIAlloyingFuelDisplay(List<EntryIngredient> fuel, int fuelTime) {
super(fuel, Collections.emptyList());
this.fuelTime = fuelTime; this.fuelTime = fuelTime;
} }
/*public REIAlloyingFuelDisplay(EntryStack fuel, int fuelTime) {
this.fuel = fuel;
this.fuelTime = fuelTime;
}*/
@Override @Override
public @NotNull List<List<EntryStack>> getInputEntries() { public CategoryIdentifier<?> getCategoryIdentifier() {
return Collections.singletonList(Collections.singletonList(fuel));
}
@Override
public @NotNull List<List<EntryStack>> getResultingEntries() {
return Collections.emptyList();
}
@Override
public @NotNull ResourceLocation getRecipeCategory() {
return REIPlugin.ALLOYING_FUEL; return REIPlugin.ALLOYING_FUEL;
} }