|
@@ -1,5 +1,6 @@
|
|
package me.shedaniel.gui;
|
|
package me.shedaniel.gui;
|
|
|
|
|
|
|
|
+import com.mojang.blaze3d.platform.GlStateManager;
|
|
import me.shedaniel.api.IDisplayCategory;
|
|
import me.shedaniel.api.IDisplayCategory;
|
|
import me.shedaniel.api.IRecipe;
|
|
import me.shedaniel.api.IRecipe;
|
|
import me.shedaniel.gui.widget.Button;
|
|
import me.shedaniel.gui.widget.Button;
|
|
@@ -7,14 +8,13 @@ import me.shedaniel.gui.widget.Control;
|
|
import me.shedaniel.gui.widget.REISlot;
|
|
import me.shedaniel.gui.widget.REISlot;
|
|
import me.shedaniel.gui.widget.Tab;
|
|
import me.shedaniel.gui.widget.Tab;
|
|
import me.shedaniel.impl.REIRecipeManager;
|
|
import me.shedaniel.impl.REIRecipeManager;
|
|
-import net.minecraft.client.MainWindow;
|
|
|
|
-import net.minecraft.client.Minecraft;
|
|
|
|
-import net.minecraft.client.gui.GuiScreen;
|
|
|
|
-import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
-import net.minecraft.client.renderer.GlStateManager;
|
|
|
|
-import net.minecraft.client.renderer.RenderHelper;
|
|
|
|
-import net.minecraft.inventory.Container;
|
|
|
|
-import net.minecraft.util.ResourceLocation;
|
|
|
|
|
|
+import net.minecraft.client.MinecraftClient;
|
|
|
|
+import net.minecraft.client.gui.ContainerGui;
|
|
|
|
+import net.minecraft.client.gui.Gui;
|
|
|
|
+import net.minecraft.client.render.GuiLighting;
|
|
|
|
+import net.minecraft.client.util.Window;
|
|
|
|
+import net.minecraft.container.Container;
|
|
|
|
+import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.math.MathHelper;
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -22,13 +22,13 @@ import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
-public class RecipeGui extends GuiContainer {
|
|
|
|
|
|
+public class RecipeGui extends ContainerGui {
|
|
|
|
|
|
- private static final ResourceLocation CREATIVE_INVENTORY_TABS = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
|
|
|
|
- private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png");
|
|
|
|
- private final MainWindow mainWindow;
|
|
|
|
|
|
+ private static final Identifier CREATIVE_INVENTORY_TABS = new Identifier("textures/gui/container/creative_inventory/tabs.png");
|
|
|
|
+ private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
|
|
|
|
+ private final Window mainWindow;
|
|
private final Container container;
|
|
private final Container container;
|
|
- private final GuiScreen prevScreen;
|
|
|
|
|
|
+ private final Gui prevScreen;
|
|
private final Map<IDisplayCategory, List<IRecipe>> recipes;
|
|
private final Map<IDisplayCategory, List<IRecipe>> recipes;
|
|
private int guiWidth = 176;
|
|
private int guiWidth = 176;
|
|
private int guiHeight = 222;
|
|
private int guiHeight = 222;
|
|
@@ -43,15 +43,15 @@ public class RecipeGui extends GuiContainer {
|
|
private List<Tab> tabs;
|
|
private List<Tab> tabs;
|
|
private boolean tabsEnabled = false;
|
|
private boolean tabsEnabled = false;
|
|
|
|
|
|
- public RecipeGui(Container p_i1072_1_, GuiScreen prevScreen, Map<IDisplayCategory, List<IRecipe>> recipes) {
|
|
|
|
|
|
+ public RecipeGui(Container p_i1072_1_, Gui prevScreen, Map<IDisplayCategory, List<IRecipe>> recipes) {
|
|
super(new RecipeContainer());
|
|
super(new RecipeContainer());
|
|
this.container = p_i1072_1_;
|
|
this.container = p_i1072_1_;
|
|
this.prevScreen = prevScreen;
|
|
this.prevScreen = prevScreen;
|
|
this.recipes = recipes;
|
|
this.recipes = recipes;
|
|
- this.mc = Minecraft.getInstance();
|
|
|
|
- this.itemRender = mc.getItemRenderer();
|
|
|
|
- this.fontRenderer = mc.fontRenderer;
|
|
|
|
- this.mainWindow = Minecraft.getInstance().mainWindow;
|
|
|
|
|
|
+ this.client = MinecraftClient.getInstance();
|
|
|
|
+ this.itemRenderer = client.getItemRenderer();
|
|
|
|
+ this.fontRenderer = client.fontRenderer;
|
|
|
|
+ this.mainWindow = client.window;
|
|
|
|
|
|
setupCategories();
|
|
setupCategories();
|
|
}
|
|
}
|
|
@@ -71,13 +71,12 @@ public class RecipeGui extends GuiContainer {
|
|
updateRecipe();
|
|
updateRecipe();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
- public void render(int mouseX, int mouseY, float partialTicks) {
|
|
|
|
- super.render(mouseX, mouseY, partialTicks);
|
|
|
|
|
|
+ public void draw(int mouseX, int mouseY, float partialTicks) {
|
|
|
|
+ super.draw(mouseX, mouseY, partialTicks);
|
|
int y = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
|
|
int y = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
|
|
- drawCenteredString(this.fontRenderer, selectedCategory.getDisplayName(), guiLeft + guiWidth / 2, y + 11, -1);
|
|
|
|
- drawCenteredString(this.fontRenderer, String.format("%d/%d", 1 + getCurrentPage(), getTotalPages()), guiLeft + guiWidth / 2, y + 34, -1);
|
|
|
|
|
|
+ drawStringCentered(this.fontRenderer, selectedCategory.getDisplayName(), left + guiWidth / 2, y + 11, -1);
|
|
|
|
+ drawStringCentered(this.fontRenderer, String.format("%d/%d", 1 + getCurrentPage(), getTotalPages()), left + guiWidth / 2, y + 34, -1);
|
|
controls.forEach(Control::draw);
|
|
controls.forEach(Control::draw);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -86,16 +85,15 @@ public class RecipeGui extends GuiContainer {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void tick() {
|
|
|
|
- super.tick();
|
|
|
|
|
|
+ public void update() {
|
|
|
|
+ super.update();
|
|
slots.forEach(REISlot::tick);
|
|
slots.forEach(REISlot::tick);
|
|
controls.forEach(Control::tick);
|
|
controls.forEach(Control::tick);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
- public void onResize(Minecraft p_onResize_1_, int p_onResize_2_, int p_onResize_3_) {
|
|
|
|
- super.onResize(p_onResize_1_, p_onResize_2_, p_onResize_3_);
|
|
|
|
|
|
+ public void onScaleChanged(MinecraftClient p_onResize_1_, int p_onResize_2_, int p_onResize_3_) {
|
|
|
|
+ super.onScaleChanged(p_onResize_1_, p_onResize_2_, p_onResize_3_);
|
|
updateRecipe();
|
|
updateRecipe();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -111,18 +109,18 @@ public class RecipeGui extends GuiContainer {
|
|
slots.addAll(categories.get(categoryPointer).setupDisplay(1));
|
|
slots.addAll(categories.get(categoryPointer).setupDisplay(1));
|
|
}
|
|
}
|
|
|
|
|
|
- guiLeft = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2));
|
|
|
|
- guiTop = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
|
|
|
|
|
|
+ left = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2));
|
|
|
|
+ top = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
|
|
|
|
|
|
- slots.forEach(reiSlot -> reiSlot.move(guiLeft, guiTop));
|
|
|
|
|
|
+ slots.forEach(reiSlot -> reiSlot.move(left, top));
|
|
|
|
|
|
- Button btnCategoryLeft = new Button(guiLeft + 10, guiTop + 5, 15, 20, "<");
|
|
|
|
- Button btnCategoryRight = new Button(guiLeft + guiWidth - 25, guiTop + 5, 15, 20, ">");
|
|
|
|
|
|
+ Button btnCategoryLeft = new Button(left + 10, top + 5, 15, 20, "<");
|
|
|
|
+ Button btnCategoryRight = new Button(left + guiWidth - 25, top + 5, 15, 20, ">");
|
|
btnCategoryRight.onClick = this::btnCategoryRight;
|
|
btnCategoryRight.onClick = this::btnCategoryRight;
|
|
btnCategoryLeft.onClick = this::btnCategoryLeft;
|
|
btnCategoryLeft.onClick = this::btnCategoryLeft;
|
|
|
|
|
|
- Button btnRecipeLeft = new Button(guiLeft + 10, guiTop + 28, 15, 20, "<");
|
|
|
|
- Button btnRecipeRight = new Button(guiLeft + guiWidth - 25, guiTop + 28, 15, 20, ">");
|
|
|
|
|
|
+ Button btnRecipeLeft = new Button(left + 10, top + 28, 15, 20, "<");
|
|
|
|
+ Button btnRecipeRight = new Button(left + guiWidth - 25, top + 28, 15, 20, ">");
|
|
btnRecipeLeft.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && recipePointer > 0);
|
|
btnRecipeLeft.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && recipePointer > 0);
|
|
btnRecipeRight.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && getCurrentPage() + 1 < getTotalPages());
|
|
btnRecipeRight.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && getCurrentPage() + 1 < getTotalPages());
|
|
btnRecipeRight.onClick = this::btnRecipeRight;
|
|
btnRecipeRight.onClick = this::btnRecipeRight;
|
|
@@ -148,16 +146,16 @@ public class RecipeGui extends GuiContainer {
|
|
categories.get(categoryPointer).addWidget(newControls, 0);
|
|
categories.get(categoryPointer).addWidget(newControls, 0);
|
|
if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2)
|
|
if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2)
|
|
categories.get(categoryPointer).addWidget(newControls, 1);
|
|
categories.get(categoryPointer).addWidget(newControls, 1);
|
|
- newControls.forEach(f -> f.move(guiLeft, guiTop));
|
|
|
|
|
|
+ newControls.forEach(f -> f.move(left, top));
|
|
controls.addAll(newControls);
|
|
controls.addAll(newControls);
|
|
|
|
|
|
updateTabs();
|
|
updateTabs();
|
|
}
|
|
}
|
|
|
|
|
|
private void updateTabs() {
|
|
private void updateTabs() {
|
|
- tabsEnabled = guiTop - 28 > 4;
|
|
|
|
|
|
+ tabsEnabled = top - 28 > 4;
|
|
if (tabsEnabled) {
|
|
if (tabsEnabled) {
|
|
- tabs.forEach(tab -> tab.moveTo(guiLeft + 4, guiLeft + 2 + tabs.indexOf(tab) * 28, guiTop - 28));
|
|
|
|
|
|
+ tabs.forEach(tab -> tab.moveTo(left + 4, left + 2 + tabs.indexOf(tab) * 28, top - 28));
|
|
for(int i = 0; i < tabs.size(); i++) {
|
|
for(int i = 0; i < tabs.size(); i++) {
|
|
int ref = i + categoryTabPage * 6;
|
|
int ref = i + categoryTabPage * 6;
|
|
if (categories.size() > ref) {
|
|
if (categories.size() > ref) {
|
|
@@ -169,38 +167,38 @@ public class RecipeGui extends GuiContainer {
|
|
}
|
|
}
|
|
|
|
|
|
private boolean onClickTab(int index) {
|
|
private boolean onClickTab(int index) {
|
|
- System.out.println(index);
|
|
|
|
if (index + categoryTabPage * 6 == categories.indexOf(selectedCategory))
|
|
if (index + categoryTabPage * 6 == categories.indexOf(selectedCategory))
|
|
return false;
|
|
return false;
|
|
selectedCategory = categories.get(index + categoryTabPage * 6);
|
|
selectedCategory = categories.get(index + categoryTabPage * 6);
|
|
|
|
+ updateRecipe();
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected void drawGuiContainerBackgroundLayer(float v, int i, int i1) {
|
|
|
|
|
|
+ protected void drawBackground(float v, int i, int i1) {
|
|
//Tabs
|
|
//Tabs
|
|
if (tabsEnabled) {
|
|
if (tabsEnabled) {
|
|
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
- RenderHelper.enableGUIStandardItemLighting();
|
|
|
|
- this.mc.getTextureManager().bindTexture(CREATIVE_INVENTORY_TABS);
|
|
|
|
|
|
+ GuiLighting.enableForItems();
|
|
|
|
+ this.client.getTextureManager().bindTexture(CREATIVE_INVENTORY_TABS);
|
|
tabs.stream().filter(tab -> tab.getId() + categoryTabPage * 6 == categories.indexOf(selectedCategory)).forEach(Tab::drawTab);
|
|
tabs.stream().filter(tab -> tab.getId() + categoryTabPage * 6 == categories.indexOf(selectedCategory)).forEach(Tab::drawTab);
|
|
}
|
|
}
|
|
|
|
|
|
- drawDefaultBackground();
|
|
|
|
|
|
+ drawBackground();
|
|
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
- this.mc.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
|
|
|
|
|
|
+ this.client.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
|
|
|
|
|
|
int lvt_4_1_ = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2));
|
|
int lvt_4_1_ = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2));
|
|
int lvt_5_1_ = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
|
|
int lvt_5_1_ = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
|
|
|
|
|
|
- this.drawTexturedModalRect(lvt_4_1_, lvt_5_1_, 0, 0, this.guiWidth, this.guiHeight);
|
|
|
|
|
|
+ this.drawTexturedRect(lvt_4_1_, lvt_5_1_, 0, 0, this.guiWidth, this.guiHeight);
|
|
slots.forEach(REISlot::draw);
|
|
slots.forEach(REISlot::draw);
|
|
|
|
|
|
if (tabsEnabled)
|
|
if (tabsEnabled)
|
|
tabs.stream().filter(tab -> tab.getId() + categoryTabPage * 6 != categories.indexOf(selectedCategory)).forEach(tab -> {
|
|
tabs.stream().filter(tab -> tab.getId() + categoryTabPage * 6 != categories.indexOf(selectedCategory)).forEach(tab -> {
|
|
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
- RenderHelper.enableGUIStandardItemLighting();
|
|
|
|
- this.mc.getTextureManager().bindTexture(CREATIVE_INVENTORY_TABS);
|
|
|
|
|
|
+ GuiLighting.enableForItems();
|
|
|
|
+ this.client.getTextureManager().bindTexture(CREATIVE_INVENTORY_TABS);
|
|
tab.drawTab();
|
|
tab.drawTab();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -208,18 +206,13 @@ public class RecipeGui extends GuiContainer {
|
|
@Override
|
|
@Override
|
|
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
|
|
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
|
|
if (p_keyPressed_1_ == 259 && prevScreen != null && REIRenderHelper.focusedControl == null) {
|
|
if (p_keyPressed_1_ == 259 && prevScreen != null && REIRenderHelper.focusedControl == null) {
|
|
- Minecraft.getInstance().displayGuiScreen(prevScreen);
|
|
|
|
|
|
+ this.client.openGui(prevScreen);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_);
|
|
return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_);
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public void onGuiClosed() {
|
|
|
|
- super.onGuiClosed();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private boolean btnCategoryLeft(int button) {
|
|
private boolean btnCategoryLeft(int button) {
|
|
recipePointer = 0;
|
|
recipePointer = 0;
|
|
int categoryPointer = categories.indexOf(selectedCategory);
|
|
int categoryPointer = categories.indexOf(selectedCategory);
|