diff options
| author | Moulberry <james.jenour@student.scotch.wa.edu.au> | 2020-07-17 05:57:11 +0800 |
|---|---|---|
| committer | Moulberry <james.jenour@student.scotch.wa.edu.au> | 2020-07-17 05:57:11 +0800 |
| commit | f7d3491def0f7498d7bf0d547445f75f0c515912 (patch) | |
| tree | 7aa7cea0da7cdca2fdea55fffcbf746d22734b1c | |
| parent | f90f0b2f1f234d08742a4f0dd8afcd4b80e26d05 (diff) | |
| download | NotEnoughUpdates-1.5-REL.tar.gz NotEnoughUpdates-1.5-REL.tar.bz2 NotEnoughUpdates-1.5-REL.zip | |
REL-1.0.0REL-1.0.01.5-REL(2)1.5-REL
37 files changed, 2506 insertions, 1086 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java index 613ebe5f..200569df 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java @@ -1,89 +1,241 @@ package io.github.moulberry.notenoughupdates; import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.util.TexLoc; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiCrafting; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.I18n; import net.minecraft.inventory.ContainerWorkbench; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; +import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.vector.Vector2f; +import org.lwjgl.util.vector.Vector3f; -public class GuiItemRecipe extends GuiCrafting { +import java.awt.*; +import java.io.IOException; +import java.util.List; - private ItemStack[] craftMatrix; - private JsonObject result; - private String text; - private String craftText = ""; +public class GuiItemRecipe extends GuiScreen { + + private static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation("textures/gui/container/crafting_table.png"); + + private List<ItemStack[]> craftMatrices; + private List<JsonObject> results; + private int currentIndex = 0; + + private String title; private NEUManager manager; - public GuiItemRecipe(ItemStack[] craftMatrix, JsonObject result, String text, NEUManager manager) { - super(Minecraft.getMinecraft().thePlayer.inventory, Minecraft.getMinecraft().theWorld); - this.craftMatrix = craftMatrix; - this.result = result; - this.text = text; + private int guiLeft = 0; + private int guiTop = 0; + private int xSize = 176; + private int ySize = 166; + + public GuiItemRecipe(String title, List<ItemStack[]> craftMatrices, List<JsonObject> results, NEUManager manager) { + this.craftMatrices = craftMatrices; + this.results = results; this.manager = manager; + this.title = title; + } - setContents(); + private String getCraftText() { + if(results.get(currentIndex).has("crafttext")) { + return results.get(currentIndex).get("crafttext").getAsString(); + } else { + return ""; + } } - public void setContents() { - ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; - for(int i=0; i<Math.min(craftMatrix.length, 9); i++) { - if(craftMatrix[i] == null) continue; - cw.craftMatrix.setInventorySlotContents(i, craftMatrix[i]); + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + + if(currentIndex < 0) { + currentIndex = 0; + } else if(currentIndex >= craftMatrices.size()) { + currentIndex = craftMatrices.size()-1; } - if(result.has("crafttext")) { - craftText = result.get("crafttext").getAsString(); + + FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; + + this.guiLeft = (width - this.xSize) / 2; + this.guiTop = (height - this.ySize) / 2; + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(craftingTableGuiTextures); + this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); + + List<String> tooltipToRender = null; + for(int index=0; index <= 45; index++) { + Vector2f pos = getPositionForIndex(index); + Utils.drawItemStack(getStackForIndex(index), (int)pos.x, (int)pos.y); + + if(mouseX > pos.x && mouseX < pos.x+16) { + if(mouseY > pos.y && mouseY < pos.y+16) { + ItemStack stack = getStackForIndex(index); + if(stack != null) { + tooltipToRender = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + } + } } - cw.craftResult.setInventorySlotContents(0, manager.jsonToStack(result)); - } - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - setContents(); + if(craftMatrices.size() > 1) { + int guiX = mouseX - guiLeft; + int guiY = mouseY - guiTop; + + int buttonWidth = 7; + int buttonHeight = 11; + + boolean leftSelected = false; + boolean rightSelected = false; + + if(guiY > + 63 && guiY < + 63 + buttonHeight) { + if(guiX > + 110 && guiX < 110 + buttonWidth) { + leftSelected = true; + } else if(guiX > 147 && guiX < 147 + buttonWidth) { + rightSelected = true; + } + } - String t = text.equals("") ? I18n.format("container.crafting", new Object[0]) : text; + Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture); + //Left arrow + Utils.drawTexturedRect(guiLeft+110, guiTop+63, 7, 11, 34/256f, 48/256f, + 5/256f + (leftSelected ? 32/256f : 0), 27/256f + (leftSelected ? 32/256f : 0)); + //Right arrow + Utils.drawTexturedRect(guiLeft+147, guiTop+63, 7, 11, 10/256f, 24/256f, + 5/256f + (rightSelected ? 32/256f : 0), 27/256f + (rightSelected ? 32/256f : 0)); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); - Utils.drawStringScaledMaxWidth(t, fontRendererObj, 28, 6, t.contains("\u00a7"), xSize-38, 4210752); - this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); + String str = (currentIndex+1)+"/"+craftMatrices.size(); + Utils.drawStringCenteredScaledMaxWidth(str, fontRendererObj, guiLeft+132, guiTop+69, + false, 24, Color.BLACK.getRGB()); + } - Utils.drawStringCenteredScaledMaxWidth(craftText, fontRendererObj, 132, 25, + Utils.drawStringCenteredScaledMaxWidth(getCraftText(), fontRendererObj, guiLeft+132, guiTop+25, false, 75, 4210752); + + Utils.drawStringScaledMaxWidth(title, fontRendererObj, guiLeft+28, guiTop+6, title.contains("\u00a7"), xSize-38, 4210752); + + if(tooltipToRender != null) { + Utils.drawHoveringText(tooltipToRender, mouseX, mouseY, width, height, -1, fontRendererObj); + } } - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + public ItemStack getStackForIndex(int index) { + if(index == 0) { + return manager.jsonToStack(results.get(currentIndex)); + } else if(index >= 1 && index <= 9) { + return craftMatrices.get(currentIndex)[index-1]; + } else { + return Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(index-10); + } } - protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - ItemStack click = null; - if(slotId >= 1 && slotId <= 9) { - click = craftMatrix[slotId-1]; - } else if(slotId == 0) { - ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; - click = cw.craftResult.getStackInSlot(0); + public Vector2f getPositionForIndex(int index) { + //0 = result + //1-9 = craft matrix + //10-18 = hotbar + //19-45 = player inv + + if(index == 0) { + return new Vector2f(guiLeft+124, guiTop+35); + } else if(index >= 1 && index <= 9) { + index -= 1; + int x = index % 3; + int y = index / 3; + return new Vector2f(guiLeft+30 + x*18, guiTop+17 + y * 18); + } else if(index >= 10 && index <= 18) { + index -= 10; + return new Vector2f(guiLeft+8 + index*18, guiTop+142); + } else if(index >= 19 && index <= 45) { + index -= 19; + int x = index % 9; + int y = index / 9; + return new Vector2f(guiLeft+8 + x*18, guiTop+84 + y*18); } - if(click != null) { - if(clickedButton == 0) { - manager.displayGuiItemRecipe(manager.getInternalNameForItem(click), ""); - } else if(clickedButton == 1) { - manager.displayGuiItemUsages(manager.getInternalNameForItem(click), ""); + return null; + } + + @Override + public void handleKeyboardInput() throws IOException { + super.handleKeyboardInput(); //TODO: r and u + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter()+256 : Keyboard.getEventKey(); + + for(int index=0; index <= 45; index++) { + Vector2f pos = getPositionForIndex(index); + if(mouseX > pos.x && mouseX < pos.x+16) { + if(mouseY > pos.y && mouseY < pos.y+16) { + ItemStack stack = getStackForIndex(index); + if(stack != null) { + if(keyPressed == manager.keybindViewRecipe.getKeyCode()) { + manager.displayGuiItemRecipe(manager.getInternalNameForItem(stack), ""); + } else if(keyPressed == manager.keybindViewUsages.getKeyCode()) { + manager.displayGuiItemUsages(manager.getInternalNameForItem(stack)); + } + } + return; + } } } } - /*public void handleMouseInput() throws IOException { - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int height = scaledresolution.getScaledHeight(); + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + + int guiX = mouseX - guiLeft; + int guiY = mouseY - guiTop; - int mouseX = Mouse.getX() / scaledresolution.getScaleFactor(); - int mouseY = height - Mouse.getY() / scaledresolution.getScaleFactor(); - if(mouseY > this.guiTop + this.ySize - 94 || mouseY < this.guiTop || - mouseX < this.guiLeft || mouseX > this.guiLeft+this.xSize) { - //Potentially allow mouse input in the future. For now this is still broken. - //super.handleMouseInput(); + int buttonWidth = 7; + int buttonHeight = 11; + + if(guiY > + 63 && guiY < + 63 + buttonHeight) { + if(guiX > + 110 && guiX < 110 + buttonWidth) { + currentIndex--; + Utils.playPressSound(); + return; + } else if(guiX > 147 && guiX < 147 + buttonWidth) { + currentIndex++; + Utils.playPressSound(); + return; + } } - }*/ - public void onCraftMatrixChanged(IInventory inventoryIn){} + for(int index=0; index <= 45; index++) { + Vector2f pos = getPositionForIndex(index); + if(mouseX > pos.x && mouseX < pos.x+16) { + if(mouseY > pos.y && mouseY < pos.y+16) { + ItemStack stack = getStackForIndex(index); + if(stack != null) { + if(mouseButton == 0) { + manager.displayGuiItemRecipe(manager.getInternalNameForItem(stack), ""); + } else if(mouseButton == 1) { + manager.displayGuiItemUsages(manager.getInternalNameForItem(stack)); + } + } + return; + } + } + } + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java deleted file mode 100644 index a56293e9..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java +++ /dev/null @@ -1,170 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.util.TexLoc; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiCrafting; -import net.minecraft.client.resources.I18n; -import net.minecraft.inventory.ContainerWorkbench; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; - -import java.awt.*; -import java.io.IOException; -import java.util.List; - -public class GuiItemUsages extends GuiCrafting { - private static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); - - private List<ItemStack[]> craftMatrices; - private List<JsonObject> results; - private int currentIndex = 0; - - private String text; - private String craftText = ""; - private String collectionText = ""; - private NEUManager manager; - - private TexLoc left = new TexLoc(0, 0, Keyboard.KEY_N); - private TexLoc right = new TexLoc(0, 0, Keyboard.KEY_M); - - public GuiItemUsages(List<ItemStack[]> craftMatrices, List<JsonObject> results, String text, NEUManager manager) { - super(Minecraft.getMinecraft().thePlayer.inventory, Minecraft.getMinecraft().theWorld); - - this.craftMatrices = craftMatrices; - this.results = results; - this.text = text; - this.manager = manager; - - setIndex(0); - } - - private void setIndex(int index) { - if(index < 0 || index >= craftMatrices.size()) { - return; - } else { - currentIndex = index; - - ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; - for(int i=0; i<Math.min(craftMatrices.get(currentIndex).length, 9); i++) { - cw.craftMatrix.setInventorySlotContents(i, craftMatrices.get(currentIndex)[i]); - } - if(results.get(currentIndex).has("crafttext")) { - craftText = results.get(currentIndex).get("crafttext").getAsString(); - } else { - craftText = ""; - } - cw.craftResult.setInventorySlotContents(0, manager.jsonToStack(results.get(currentIndex))); - } - } - - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - String t = "Crafting Usages"; - - setIndex(currentIndex); - - int guiX = mouseX - guiLeft; - int guiY = mouseY - guiTop; - - int buttonWidth = 7; - int buttonHeight = 11; - - boolean leftSelected = false; - boolean rightSelected = false; - - if(guiY > + 63 && guiY < + 63 + buttonHeight) { - if(guiX > + 110 && guiX < 110 + buttonWidth) { - leftSelected = true; - } else if(guiX > 147 && guiX < 147 + buttonWidth) { - rightSelected = true; - } - } - - Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture); - //Left arrow - Utils.drawTexturedRect(110, 63, 7, 11, 34/256f, 48/256f, - 5/256f + (leftSelected ? 32/256f : 0), 27/256f + (leftSelected ? 32/256f : 0)); - //Right arrow - Utils.drawTexturedRect(147, 63, 7, 11, 10/256f, 24/256f, - 5/256f + (rightSelected ? 32/256f : 0), 27/256f + (rightSelected ? 32/256f : 0)); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); - - String str = (currentIndex+1)+"/"+craftMatrices.size(); - Utils.drawStringCenteredScaledMaxWidth(str, fontRendererObj, 132, 69, - false, 24, Color.BLACK.getRGB()); - - - Utils.drawStringCenteredScaledMaxWidth(craftText, fontRendererObj, 132, 25, - false, 75, 4210752); - - - Utils.drawStringScaledMaxWidth(t, fontRendererObj, 28, 6, t.contains("\u00a7"), xSize-38, 4210752); - this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); - } - - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - } - - @Override - public void handleKeyboardInput() throws IOException { - super.handleKeyboardInput(); //TODO: r and u - left.handleKeyboardInput(); - right.handleKeyboardInput(); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - super.mouseClicked(mouseX, mouseY, mouseButton); - - int guiX = mouseX - guiLeft; - int guiY = mouseY - guiTop; - - int buttonWidth = 7; - int buttonHeight = 11; - - if(guiY > + 63 && guiY < + 63 + buttonHeight) { - if(guiX > + 110 && guiX < 110 + buttonWidth) { - setIndex(currentIndex-1); - } else if(guiX > 147 && guiX < 147 + buttonWidth) { - setIndex(currentIndex+1); - } - } - } - - protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - ItemStack click = null; - if(slotId >= 1 && slotId <= 9) { - click = craftMatrices.get(currentIndex)[slotId-1]; - } else if(slotId == 0) { - ContainerWorkbench cw = (ContainerWorkbench) this.inventorySlots; - click = cw.craftResult.getStackInSlot(0); - } - if(click != null) { - if(clickedButton == 0) { - manager.displayGuiItemRecipe(manager.getInternalNameForItem(click), ""); - } else if(clickedButton == 1) { - manager.displayGuiItemUsages(manager.getInternalNameForItem(click), ""); - } - } - } - - /*public void handleMouseInput() throws IOException { - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int height = scaledresolution.getScaledHeight(); - - int mouseX = Mouse.getX() / scaledresolution.getScaleFactor(); - int mouseY = height - Mouse.getY() / scaledresolution.getScaleFactor(); - if(mouseY > this.guiTop + this.ySize - 94 || mouseY < this.guiTop || - mouseX < this.guiLeft || mouseX > this.guiLeft+this.xSize) { - //Potentially allow mouse input in the future. For now this is still broken. - //super.handleMouseInput(); - } - }*/ - - public void onCraftMatrixChanged(IInventory inventoryIn){} -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java index 573e20cf..1f87018b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java @@ -22,6 +22,9 @@ public class GuiTextures { public static final ResourceLocation slider_button = new ResourceLocation("notenoughupdates:slider_button.png"); public static final ResourceLocation item_mask = new ResourceLocation("notenoughupdates:item_mask.png"); + public static final ResourceLocation button_tex = new ResourceLocation("notenoughupdates:button.png"); + + public static final ResourceLocation dungeon_chest_worth = new ResourceLocation("notenoughupdates:dungeon_chest_worth.png"); public static final ResourceLocation auction_view = new ResourceLocation("notenoughupdates:auction_view.png"); public static final ResourceLocation auction_accept = new ResourceLocation("notenoughupdates:auction_accept.png"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java index d2190425..b9f086a4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUIO.java @@ -74,13 +74,10 @@ public class NEUIO { GHRepository repo = github.getRepositoryById("247692460"); for(GHTreeEntry treeEntry : repo.getTreeRecursive("master", 1).getTree()) { - if(treeEntry.getPath().startsWith("items/")) { - String[] split = treeEntry.getPath().split("/"); - String name = split[split.length-1]; - - String oldSha = oldShas.get(name); + if(treeEntry.getPath().contains(".")) { + String oldSha = oldShas.get(treeEntry.getPath()); if(!treeEntry.getSha().equals(oldSha)) { - changedFiles.put(name, treeEntry.getSha()); + changedFiles.put(treeEntry.getPath(), treeEntry.getSha()); } } } @@ -109,22 +106,4 @@ public class NEUIO { removedItems.removeAll(repoItems); return removedItems; } - - /** - * Takes set of filename (eg. BOW.json) and returns map from that filename to the individual download link. - */ - public Map<String, String> getItemsDownload(Set<String> filename) { - HashMap<String, String> downloadUrls = new HashMap<>(); - try { - GitHub github = new GitHubBuilder().withOAuthToken(accessToken).build(); - GHRepository repo = github.getRepositoryById("247692460"); - - for(GHContent content : repo.getDirectoryContent("items")) { - if(filename.contains(content.getName())) { - downloadUrls.put(content.getName(), content.getDownloadUrl()); - } - } - } catch(IOException e) { } - return downloadUrls; - } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 77d3be7f..8d625c14 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -1,14 +1,15 @@ package io.github.moulberry.notenoughupdates; +import com.google.common.collect.Lists; import com.google.gson.*; -import io.github |
