diff options
| author | unknown <james.jenour@protonmail.com> | 2020-05-31 01:59:47 +1000 |
|---|---|---|
| committer | unknown <james.jenour@protonmail.com> | 2020-05-31 01:59:47 +1000 |
| commit | de97f55968d183cc7d76aad87e3b27d382bfdbc9 (patch) | |
| tree | eab5e7769069f31b79016e3702855ebb9f614a8e /src/main/java | |
| download | NotEnoughUpdates-de97f55968d183cc7d76aad87e3b27d382bfdbc9.tar.gz NotEnoughUpdates-de97f55968d183cc7d76aad87e3b27d382bfdbc9.tar.bz2 NotEnoughUpdates-de97f55968d183cc7d76aad87e3b27d382bfdbc9.zip | |
1.5BETA-1.6
Diffstat (limited to 'src/main/java')
34 files changed, 7583 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/AllowEmptyHTMLTag.java b/src/main/java/io/github/moulberry/notenoughupdates/AllowEmptyHTMLTag.java new file mode 100644 index 00000000..3cf5ef31 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/AllowEmptyHTMLTag.java @@ -0,0 +1,74 @@ +package io.github.moulberry.notenoughupdates; + +import info.bliki.htmlcleaner.TagNode; +import info.bliki.wiki.filter.ITextConverter; +import info.bliki.wiki.model.IWikiModel; +import info.bliki.wiki.tags.HTMLTag; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class AllowEmptyHTMLTag extends HTMLTag { + public AllowEmptyHTMLTag(String name) { + super(name); + } + + public void renderHTML(ITextConverter converter, Appendable buf, IWikiModel model) throws IOException { + boolean newLinesAfterTag = false; + boolean newLinesAfterChildren = false; + TagNode node = this; + String name = node.getName(); + List<Object> children = node.getChildren(); + + if (NEW_LINES) { + switch (name) { + case "div": + case "p": + case "li": + case "td": + buf.append('\n'); + break; + case "table": + case "ul": + case "ol": + case "th": + case "tr": + buf.append('\n'); + newLinesAfterTag = true; + newLinesAfterChildren = true; + break; + case "pre": + buf.append('\n'); + newLinesAfterTag = false; + newLinesAfterChildren = true; + break; + case "blockquote": + newLinesAfterChildren = true; + break; + } + } + buf.append('<'); + buf.append(name); + + Map<String, String> tagAtttributes = node.getAttributes(); + + appendAttributes(buf, tagAtttributes); + + if (children.size() == 0) { + buf.append(" />"); + } else { + buf.append('>'); + if (newLinesAfterTag) { + buf.append('\n'); + } + converter.nodesToText(children, buf, model); + if (newLinesAfterChildren) { + buf.append('\n'); + } + buf.append("</"); + buf.append(node.getName()); + buf.append('>'); + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/CustomRenderItem.java b/src/main/java/io/github/moulberry/notenoughupdates/CustomRenderItem.java new file mode 100644 index 00000000..bf194e33 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/CustomRenderItem.java @@ -0,0 +1,167 @@ +package io.github.moulberry.notenoughupdates; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Vec3i; + +import java.lang.reflect.Method; +import java.util.List; + +public class CustomRenderItem { + + public static void renderItemIntoGUI(RenderItem renderItem, ItemStack stack, int x, int y, boolean effect) { + IBakedModel ibakedmodel = renderItem.getItemModelMesher().getItemModel(stack); + GlStateManager.pushMatrix(); + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture).setBlurMipmap(false, false); + GlStateManager.enableRescaleNormal(); + GlStateManager.enableAlpha(); + GlStateManager.alphaFunc(516, 0.1F); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(770, 771); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + setupGuiTransform(x, y, ibakedmodel.isGui3d()); + ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel, ItemCameraTransforms.TransformType.GUI); + renderItem(renderItem, stack, ibakedmodel, effect); + GlStateManager.disableAlpha(); + GlStateManager.disableRescaleNormal(); + GlStateManager.disableLighting(); + GlStateManager.popMatrix(); + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture).restoreLastBlurMipmap(); + } + + private static void setupGuiTransform(int xPosition, int yPosition, boolean isGui3d) { + GlStateManager.translate((float)xPosition, (float)yPosition, 0); + GlStateManager.translate(8.0F, 8.0F, 0.0F); + GlStateManager.scale(1.0F, 1.0F, -1.0F); + GlStateManager.scale(0.5F, 0.5F, 0.5F); + + if (isGui3d) { + GlStateManager.scale(40.0F, 40.0F, 40.0F); + GlStateManager.rotate(210.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.enableLighting(); + } else { + GlStateManager.scale(64.0F, 64.0F, 64.0F); + GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.disableLighting(); + } + } + + public static void renderItem(RenderItem renderItem, ItemStack stack, IBakedModel model, boolean effect) { + if (stack != null) { + GlStateManager.pushMatrix(); + GlStateManager.scale(0.5F, 0.5F, 0.5F); + + if (model.isBuiltInRenderer()) { + GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.translate(-0.5F, -0.5F, -0.5F); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.enableRescaleNormal(); + TileEntityItemStackRenderer.instance.renderByItem(stack); + } else { + GlStateManager.translate(-0.5F, -0.5F, -0.5F); + Class<?>[] paramsRM = new Class[]{IBakedModel.class, ItemStack.class}; + Method renderModelMethod = Utils.getMethod(RenderItem.class, paramsRM, + "renderModel", "func_175036_a"); + if(renderModelMethod != null) { + renderModelMethod.setAccessible(true); + try { + renderModelMethod.invoke(renderItem, model, stack); + } catch(Exception e) {} + } + + if (stack.hasEffect() && effect) { + Class<?>[] paramsRE = new Class[]{IBakedModel.class}; + Method renderEffectMethod = Utils.getMethod(RenderItem.class, paramsRE, + "renderEffect", "func_180451_a"); + if(renderEffectMethod != null) { + renderEffectMethod.setAccessible(true); + try { + renderEffectMethod.invoke(renderItem, model); + } catch(Exception e) {} + } + } + } + + GlStateManager.popMatrix(); + } + } + + /*private static void renderModel(IBakedModel model, ItemStack stack) + { + renderModel(model, -1, stack); + } + + private static void renderModel(IBakedModel model, int color) + { + renderModel(model, color, (ItemStack)null); + } + + private static void renderModel(IBakedModel model, int color, ItemStack stack) + { + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.ITEM); + + for (EnumFacing enumfacing : EnumFacing.values()) + { + renderQuads(worldrenderer, model.getFaceQuads(enumfacing), color, stack); + } + + renderQuads(worldrenderer, model.getGeneralQuads(), color, stack); + tessellator.draw(); + } + + private static void putQuadNormal(WorldRenderer renderer, BakedQuad quad) + { + Vec3i vec3i = quad.getFace().getDirectionVec(); + renderer.putNormal((float)vec3i.getX(), (float)vec3i.getY(), (float)vec3i.getZ()); + } + + private static void renderQuad(WorldRenderer renderer, BakedQuad quad, int color) + { + renderer.addVertexData(quad.getVertexData()); + renderer.putColor4(color); + putQuadNormal(renderer, quad); + } + + private static void renderQuads(WorldRenderer renderer, List<BakedQuad> quads, int color, ItemStack stack) + { + boolean flag = color == -1 && stack != null; + int i = 0; + + for (int j = quads.size(); i < j; ++i) + { + BakedQuad bakedquad = (BakedQuad)quads.get(i); + int k = color; + + if (flag && bakedquad.hasTintIndex()) + { + k = stack.getItem().getColorFromItemStack(stack, bakedquad.getTintIndex()); + + if (EntityRenderer.anaglyphEnable) + { + k = TextureUtil.anaglyphColor(k); + } + + k = k | -16777216; + } + + net.minecraftforge.client.model.pipeline.LightUtil.renderQuadColor(renderer, bakedquad, k); + } + }*/ + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java new file mode 100644 index 00000000..6916372b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java @@ -0,0 +1,80 @@ +package io.github.moulberry.notenoughupdates; + +import com.google.gson.JsonObject; +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; + +public class GuiItemRecipe extends GuiCrafting { + + private ItemStack[] craftMatrix; + private String text; + private String craftText = ""; + 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.text = text; + this.manager = manager; + + 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]); + } + if(result.has("crafttext")) { + craftText = result.get("crafttext").getAsString(); + } + cw.craftResult.setInventorySlotContents(0, manager.jsonToStack(result)); + } + + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + String t = text.equals("") ? I18n.format("container.crafting", new Object[0]) : text; + + 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); + + Utils.drawStringCenteredScaledMaxWidth(craftText, fontRendererObj, 132, 25, + false, 75, 4210752); + } + + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + } + + 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); + } + 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/GuiItemUsages.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java new file mode 100644 index 00000000..ceb4e5d4 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemUsages.java @@ -0,0 +1,165 @@ +package io.github.moulberry.notenoughupdates; + +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.util.TexLoc; +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(); + } + cw.craftResult.setInventorySlotContents(0, manager.jsonToStack(results.get(currentIndex))); + } + } + + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + String t = "Crafting Usages"; + + 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 new file mode 100644 index 00000000..48db19a5 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java @@ -0,0 +1,47 @@ +package io.github.moulberry.notenoughupdates; + +import net.minecraft.util.ResourceLocation; + +public class GuiTextures { + + private GuiTextures() {} //Not instantiable. Use import static to access class members. + + public static final ResourceLocation itemPaneTabArrow = new ResourceLocation("notenoughupdates:item_pane_tab_arrow.png"); + //public static final ResourceLocation prev = new ResourceLocation("notenoughupdates:prev.png"); + //public static final ResourceLocation next = new ResourceLocation("notenoughupdates:next.png"); + public static final ResourceLocation rightarrow_overlay = new ResourceLocation("notenoughupdates:rightarrow_overlay.png"); + public static final ResourceLocation rightarrow = new ResourceLocation("notenoughupdates:rightarrow.png"); + public static final ResourceLocation item_edit = new ResourceLocation("notenoughupdates:item_edit.png"); + public static final ResourceLocation close = new ResourceLocation("notenoughupdates:close.png"); + public static final ResourceLocation settings = new ResourceLocation("notenoughupdates:settings.png"); + public static final ResourceLocation off = new ResourceLocation("notenoughupdates:off.png"); + public static final ResourceLocation on = new ResourceLocation("notenoughupdates:on.png"); + public static final ResourceLocation help = new ResourceLocation("notenoughupdates:help.png"); + + public static final ResourceLocation item_mask = new ResourceLocation("notenoughupdates:item_mask.png"); + + public static final ResourceLocation logo = new ResourceLocation("notenoughupdates:logo.png"); + public static final ResourceLocation logo_fg = new ResourceLocation("notenoughupdates:logo_fg.png"); + public static final ResourceLocation logo_bg = new ResourceLocation("notenoughupdates:logo_bg.png"); + + public static final ResourceLocation sort_all = new ResourceLocation("notenoughupdates:sort_all.png" |
