aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-06-06 18:36:51 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-06-06 18:36:51 +0800
commit98c2c0f1af8b264cfce5c005f4694318cce001b2 (patch)
tree5a7aaa389ddbf86ae2e4fed06fa40e8d427c8bae
parent36609262e4014e976523130bf26879eac2e90e19 (diff)
downloadRoughlyEnoughItems-98c2c0f1af8b264cfce5c005f4694318cce001b2.tar.gz
RoughlyEnoughItems-98c2c0f1af8b264cfce5c005f4694318cce001b2.tar.bz2
RoughlyEnoughItems-98c2c0f1af8b264cfce5c005f4694318cce001b2.zip
alterative solution to the working stations
-rw-r--r--src/main/java/me/shedaniel/rei/api/RecipeHelper.java10
-rw-r--r--src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java11
-rw-r--r--src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java42
-rw-r--r--src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java31
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java92
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java14
-rwxr-xr-xsrc/main/resources/assets/roughlyenoughitems/lang/en_us.json1
7 files changed, 95 insertions, 106 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java
index 2dbf3717a..cb5e3684f 100644
--- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java
+++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java
@@ -58,9 +58,17 @@ public interface RecipeHelper {
* @param category the category
* @param workingStations the working stations
*/
+ void registerWorkingStations(Identifier category, List<ItemStack>... workingStations);
+
+ /**
+ * Registers the working stations of a category
+ *
+ * @param category the category
+ * @param workingStations the working stations
+ */
void registerWorkingStations(Identifier category, ItemStack... workingStations);
- List<ItemStack> getWorkingStations(Identifier category);
+ List<List<ItemStack>> getWorkingStations(Identifier category);
/**
* Registers a recipe display
diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java
index 45f15d18b..00155ba65 100644
--- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java
+++ b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java
@@ -43,7 +43,7 @@ public class RecipeHelperImpl implements RecipeHelper {
private final List<RecipeCategory> categories = Lists.newArrayList();
private final Map<Identifier, ButtonAreaSupplier> speedCraftAreaSupplierMap = Maps.newHashMap();
private final Map<Identifier, List<SpeedCraftFunctional>> speedCraftFunctionalMap = Maps.newHashMap();
- private final Map<Identifier, List<ItemStack>> categoryWorkingStations = Maps.newHashMap();
+ private final Map<Identifier, List<List<ItemStack>>> categoryWorkingStations = Maps.newHashMap();
private final List<DisplayVisibilityHandler> displayVisibilityHandlers = Lists.newArrayList();
private final List<LiveRecipeGenerator> liveRecipeGenerators = Lists.newArrayList();
private RecipeManager recipeManager;
@@ -87,12 +87,17 @@ public class RecipeHelperImpl implements RecipeHelper {
}
@Override
- public void registerWorkingStations(Identifier category, ItemStack... workingStations) {
+ public void registerWorkingStations(Identifier category, List<ItemStack>... workingStations) {
categoryWorkingStations.get(category).addAll(Arrays.asList(workingStations));
}
@Override
- public List<ItemStack> getWorkingStations(Identifier category) {
+ public void registerWorkingStations(Identifier category, ItemStack... workingStations) {
+ categoryWorkingStations.get(category).addAll(Arrays.asList(workingStations).stream().map(Collections::singletonList).collect(Collectors.toList()));
+ }
+
+ @Override
+ public List<List<ItemStack>> getWorkingStations(Identifier category) {
return categoryWorkingStations.get(category);
}
diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java
index e420ec1c6..5dd88c61e 100644
--- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java
+++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java
@@ -12,6 +12,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.api.*;
import me.shedaniel.rei.client.ScreenHelper;
import me.shedaniel.rei.gui.widget.*;
+import net.minecraft.ChatFormat;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
@@ -20,6 +21,7 @@ import net.minecraft.client.render.GuiLighting;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.Window;
+import net.minecraft.item.ItemStack;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sound.SoundEvents;
@@ -27,16 +29,15 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import java.awt.*;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
import java.util.function.Supplier;
public class RecipeViewingScreen extends Screen {
public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
private static final int TABS_PER_PAGE = 5;
+ private final List<Widget> preWidgets;
private final List<Widget> widgets;
private final List<TabWidget> tabs;
private final Map<RecipeCategory, List<RecipeDisplay>> categoriesMap;
@@ -54,6 +55,7 @@ public class RecipeViewingScreen extends Screen {
public RecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> categoriesMap) {
super(new TextComponent(""));
this.categoryPages = 0;
+ this.preWidgets = Lists.newArrayList();
this.widgets = Lists.newArrayList();
Window window = MinecraftClient.getInstance().window;
this.bounds = new Rectangle(window.getScaledWidth() / 2 - guiWidth / 2, window.getScaledHeight() / 2 - guiHeight / 2, 176, 186);
@@ -121,6 +123,7 @@ public class RecipeViewingScreen extends Screen {
super.init();
this.children.clear();
this.tabs.clear();
+ this.preWidgets.clear();
this.widgets.clear();
this.largestWidth = width - 100;
this.largestHeight = height - 40;
@@ -294,9 +297,38 @@ public class RecipeViewingScreen extends Screen {
else
recipeChoosePageWidget = null;
+ List<List<ItemStack>> workingStations = RoughlyEnoughItemsCore.getRecipeHelper().getWorkingStations(selectedCategory.getIdentifier());
+ if (!workingStations.isEmpty()) {
+ int hh = MathHelper.floor((bounds.height - 16) / 18f);
+ int actualHeight = Math.min(hh, workingStations.size());
+ int innerWidth = MathHelper.ceil(workingStations.size() / ((float) hh));
+ int xx = bounds.x - (10 + innerWidth * 18) + 6;
+ int yy = bounds.y + 16;
+ preWidgets.add(new CategoryBaseWidget(new Rectangle(xx - 6, yy - 6, 15 + innerWidth * 18, 11 + actualHeight * 18)));
+ int index = 0;
+ List list = Collections.singletonList(ChatFormat.YELLOW.toString() + I18n.translate("text.rei.working_station"));
+ xx += (innerWidth - 1) * 18;
+ for(List<ItemStack> workingStation : workingStations) {
+ preWidgets.add(new SlotWidget(xx, yy, workingStation, true, true, true) {
+ @Override
+ protected List<String> getExtraToolTips(ItemStack stack) {
+ return list;
+ }
+ });
+ index++;
+ yy += 18;
+ if (index >= hh) {
+ index = 0;
+ yy = bounds.y + 16;
+ xx -= 18;
+ }
+ }
+ }
+
children.addAll(tabs);
children.add(ScreenHelper.getLastOverlay(true, false));
children.addAll(widgets);
+ children.addAll(preWidgets);
}
public List<Widget> getWidgets() {
@@ -339,6 +371,10 @@ public class RecipeViewingScreen extends Screen {
@Override
public void render(int mouseX, int mouseY, float delta) {
this.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680);
+ preWidgets.forEach(widget -> {
+ GuiLighting.disable();
+ widget.render(mouseX, mouseY, delta);
+ });
if (selectedCategory != null)
selectedCategory.drawCategoryBackground(bounds, mouseX, mouseY, delta);
else {
diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java
index 5a7601e06..6a4208a93 100644
--- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java
+++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java
@@ -25,12 +25,14 @@ import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.sound.PositionedSoundInstance;
+import net.minecraft.item.ItemStack;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.MathHelper;
import java.awt.*;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -95,6 +97,34 @@ public class VillagerRecipeViewingScreen extends Screen {
int guiWidth = MathHelper.clamp(category.getDisplayWidth(display) + 30, 0, largestWidth) + 100;
int guiHeight = MathHelper.clamp(category.getDisplayHeight() + 40, 166, largestHeight);
this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight);
+
+ List<List<ItemStack>> workingStations = RoughlyEnoughItemsCore.getRecipeHelper().getWorkingStations(category.getIdentifier());
+ if (!workingStations.isEmpty()) {
+ int ww = MathHelper.floor((bounds.width - 16) / 18f);
+ int w = Math.min(ww, workingStations.size());
+ int h = MathHelper.ceil(workingStations.size() / ((float)ww));
+ int xx = bounds.x + 16;
+ int yy = bounds.y + bounds.height + 5;
+ widgets.add(new CategoryBaseWidget(new Rectangle(xx - 6, bounds.y + bounds.height - 5, 11 + w * 18, 15 + h * 18)));
+ int index = 0;
+ List list = Collections.singletonList(ChatFormat.YELLOW.toString() + I18n.translate("text.rei.working_station"));
+ for(List<ItemStack> workingStation : workingStations) {
+ widgets.add(new SlotWidget(xx, yy, workingStation, true, true, true) {
+ @Override
+ protected List<String> getExtraToolTips(ItemStack stack) {
+ return list;
+ }
+ });
+ index++;
+ xx += 18;
+ if (index >= ww) {
+ index = 0;
+ xx = bounds.x + 16;
+ yy += 18;
+ }
+ }
+ }
+
this.widgets.add(new CategoryBaseWidget(bounds));
this.scrollListBounds = new Rectangle(bounds.x + 4, bounds.y + 17, 97 + 5, guiHeight - 17 - 7);
this.widgets.add(new SlotBaseWidget(scrollListBounds));
@@ -198,6 +228,7 @@ public class VillagerRecipeViewingScreen extends Screen {
return RoughlyEnoughItemsCore.getConfigManager().getConfig().darkTheme ? 0xFFBBBBBB : 4210752;
}
});
+
this.children.addAll(buttonWidgets);
this.widgets.addAll(tabs);
this.children.addAll(widgets);
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java
index e6efdf3d8..0ca0849d9 100644
--- a/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java
+++ b/src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java
@@ -5,7 +5,6 @@
package me.shedaniel.rei.gui.widget;
-import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.GlStateManager;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.api.ClientHelper;
@@ -14,7 +13,6 @@ import me.shedaniel.rei.api.Renderer;
import me.shedaniel.rei.client.ScreenHelper;
import net.minecraft.ChatFormat;
import net.minecraft.client.render.GuiLighting;
-import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import java.awt.*;
@@ -26,8 +24,6 @@ public class TabWidget extends HighlightableWidget {
public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
public static final Identifier CHEST_GUI_TEXTURE_DARK = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer_dark.png");
- // private final Consumer<QueuedTooltip> tooltipRenderer;
- private final List<ItemStack> slots;
public boolean shown = false, selected = false;
public Renderer renderer;
public int id;
@@ -38,103 +34,15 @@ public class TabWidget extends HighlightableWidget {
public TabWidget(int id, Rectangle bounds) {
this.id = id;
this.bounds = bounds;
- this.slots = Lists.newArrayList();
- // this.tooltipRenderer = tooltip -> {
- // MinecraftClient client = MinecraftClient.getInstance();
- // int specWidth = MathHelper.clamp(slots.size(), 1, 9) * 18 + 10;
- // int specHeight = Math.max(1, MathHelper.ceil(slots.size() / 9)) * 18 + 10;
- // List<String> lines = tooltip.getText();
- // TextRenderer font = client.textRenderer;
- // int width = Math.max(lines.stream().map(font::getStringWidth).max(Integer::compareTo).get(), specWidth);
- // int tooltipHeight = lines.size() <= 1 ? 8 : lines.size() * 10;
- // int height = (lines.isEmpty() ? 0 : (tooltipHeight + 10)) + specHeight;
- // ScreenHelper.drawHoveringWidget(tooltip.getX(), tooltip.getY(), (x, y, aFloat) -> {
- // int currentY = y;
- // if (!lines.isEmpty()) {
- // GlStateManager.disableRescaleNormal();
- // GuiLighting.disable();
- // GlStateManager.disableLighting();
- // this.blitOffset = 1000;
- // this.fillGradient(x - 3, y - 4, x + width + 3, y - 3, -267386864, -267386864);
- // this.fillGradient(x - 3, y + tooltipHeight + 3, x + width + 3, y + tooltipHeight + 4, -267386864, -267386864);
- // this.fillGradient(x - 3, y - 3, x + width + 3, y + tooltipHeight + 3, -267386864, -267386864);
- // this.fillGradient(x - 4, y - 3, x - 3, y + tooltipHeight + 3, -267386864, -267386864);
- // this.fillGradient(x + width + 3, y - 3, x + width + 4, y + tooltipHeight + 3, -267386864, -267386864);
- // this.fillGradient(x - 3, y - 3 + 1, x - 3 + 1, y + tooltipHeight + 3 - 1, 1347420415, 1344798847);
- // this.fillGradient(x + width + 2, y - 3 + 1, x + width + 3, y + tooltipHeight + 3 - 1, 1347420415, 1344798847);
- // this.fillGradient(x - 3, y - 3, x + width + 3, y - 3 + 1, 1347420415, 1347420415);
- // this.fillGradient(x - 3, y + tooltipHeight + 2, x + width + 3, y + tooltipHeight + 3, 1344798847, 1344798847);
- // for(int lineIndex = 0; lineIndex < lines.size(); lineIndex++) {
- // GlStateManager.disableDepthTest();
- // font.drawWithShadow(lines.get(lineIndex), x, currentY, -1);
- // GlStateManager.enableDepthTest();
- // currentY += lineIndex == 0 ? 12 : 10;
- // }
- // this.blitOffset = 0;
- // GlStateManager.enableLighting();
- // GuiLighting.enable();
- // GlStateManager.enableRescaleNormal();
- // currentY += 6;
- // }
- // List<Pair<Point, ItemStack>> pairs = Lists.newArrayList();
- // GlStateManager.pushMatrix();
- // GlStateManager.translatef(x, currentY, 1000f);
- // // new CategoryBaseWidget(new Rectangle(specWidth, specHeight)).render();
- // GlStateManager.popMatrix();
- // ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
- // int currentX = 5;
- // int currentYY = 5;
- // int i = 0;
- // for(ItemStack stack : slots) {
- // i++;
- // // minecraft.getTextureManager().bindTexture(RoughlyEnoughItemsCore.getConfigManager().getConfig().darkTheme ? SlotWidget.RECIPE_GUI_DARK : SlotWidget.RECIPE_GUI);
- // // blit(x + currentX, currentY + currentYY, 0, 222, 18, 18);
- // SlotWidget slotWidget = new SlotWidget(x + currentX + 1, currentY + currentYY + 1, stack, true, false) {
- // @Override
- // public void render(int mouseX, int mouseY, float delta) {
- // Renderer renderer = getCurrentRenderer();
- // boolean darkTheme = RoughlyEnoughItemsCore.getConfigManager().getConfig().darkTheme;
- // blitOffset = 1000;
- // minecraft.getTextureManager().bindTexture(darkTheme ? RECIPE_GUI_DARK : RECIPE_GUI);
- //// blit(this.x - 1, this.y - 1, 0, 222, 18, 18);
- // GlStateManager.pushMatrix();
- // GlStateManager.translatef(0, 0, 1000f);
- // renderer.setBlitOffset(205);
- // renderer.render(x + 8, y + 6, mouseX, mouseY, delta);
- // GlStateManager.enableDepthTest();
- // GlStateManager.popMatrix();
- // }
- // };
- // GuiLighting.disable();
- // slotWidget.render(-1, -1, client.getLastFrameDuration());
- // // GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
- // // GuiLighting.enableForItems();
- // // itemRenderer.zOffset = blitOffset + 50;
- // // itemRenderer.renderGuiItem(stack, x + currentX + 1, currentY + currentYY + 1);
- // // itemRenderer.renderGuiItemOverlay(font, stack, x + currentX + 1, currentY + currentYY + 1);
- // // itemRenderer.zOffset = 0;
- // // GlStateManager.enableDepthTest();
- // currentX += 18;
- // if (i > 9) {
- // i = 1;
- // currentX = 5;
- // currentYY += 18;
- // }
- // }
- // this.blitOffset = 0;
- // }, width, height, 0);
- // };
}
public void setRenderer(RecipeCategory category, Renderer renderable, String categoryName, boolean selected) {
- slots.clear();
if (renderable == null) {
shown = false;
this.renderer = null;
} else {
shown = true;
this.renderer = renderable;
- this.slots.addAll(RoughlyEnoughItemsCore.getRecipeHelper().getWorkingStations(category.getIdentifier()));
}
this.category = category;
this.selected = selected;
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
index ce60a55a9..3815b35b9 100644
--- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
+++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
@@ -235,13 +235,13 @@ public class DefaultPlugin implements REIPluginEntry {
@Override
public void registerOthers(RecipeHelper recipeHelper) {
- recipeHelper.registerWorkingStations(CRAFTING, Items.CRAFTING_TABLE.getDefaultStack(), Items.CAKE.getDefaultStack());
- recipeHelper.registerWorkingStations(SMELTING, Items.FURNACE.getDefaultStack());
- recipeHelper.registerWorkingStations(SMOKING, Items.SMOKER.getDefaultStack());
- recipeHelper.registerWorkingStations(BLASTING, Items.BLAST_FURNACE.getDefaultStack());
- recipeHelper.registerWorkingStations(CAMPFIRE, Items.CAMPFIRE.getDefaultStack());
- recipeHelper.registerWorkingStations(BREWING, Items.BREWING_STAND.getDefaultStack());
- recipeHelper.registerWorkingStations(STONE_CUTTING, Items.STONECUTTER.getDefaultStack());
+ recipeHelper.registerWorkingStations(CRAFTING, new ItemStack(Items.CRAFTING_TABLE));
+ recipeHelper.registerWorkingStations(SMELTING, new ItemStack(Items.FURNACE));
+ recipeHelper.registerWorkingStations(SMOKING, new ItemStack(Items.SMOKER));
+ recipeHelper.registerWorkingStations(BLASTING, new ItemStack(Items.BLAST_FURNACE));
+ recipeHelper.registerWorkingStations(CAMPFIRE, new ItemStack(Items.CAMPFIRE));
+ recipeHelper.registerWorkingStations(BREWING, new ItemStack(Items.BREWING_STAND));
+ recipeHelper.registerWorkingStations(STONE_CUTTING, new ItemStack(Items.STONECUTTER));
recipeHelper.registerRecipeVisibilityHandler(new DisplayVisibilityHandler() {
@Override
public DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display) {
diff --git a/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/src/main/resources/assets/roughlyenoughitems/lang/en_us.json
index d8eba374b..a07adbd33 100755
--- a/src/main/resources/assets/roughlyenoughitems/lang/en_us.json
+++ b/src/main/resources/assets/roughlyenoughitems/lang/en_us.json
@@ -100,6 +100,7 @@
"text.rei.config.recipe_screen_type.original": "Original",
"text.rei.config.recipe_screen_type.villager": "Villager",
"text.rei.select": "Select",
+ "text.rei.working_station": "Working Station",
"text.rei.recipe_id": "\n%sRecipe Id: %s",
"text.rei.config.register_in_other_thread": "Register Recipes in other thread:",
"text.rei.recipe_screen_type.selection": "Recipe Screen Type Selection",