diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2018-12-31 13:12:25 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2018-12-31 13:12:25 +0800 |
| commit | fee12aa0885da204ec874cd5ada371c42501c873 (patch) | |
| tree | 880596f5f463e08762a56b1cb1d7008aaed1899d /src/main/java/me/shedaniel/gui/RecipeGui.java | |
| parent | 1b14c5142bb49db9af078b5c753bc22ce35a40cc (diff) | |
| download | RoughlyEnoughItems-fee12aa0885da204ec874cd5ada371c42501c873.tar.gz RoughlyEnoughItems-fee12aa0885da204ec874cd5ada371c42501c873.tar.bz2 RoughlyEnoughItems-fee12aa0885da204ec874cd5ada371c42501c873.zip | |
packetadder wip
Diffstat (limited to 'src/main/java/me/shedaniel/gui/RecipeGui.java')
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/RecipeGui.java | 99 |
1 files changed, 46 insertions, 53 deletions
diff --git a/src/main/java/me/shedaniel/gui/RecipeGui.java b/src/main/java/me/shedaniel/gui/RecipeGui.java index 43cb8333d..d4f3db8f0 100755 --- a/src/main/java/me/shedaniel/gui/RecipeGui.java +++ b/src/main/java/me/shedaniel/gui/RecipeGui.java @@ -1,5 +1,6 @@ package me.shedaniel.gui; +import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.api.IDisplayCategory; import me.shedaniel.api.IRecipe; 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.Tab; 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 java.util.ArrayList; @@ -22,13 +22,13 @@ import java.util.LinkedList; import java.util.List; 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 GuiScreen prevScreen; + private final Gui prevScreen; private final Map<IDisplayCategory, List<IRecipe>> recipes; private int guiWidth = 176; private int guiHeight = 222; @@ -43,15 +43,15 @@ public class RecipeGui extends GuiContainer { private List<Tab> tabs; 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()); this.container = p_i1072_1_; this.prevScreen = prevScreen; 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(); } @@ -71,13 +71,12 @@ public class RecipeGui extends GuiContainer { updateRecipe(); } - @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)); - 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); } @@ -86,16 +85,15 @@ public class RecipeGui extends GuiContainer { } @Override - public void tick() { - super.tick(); + public void update() { + super.update(); slots.forEach(REISlot::tick); controls.forEach(Control::tick); } - @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(); } @@ -111,18 +109,18 @@ public class RecipeGui extends GuiContainer { 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; 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); btnRecipeRight.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && getCurrentPage() + 1 < getTotalPages()); btnRecipeRight.onClick = this::btnRecipeRight; @@ -148,16 +146,16 @@ public class RecipeGui extends GuiContainer { categories.get(categoryPointer).addWidget(newControls, 0); if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) categories.get(categoryPointer).addWidget(newControls, 1); - newControls.forEach(f -> f.move(guiLeft, guiTop)); + newControls.forEach(f -> f.move(left, top)); controls.addAll(newControls); updateTabs(); } private void updateTabs() { - tabsEnabled = guiTop - 28 > 4; + tabsEnabled = top - 28 > 4; 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++) { int ref = i + categoryTabPage * 6; if (categories.size() > ref) { @@ -169,38 +167,38 @@ public class RecipeGui extends GuiContainer { } private boolean onClickTab(int index) { - System.out.println(index); if (index + categoryTabPage * 6 == categories.indexOf(selectedCategory)) return false; selectedCategory = categories.get(index + categoryTabPage * 6); + updateRecipe(); return false; } @Override - protected void drawGuiContainerBackgroundLayer(float v, int i, int i1) { + protected void drawBackground(float v, int i, int i1) { //Tabs if (tabsEnabled) { 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); } - drawDefaultBackground(); + drawBackground(); 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_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); if (tabsEnabled) tabs.stream().filter(tab -> tab.getId() + categoryTabPage * 6 != categories.indexOf(selectedCategory)).forEach(tab -> { 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(); }); } @@ -208,18 +206,13 @@ public class RecipeGui extends GuiContainer { @Override 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) { - Minecraft.getInstance().displayGuiScreen(prevScreen); + this.client.openGui(prevScreen); return true; } return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); } - @Override - public void onGuiClosed() { - super.onGuiClosed(); - } - private boolean btnCategoryLeft(int button) { recipePointer = 0; int categoryPointer = categories.indexOf(selectedCategory); |
