2020-08-03 17:50:13 +00:00
|
|
|
package com.thebrokenrail.energonrelics.client.rei.infuser;
|
2020-07-30 19:49:18 +00:00
|
|
|
|
|
|
|
import com.thebrokenrail.energonrelics.EnergonRelics;
|
2020-08-03 17:50:13 +00:00
|
|
|
import com.thebrokenrail.energonrelics.block.entity.infuser.InfuserEntry;
|
|
|
|
import com.thebrokenrail.energonrelics.block.entity.infuser.InfuserOutputItem;
|
|
|
|
import com.thebrokenrail.energonrelics.block.entity.infuser.InfuserRegistry;
|
|
|
|
import com.thebrokenrail.energonrelics.client.rei.EnergonRelicsPlugin;
|
2020-07-30 19:49:18 +00:00
|
|
|
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
2020-08-03 17:50:13 +00:00
|
|
|
import com.thebrokenrail.energonrelics.util.BooleanIterator;
|
2020-07-30 19:49:18 +00:00
|
|
|
import me.shedaniel.math.Point;
|
|
|
|
import me.shedaniel.math.Rectangle;
|
|
|
|
import me.shedaniel.rei.api.EntryStack;
|
|
|
|
import me.shedaniel.rei.api.RecipeCategory;
|
2020-08-03 17:50:13 +00:00
|
|
|
import me.shedaniel.rei.api.RecipeHelper;
|
2020-07-30 19:49:18 +00:00
|
|
|
import me.shedaniel.rei.api.widgets.Widgets;
|
|
|
|
import me.shedaniel.rei.gui.widget.Widget;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
|
|
import net.fabricmc.api.Environment;
|
|
|
|
import net.minecraft.client.resource.language.I18n;
|
2020-08-03 17:50:13 +00:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2020-08-03 17:00:08 +00:00
|
|
|
import net.minecraft.text.Text;
|
2020-07-30 19:49:18 +00:00
|
|
|
import net.minecraft.text.TranslatableText;
|
|
|
|
import net.minecraft.util.Identifier;
|
2020-08-03 17:00:08 +00:00
|
|
|
import net.minecraft.util.registry.Registry;
|
2020-07-30 19:49:18 +00:00
|
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2020-08-03 17:50:13 +00:00
|
|
|
import java.util.Map;
|
2020-07-30 19:49:18 +00:00
|
|
|
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
|
|
public class InfuserCategory implements RecipeCategory<InfuserDisplay> {
|
|
|
|
@Override
|
|
|
|
public List<Widget> setupDisplay(InfuserDisplay display, Rectangle bounds) {
|
|
|
|
Point startPoint = new Point(bounds.getCenterX() - 41, bounds.y + 10);
|
|
|
|
List<Widget> widgets = new ArrayList<>();
|
|
|
|
widgets.add(Widgets.createRecipeBase(bounds));
|
2020-07-30 22:57:20 +00:00
|
|
|
widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width / 2, bounds.y + 9), new TranslatableText("category.rei." + EnergonRelics.NAMESPACE + ".infuser.chance", new DecimalFormat("###.##").format(display.successChance * 100d))).noShadow().centered().color(0xFF404040, 0xFFBBBBBB));
|
|
|
|
widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width / 2, bounds.y + 18), new TranslatableText("category.rei." + EnergonRelics.NAMESPACE + ".infuser.cost", display.cost)).noShadow().centered().color(0xFF404040, 0xFFBBBBBB));
|
|
|
|
widgets.add(Widgets.createArrow(new Point(startPoint.x + 24, startPoint.y + 25)).animationDurationTicks(HardcodedConfig.INFUSER_TIME));
|
|
|
|
widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 26)).entries(display.getInputEntries().get(0)).markInput());
|
2020-08-03 17:00:08 +00:00
|
|
|
|
|
|
|
int outputX = startPoint.x + 61;
|
|
|
|
int outputY = startPoint.y + 26;
|
|
|
|
if (display.outputsItem) {
|
|
|
|
widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 61, startPoint.y + 26)));
|
|
|
|
widgets.add(Widgets.createSlot(new Point(outputX, outputY)).entries(display.getOutputEntries()).disableBackground().markOutput());
|
|
|
|
} else {
|
|
|
|
Identifier outputID = Registry.ITEM.getId(display.getOutputEntries().get(0).getItem());
|
|
|
|
Text text = new TranslatableText("category.rei." + EnergonRelics.NAMESPACE + ".infuser.display_item." + outputID.getNamespace() + "." + outputID.getPath());
|
|
|
|
widgets.add(Widgets.createLabel(new Point(outputX - 7, outputY + 3), text).noShadow().leftAligned().color(0xFF404040, 0xFFBBBBBB));
|
|
|
|
}
|
2020-07-30 19:49:18 +00:00
|
|
|
return widgets;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getDisplayHeight() {
|
2020-07-30 22:57:20 +00:00
|
|
|
return 66;
|
2020-07-30 19:49:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Identifier getIdentifier() {
|
|
|
|
return EnergonRelicsPlugin.INFUSER;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EntryStack getLogo() {
|
|
|
|
return EntryStack.create(EnergonRelics.INFUSER_BLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getCategoryName() {
|
|
|
|
return I18n.translate("category.rei." + EnergonRelics.NAMESPACE + ".infuser.name");
|
|
|
|
}
|
2020-08-03 17:50:13 +00:00
|
|
|
|
|
|
|
public static void register(RecipeHelper recipeHelper) {
|
|
|
|
for (Map.Entry<Item, InfuserEntry> entry : InfuserRegistry.entrySet()) {
|
|
|
|
BooleanIterator.run(isFail -> {
|
|
|
|
List<InfuserOutputItem> list = entry.getValue().getOutputItems(isFail);
|
|
|
|
for (InfuserOutputItem item : list) {
|
|
|
|
recipeHelper.registerDisplay(new InfuserDisplay(new ItemStack(entry.getKey()), item, entry.getValue().getSingleChance(isFail), entry.getValue().cost));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-07-30 19:49:18 +00:00
|
|
|
}
|