diff --git a/src/mantle/Mantle.java b/src/mantle/Mantle.java index aa5130f..b000244 100644 --- a/src/mantle/Mantle.java +++ b/src/mantle/Mantle.java @@ -2,11 +2,14 @@ package mantle; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.Mod.Instance; import net.minecraftforge.common.Configuration; import static mantle.lib.CoreRepo.*; +import mantle.common.MProxyCommon; import mantle.lib.CoreConfig; import mantle.lib.environment.EnvironmentChecks; @@ -21,6 +24,12 @@ import mantle.lib.environment.EnvironmentChecks; @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class Mantle { + /* Instance of this mod, used for grabbing prototype fields */ + @Instance("Mantle") + public static Mantle instance; + /* Proxies for sides, used for graphics processing */ + @SidedProxy(clientSide = "Mantle.client.MProxyClient", serverSide = "Mantle.common.MProxyCommon") + public static MProxyCommon proxy; /** * FML preinitialisation handler diff --git a/src/mantle/client/MProxyClient.java b/src/mantle/client/MProxyClient.java new file mode 100644 index 0000000..190a1b5 --- /dev/null +++ b/src/mantle/client/MProxyClient.java @@ -0,0 +1,38 @@ +package mantle.client; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.MinecraftForge; +import mantle.client.block.SmallFontRenderer; +import mantle.client.pages.BlankPage; +import mantle.client.pages.BookPage; +import mantle.client.pages.CraftingPage; + + +public class MProxyClient +{ + public static SmallFontRenderer smallFontRenderer; + + /* Registers any rendering code. */ + public void registerRenderer () + { + Minecraft mc = Minecraft.getMinecraft(); + smallFontRenderer = new SmallFontRenderer(mc.gameSettings, new ResourceLocation("textures/font/ascii.png"), mc.renderEngine, false); + } + + public static Map> pageClasses = new HashMap>(); + + public static void registerManualPage (String type, Class clazz) + { + pageClasses.put(type, clazz); + } + + public static Class getPageClass (String type) + { + return pageClasses.get(type); + } + +} diff --git a/src/mantle/client/RenderItemCopy.java b/src/mantle/client/RenderItemCopy.java new file mode 100644 index 0000000..982e19f --- /dev/null +++ b/src/mantle/client/RenderItemCopy.java @@ -0,0 +1,669 @@ +package mantle.client; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Icon; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.ForgeHooksClient; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import mantle.client.block.SmallFontRenderer; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderItemCopy extends Render +{ + private static final ResourceLocation field_110798_h = new ResourceLocation("textures/misc/enchanted_item_glint.png"); + private RenderBlocks itemRenderBlocks = new RenderBlocks(); + + /** The RNG used in RenderItem (for bobbing itemstacks on the ground) */ + private Random random = new Random(); + public boolean renderWithColor = true; + + /** Defines the zLevel of rendering of item on GUI. */ + public float zLevel; + public static boolean renderInFrame; + + public RenderItemCopy() + { + this.shadowSize = 0.15F; + this.shadowOpaque = 0.75F; + } + + /** + * Renders the item + */ + public void doRenderItem (EntityItem par1EntityItem, double par2, double par4, double par6, float par8, float par9) + { + this.bindEntityTexture(par1EntityItem); + this.random.setSeed(187L); + ItemStack itemstack = par1EntityItem.getEntityItem(); + + if (itemstack.getItem() != null) + { + GL11.glPushMatrix(); + float f2 = shouldBob() ? MathHelper.sin(((float) par1EntityItem.age + par9) / 10.0F + par1EntityItem.hoverStart) * 0.1F + 0.1F : 0F; + float f3 = (((float) par1EntityItem.age + par9) / 20.0F + par1EntityItem.hoverStart) * (180F / (float) Math.PI); + byte b0 = getMiniBlockCount(itemstack); + + GL11.glTranslatef((float) par2, (float) par4 + f2, (float) par6); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + float f4; + float f5; + float f6; + int i; + + Block block = null; + if (itemstack.itemID < Block.blocksList.length) + { + block = Block.blocksList[itemstack.itemID]; + } + + if (ForgeHooksClient.renderEntityItem(par1EntityItem, itemstack, f2, f3, random, renderManager.renderEngine, renderBlocks)) + { + ; + } + else if (itemstack.getItemSpriteNumber() == 0 && block != null && RenderBlocks.renderItemIn3d(Block.blocksList[itemstack.itemID].getRenderType())) + { + GL11.glRotatef(f3, 0.0F, 1.0F, 0.0F); + + if (renderInFrame) + { + GL11.glScalef(1.25F, 1.25F, 1.25F); + GL11.glTranslatef(0.0F, 0.05F, 0.0F); + GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); + } + + float f7 = 0.25F; + int j = block.getRenderType(); + + if (j == 1 || j == 19 || j == 12 || j == 2) + { + f7 = 0.5F; + } + + GL11.glScalef(f7, f7, f7); + + for (i = 0; i < b0; ++i) + { + GL11.glPushMatrix(); + + if (i > 0) + { + f5 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / f7; + f4 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / f7; + f6 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / f7; + GL11.glTranslatef(f5, f4, f6); + } + + f5 = 1.0F; + this.itemRenderBlocks.renderBlockAsItem(block, itemstack.getItemDamage(), f5); + GL11.glPopMatrix(); + } + } + else + { + float f8; + + if (itemstack.getItemSpriteNumber() == 1 && itemstack.getItem().requiresMultipleRenderPasses()) + { + if (renderInFrame) + { + GL11.glScalef(0.5128205F, 0.5128205F, 0.5128205F); + GL11.glTranslatef(0.0F, -0.05F, 0.0F); + } + else + { + GL11.glScalef(0.5F, 0.5F, 0.5F); + } + + for (int k = 0; k < itemstack.getItem().getRenderPasses(itemstack.getItemDamage()); ++k) + { + this.random.setSeed(187L); + Icon icon = itemstack.getItem().getIcon(itemstack, k); + f8 = 1.0F; + + if (this.renderWithColor) + { + i = Item.itemsList[itemstack.itemID].getColorFromItemStack(itemstack, k); + f5 = (float) (i >> 16 & 255) / 255.0F; + f4 = (float) (i >> 8 & 255) / 255.0F; + f6 = (float) (i & 255) / 255.0F; + GL11.glColor4f(f5 * f8, f4 * f8, f6 * f8, 1.0F); + this.renderDroppedItem(par1EntityItem, icon, b0, par9, f5 * f8, f4 * f8, f6 * f8, k); + } + else + { + this.renderDroppedItem(par1EntityItem, icon, b0, par9, 1.0F, 1.0F, 1.0F, k); + } + } + } + else + { + if (renderInFrame) + { + GL11.glScalef(0.5128205F, 0.5128205F, 0.5128205F); + GL11.glTranslatef(0.0F, -0.05F, 0.0F); + } + else + { + GL11.glScalef(0.5F, 0.5F, 0.5F); + } + + Icon icon1 = itemstack.getIconIndex(); + + if (this.renderWithColor) + { + int l = Item.itemsList[itemstack.itemID].getColorFromItemStack(itemstack, 0); + f8 = (float) (l >> 16 & 255) / 255.0F; + float f9 = (float) (l >> 8 & 255) / 255.0F; + f5 = (float) (l & 255) / 255.0F; + f4 = 1.0F; + this.renderDroppedItem(par1EntityItem, icon1, b0, par9, f8 * f4, f9 * f4, f5 * f4); + } + else + { + this.renderDroppedItem(par1EntityItem, icon1, b0, par9, 1.0F, 1.0F, 1.0F); + } + } + } + + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + GL11.glPopMatrix(); + } + } + + protected ResourceLocation func_110796_a (EntityItem par1EntityItem) + { + return this.renderManager.renderEngine.getResourceLocation(par1EntityItem.getEntityItem().getItemSpriteNumber()); + } + + /** + * Renders a dropped item + */ + private void renderDroppedItem (EntityItem par1EntityItem, Icon par2Icon, int par3, float par4, float par5, float par6, float par7) + { + renderDroppedItem(par1EntityItem, par2Icon, par3, par4, par5, par6, par7, 0); + } + + private void renderDroppedItem (EntityItem par1EntityItem, Icon par2Icon, int par3, float par4, float par5, float par6, float par7, int pass) + { + Tessellator tessellator = Tessellator.instance; + + if (par2Icon == null) + { + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + ResourceLocation resourcelocation = texturemanager.getResourceLocation(par1EntityItem.getEntityItem().getItemSpriteNumber()); + par2Icon = ((TextureMap) texturemanager.getTexture(resourcelocation)).getAtlasSprite("missingno"); + } + + float f4 = ((Icon) par2Icon).getMinU(); + float f5 = ((Icon) par2Icon).getMaxU(); + float f6 = ((Icon) par2Icon).getMinV(); + float f7 = ((Icon) par2Icon).getMaxV(); + float f8 = 1.0F; + float f9 = 0.5F; + float f10 = 0.25F; + float f11; + + if (this.renderManager.options.fancyGraphics) + { + GL11.glPushMatrix(); + + if (renderInFrame) + { + GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); + } + else + { + GL11.glRotatef((((float) par1EntityItem.age + par4) / 20.0F + par1EntityItem.hoverStart) * (180F / (float) Math.PI), 0.0F, 1.0F, 0.0F); + } + + float f12 = 0.0625F; + f11 = 0.021875F; + ItemStack itemstack = par1EntityItem.getEntityItem(); + int j = itemstack.stackSize; + byte b0 = getMiniItemCount(itemstack); + + GL11.glTranslatef(-f9, -f10, -((f12 + f11) * (float) b0 / 2.0F)); + + for (int k = 0; k < b0; ++k) + { + // Makes items offset when in 3D, like when in 2D, looks much better. Considered a vanilla bug... + if (k > 0 && shouldSpreadItems()) + { + float x = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F; + float y = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F; + float z = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F; + GL11.glTranslatef(x, y, f12 + f11); + } + else + { + GL11.glTranslatef(0f, 0f, f12 + f11); + } + + if (itemstack.getItemSpriteNumber() == 0) + { + this.bindTexture(TextureMap.locationBlocksTexture); + } + else + { + this.bindTexture(TextureMap.locationItemsTexture); + } + + GL11.glColor4f(par5, par6, par7, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, f5, f6, f4, f7, ((Icon) par2Icon).getIconWidth(), ((Icon) par2Icon).getIconHeight(), f12); + + if (itemstack.hasEffect(pass)) + { + GL11.glDepthFunc(GL11.GL_EQUAL); + GL11.glDisable(GL11.GL_LIGHTING); + this.renderManager.renderEngine.bindTexture(field_110798_h); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + float f13 = 0.76F; + GL11.glColor4f(0.5F * f13, 0.25F * f13, 0.8F * f13, 1.0F); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPushMatrix(); + float f14 = 0.125F; + GL11.glScalef(f14, f14, f14); + float f15 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; + GL11.glTranslatef(f15, 0.0F, 0.0F); + GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f12); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glScalef(f14, f14, f14); + f15 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; + GL11.glTranslatef(-f15, 0.0F, 0.0F); + GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f12); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDepthFunc(GL11.GL_LEQUAL); + } + } + + GL11.glPopMatrix(); + } + else + { + for (int l = 0; l < par3; ++l) + { + GL11.glPushMatrix(); + + if (l > 0) + { + f11 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F; + float f16 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F; + float f17 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F; + GL11.glTranslatef(f11, f16, f17); + } + + if (!renderInFrame) + { + GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + } + + GL11.glColor4f(par5, par6, par7, 1.0F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + tessellator.addVertexWithUV((double) (0.0F - f9), (double) (0.0F - f10), 0.0D, (double) f4, (double) f7); + tessellator.addVertexWithUV((double) (f8 - f9), (double) (0.0F - f10), 0.0D, (double) f5, (double) f7); + tessellator.addVertexWithUV((double) (f8 - f9), (double) (1.0F - f10), 0.0D, (double) f5, (double) f6); + tessellator.addVertexWithUV((double) (0.0F - f9), (double) (1.0F - f10), 0.0D, (double) f4, (double) f6); + tessellator.draw(); + GL11.glPopMatrix(); + } + } + } + + /** + * Renders the item's icon or block into the UI at the specified position. + */ + public void renderItemIntoGUI (SmallFontRenderer par1FontRenderer, TextureManager par2TextureManager, ItemStack par3ItemStack, int par4, int par5) + { + renderItemIntoGUI(par1FontRenderer, par2TextureManager, par3ItemStack, par4, par5, false); + } + + public void renderItemIntoGUI (SmallFontRenderer par1FontRenderer, TextureManager par2TextureManager, ItemStack par3ItemStack, int par4, int par5, boolean renderEffect) + { + int k = par3ItemStack.itemID; + int l = par3ItemStack.getItemDamage(); + Object object = par3ItemStack.getItem() == null ? null : par3ItemStack.getIconIndex(); + float f; + int i1; + float f1; + float f2; + + Block block = (k < Block.blocksList.length ? Block.blocksList[k] : null); + if (block != null && par3ItemStack.getItemSpriteNumber() == 0 && RenderBlocks.renderItemIn3d(Block.blocksList[k].getRenderType())) + { + par2TextureManager.bindTexture(TextureMap.locationBlocksTexture); + GL11.glPushMatrix(); + GL11.glTranslatef((float) (par4 - 2), (float) (par5 + 3), -3.0F + this.zLevel); + GL11.glScalef(10.0F, 10.0F, 10.0F); + GL11.glTranslatef(1.0F, 0.5F, 1.0F); + GL11.glScalef(1.0F, 1.0F, -1.0F); + GL11.glRotatef(210.0F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F); + i1 = Item.itemsList[k].getColorFromItemStack(par3ItemStack, 0); + f = (float) (i1 >> 16 & 255) / 255.0F; + f1 = (float) (i1 >> 8 & 255) / 255.0F; + f2 = (float) (i1 & 255) / 255.0F; + + if (this.renderWithColor) + { + GL11.glColor4f(f, f1, f2, 1.0F); + } + + GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); + this.itemRenderBlocks.useInventoryTint = this.renderWithColor; + this.itemRenderBlocks.renderBlockAsItem(block, l, 1.0F); + this.itemRenderBlocks.useInventoryTint = true; + GL11.glPopMatrix(); + } + else if (Item.itemsList[k] != null && Item.itemsList[k].requiresMultipleRenderPasses()) + { + GL11.glDisable(GL11.GL_LIGHTING); + + for (int j1 = 0; j1 < Item.itemsList[k].getRenderPasses(l); ++j1) + { + par2TextureManager.bindTexture(par3ItemStack.getItemSpriteNumber() == 0 ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture); + Icon icon = Item.itemsList[k].getIcon(par3ItemStack, j1); + int k1 = Item.itemsList[k].getColorFromItemStack(par3ItemStack, j1); + f1 = (float) (k1 >> 16 & 255) / 255.0F; + f2 = (float) (k1 >> 8 & 255) / 255.0F; + float f3 = (float) (k1 & 255) / 255.0F; + + if (this.renderWithColor) + { + GL11.glColor4f(f1, f2, f3, 1.0F); + } + + this.renderIcon(par4, par5, icon, 16, 16); + + if (par3ItemStack.hasEffect(j1)) + { + renderEffect(par2TextureManager, par4, par5); + } + } + + GL11.glEnable(GL11.GL_LIGHTING); + } + else + { + GL11.glDisable(GL11.GL_LIGHTING); + ResourceLocation resourcelocation = par2TextureManager.getResourceLocation(par3ItemStack.getItemSpriteNumber()); + par2TextureManager.bindTexture(resourcelocation); + + if (object == null) + { + object = ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture(resourcelocation)).getAtlasSprite("missingno"); + } + + i1 = Item.itemsList[k].getColorFromItemStack(par3ItemStack, 0); + f = (float) (i1 >> 16 & 255) / 255.0F; + f1 = (float) (i1 >> 8 & 255) / 255.0F; + f2 = (float) (i1 & 255) / 255.0F; + + if (this.renderWithColor) + { + GL11.glColor4f(f, f1, f2, 1.0F); + } + + this.renderIcon(par4, par5, (Icon) object, 16, 16); + GL11.glEnable(GL11.GL_LIGHTING); + + if (par3ItemStack.hasEffect(0)) + { + renderEffect(par2TextureManager, par4, par5); + } + } + + GL11.glEnable(GL11.GL_CULL_FACE); + } + + private void renderEffect (TextureManager manager, int x, int y) + { + GL11.glDepthFunc(GL11.GL_GREATER); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDepthMask(false); + manager.bindTexture(field_110798_h); + this.zLevel -= 50.0F; + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_DST_COLOR); + GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F); + this.renderGlint(x * 431278612 + y * 32178161, x - 2, y - 2, 20, 20); + GL11.glDisable(GL11.GL_BLEND); + GL11.glDepthMask(true); + this.zLevel += 50.0F; + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDepthFunc(GL11.GL_LEQUAL); + } + + /** + * Render the item's icon or block into the GUI, including the glint effect. + */ + public void renderItemAndEffectIntoGUI (SmallFontRenderer par1FontRenderer, TextureManager par2TextureManager, ItemStack par3ItemStack, int par4, int par5) + { + if (par3ItemStack != null) + { + if (!ForgeHooksClient.renderInventoryItem(renderBlocks, par2TextureManager, par3ItemStack, renderWithColor, zLevel, (float) par4, (float) par5)) + { + this.renderItemIntoGUI(par1FontRenderer, par2TextureManager, par3ItemStack, par4, par5, true); + } + + /* Modders must handle this themselves if they use custom renderers! + if (par3ItemStack.hasEffect()) + { + GL11.glDepthFunc(GL11.GL_GREATER); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDepthMask(false); + par2TextureManager.bindTexture(field_110798_h); + this.zLevel -= 50.0F; + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_DST_COLOR); + GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F); + this.renderGlint(par4 * 431278612 + par5 * 32178161, par4 - 2, par5 - 2, 20, 20); + GL11.glDisable(GL11.GL_BLEND); + GL11.glDepthMask(true); + this.zLevel += 50.0F; + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDepthFunc(GL11.GL_LEQUAL); + } + */ + } + } + + private void renderGlint (int par1, int par2, int par3, int par4, int par5) + { + for (int j1 = 0; j1 < 2; ++j1) + { + if (j1 == 0) + { + GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + } + + if (j1 == 1) + { + GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + } + + float f = 0.00390625F; + float f1 = 0.00390625F; + float f2 = (float) (Minecraft.getSystemTime() % (long) (3000 + j1 * 1873)) / (3000.0F + (float) (j1 * 1873)) * 256.0F; + float f3 = 0.0F; + Tessellator tessellator = Tessellator.instance; + float f4 = 4.0F; + + if (j1 == 1) + { + f4 = -1.0F; + } + + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV((double) (par2 + 0), (double) (par3 + par5), (double) this.zLevel, (double) ((f2 + (float) par5 * f4) * f), (double) ((f3 + (float) par5) * f1)); + tessellator.addVertexWithUV((double) (par2 + par4), (double) (par3 + par5), (double) this.zLevel, (double) ((f2 + (float) par4 + (float) par5 * f4) * f), + (double) ((f3 + (float) par5) * f1)); + tessellator.addVertexWithUV((double) (par2 + par4), (double) (par3 + 0), (double) this.zLevel, (double) ((f2 + (float) par4) * f), (double) ((f3 + 0.0F) * f1)); + tessellator.addVertexWithUV((double) (par2 + 0), (double) (par3 + 0), (double) this.zLevel, (double) ((f2 + 0.0F) * f), (double) ((f3 + 0.0F) * f1)); + tessellator.draw(); + } + } + + /** + * Renders the item's overlay information. Examples being stack count or damage on top of the item's image at the + * specified position. + */ + public void renderItemOverlayIntoGUI (SmallFontRenderer par1FontRenderer, TextureManager par2TextureManager, ItemStack par3ItemStack, int par4, int par5) + { + this.renderItemOverlayIntoGUI(par1FontRenderer, par2TextureManager, par3ItemStack, par4, par5, (String) null); + } + + public void renderItemOverlayIntoGUI (SmallFontRenderer par1FontRenderer, TextureManager par2TextureManager, ItemStack par3ItemStack, int par4, int par5, String par6Str) + { + if (par3ItemStack != null) + { + if (par3ItemStack.stackSize > 1 || par6Str != null) + { + String s1 = par6Str == null ? String.valueOf(par3ItemStack.stackSize) : par6Str; + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + par1FontRenderer.drawStringWithShadow(s1, par4 + 19 - 2 - par1FontRenderer.getStringWidth(s1), par5 + 6 + 3, 16777215); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_DEPTH_TEST); + } + + if (par3ItemStack.isItemDamaged()) + { + int k = (int) Math.round(13.0D - (double) par3ItemStack.getItemDamageForDisplay() * 13.0D / (double) par3ItemStack.getMaxDamage()); + int l = (int) Math.round(255.0D - (double) par3ItemStack.getItemDamageForDisplay() * 255.0D / (double) par3ItemStack.getMaxDamage()); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_TEXTURE_2D); + Tessellator tessellator = Tessellator.instance; + int i1 = 255 - l << 16 | l << 8; + int j1 = (255 - l) / 4 << 16 | 16128; + this.renderQuad(tessellator, par4 + 2, par5 + 13, 13, 2, 0); + this.renderQuad(tessellator, par4 + 2, par5 + 13, 12, 1, j1); + this.renderQuad(tessellator, par4 + 2, par5 + 13, k, 1, i1); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + } + } + } + + /** + * Adds a quad to the tesselator at the specified position with the set width and height and color. Args: + * tessellator, x, y, width, height, color + */ + private void renderQuad (Tessellator par1Tessellator, int par2, int par3, int par4, int par5, int par6) + { + par1Tessellator.startDrawingQuads(); + par1Tessellator.setColorOpaque_I(par6); + par1Tessellator.addVertex((double) (par2 + 0), (double) (par3 + 0), 0.0D); + par1Tessellator.addVertex((double) (par2 + 0), (double) (par3 + par5), 0.0D); + par1Tessellator.addVertex((double) (par2 + par4), (double) (par3 + par5), 0.0D); + par1Tessellator.addVertex((double) (par2 + par4), (double) (par3 + 0), 0.0D); + par1Tessellator.draw(); + } + + public void renderIcon (int par1, int par2, Icon par3Icon, int par4, int par5) + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV((double) (par1 + 0), (double) (par2 + par5), (double) this.zLevel, (double) par3Icon.getMinU(), (double) par3Icon.getMaxV()); + tessellator.addVertexWithUV((double) (par1 + par4), (double) (par2 + par5), (double) this.zLevel, (double) par3Icon.getMaxU(), (double) par3Icon.getMaxV()); + tessellator.addVertexWithUV((double) (par1 + par4), (double) (par2 + 0), (double) this.zLevel, (double) par3Icon.getMaxU(), (double) par3Icon.getMinV()); + tessellator.addVertexWithUV((double) (par1 + 0), (double) (par2 + 0), (double) this.zLevel, (double) par3Icon.getMinU(), (double) par3Icon.getMinV()); + tessellator.draw(); + } + + protected ResourceLocation getEntityTexture (Entity par1Entity) + { + return this.func_110796_a((EntityItem) par1Entity); + } + + /** + * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then + * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic + * (Render 1) + ret = 2; + if (stack.stackSize > 5) + ret = 3; + if (stack.stackSize > 20) + ret = 4; + if (stack.stackSize > 40) + ret = 5; + return ret; + } + + /** + * Allows for a subclass to override how many rendered items appear in a + * "mini item 3d stack" + * @param stack + * @return + */ + public byte getMiniItemCount (ItemStack stack) + { + byte ret = 1; + if (stack.stackSize > 1) + ret = 2; + if (stack.stackSize > 15) + ret = 3; + if (stack.stackSize > 31) + ret = 4; + return ret; + } +} diff --git a/src/mantle/client/block/SmallFontRenderer.java b/src/mantle/client/block/SmallFontRenderer.java new file mode 100644 index 0000000..883bf82 --- /dev/null +++ b/src/mantle/client/block/SmallFontRenderer.java @@ -0,0 +1,1043 @@ +package mantle.client.block; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.text.Bidi; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +import javax.imageio.ImageIO; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.ResourceManager; +import net.minecraft.client.resources.ResourceManagerReloadListener; +import net.minecraft.client.settings.GameSettings; +import net.minecraft.util.ChatAllowedCharacters; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class SmallFontRenderer implements ResourceManagerReloadListener +{ + private static final ResourceLocation[] field_111274_c = new ResourceLocation[256]; + + /** Array of width of all the characters in default.png */ + private int[] charWidth = new int[256]; + + /** the height in pixels of default text */ + public int FONT_HEIGHT = 9; + public Random fontRandom = new Random(); + + /** + * Array of the start/end column (in upper/lower nibble) for every glyph in the /font directory. + */ + private byte[] glyphWidth = new byte[65536]; + + /** + * Array of RGB triplets defining the 16 standard chat colors followed by 16 darker version of the same colors for + * drop shadows. + */ + private int[] colorCode = new int[32]; + private final ResourceLocation field_111273_g; + + /** The RenderEngine used to load and setup glyph textures. */ + private final TextureManager renderEngine; + + /** Current X coordinate at which to draw the next character. */ + private float posX; + + /** Current Y coordinate at which to draw the next character. */ + private float posY; + + /** + * If true, strings should be rendered with Unicode fonts instead of the default.png font + */ + private boolean unicodeFlag; + + /** + * If true, the Unicode Bidirectional Algorithm should be run before rendering any string. + */ + private boolean bidiFlag; + + /** Used to specify new red value for the current color. */ + private float red; + + /** Used to specify new blue value for the current color. */ + private float blue; + + /** Used to specify new green value for the current color. */ + private float green; + + /** Used to speify new alpha value for the current color. */ + private float alpha; + + /** Text color of the currently rendering string. */ + private int textColor; + + /** Set if the "k" style (random) is active in currently rendering string */ + private boolean randomStyle; + + /** Set if the "l" style (bold) is active in currently rendering string */ + private boolean boldStyle; + + /** Set if the "o" style (italic) is active in currently rendering string */ + private boolean italicStyle; + + /** + * Set if the "n" style (underlined) is active in currently rendering string + */ + private boolean underlineStyle; + + /** + * Set if the "m" style (strikethrough) is active in currently rendering string + */ + private boolean strikethroughStyle; + + public SmallFontRenderer(GameSettings par1GameSettings, ResourceLocation par2ResourceLocation, TextureManager par3TextureManager, boolean par4) + { + this.field_111273_g = par2ResourceLocation; + this.renderEngine = par3TextureManager; + this.unicodeFlag = true; + par3TextureManager.bindTexture(this.field_111273_g); + + for (int i = 0; i < 32; ++i) + { + int j = (i >> 3 & 1) * 85; + int k = (i >> 2 & 1) * 170 + j; + int l = (i >> 1 & 1) * 170 + j; + int i1 = (i >> 0 & 1) * 170 + j; + + if (i == 6) + { + k += 85; + } + + if (par1GameSettings.anaglyph) + { + int j1 = (k * 30 + l * 59 + i1 * 11) / 100; + int k1 = (k * 30 + l * 70) / 100; + int l1 = (k * 30 + i1 * 70) / 100; + k = j1; + l = k1; + i1 = l1; + } + + if (i >= 16) + { + k /= 4; + l /= 4; + i1 /= 4; + } + + this.colorCode[i] = (k & 255) << 16 | (l & 255) << 8 | i1 & 255; + } + + this.readGlyphSizes(); + } + + public void onResourceManagerReload (ResourceManager par1ResourceManager) + { + this.func_111272_d(); + } + + private void func_111272_d () + { + BufferedImage bufferedimage; + + try + { + bufferedimage = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(this.field_111273_g).getInputStream()); + } + catch (IOException ioexception) + { + throw new RuntimeException(ioexception); + } + + int i = bufferedimage.getWidth(); + int j = bufferedimage.getHeight(); + int[] aint = new int[i * j]; + bufferedimage.getRGB(0, 0, i, j, aint, 0, i); + int k = j / 16; + int l = i / 16; + byte b0 = 1; + float f = 8.0F / (float) l; + int i1 = 0; + + while (i1 < 256) + { + int j1 = i1 % 16; + int k1 = i1 / 16; + + if (i1 == 32) + { + this.charWidth[i1] = 3 + b0; + } + + int l1 = l - 1; + + while (true) + { + if (l1 >= 0) + { + int i2 = j1 * l + l1; + boolean flag = true; + + for (int j2 = 0; j2 < k && flag; ++j2) + { + int k2 = (k1 * l + j2) * i; + + if ((aint[i2 + k2] >> 24 & 255) != 0) + { + flag = false; + } + } + + if (flag) + { + --l1; + continue; + } + } + + ++l1; + this.charWidth[i1] = (int) (0.5D + (double) ((float) l1 * f)) + b0; + ++i1; + break; + } + } + } + + private void readGlyphSizes () + { + try + { + InputStream inputstream = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation("font/glyph_sizes.bin")).getInputStream(); + inputstream.read(this.glyphWidth); + } + catch (IOException ioexception) + { + throw new RuntimeException(ioexception); + } + } + + /** + * Pick how to render a single character and return the width used. + */ + private float renderCharAtPos (int par1, char par2, boolean par3) + { + return par2 == 32 ? 4.0F : (par1 > 0 && !this.unicodeFlag ? this.renderDefaultChar(par1 + 32, par3) : this.renderUnicodeChar(par2, par3)); + } + + /** + * Render a single character with the default.png font at current (posX,posY) location... + */ + private float renderDefaultChar (int par1, boolean par2) + { + float f = (float) (par1 % 16 * 8); + float f1 = (float) (par1 / 16 * 8); + float f2 = par2 ? 1.0F : 0.0F; + this.renderEngine.bindTexture(this.field_111273_g); + float f3 = (float) this.charWidth[par1] - 0.01F; + GL11.glBegin(GL11.GL_TRIANGLE_STRIP); + GL11.glTexCoord2f(f / 128.0F, f1 / 128.0F); + GL11.glVertex3f(this.posX + f2, this.posY, 0.0F); + GL11.glTexCoord2f(f / 128.0F, (f1 + 7.99F) / 128.0F); + GL11.glVertex3f(this.posX - f2, this.posY + 7.99F, 0.0F); + GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, f1 / 128.0F); + GL11.glVertex3f(this.posX + f3 - 1.0F + f2, this.posY, 0.0F); + GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, (f1 + 7.99F) / 128.0F); + GL11.glVertex3f(this.posX + f3 - 1.0F - f2, this.posY + 7.99F, 0.0F); + GL11.glEnd(); + return (float) this.charWidth[par1]; + } + + private ResourceLocation func_111271_a (int par1) + { + if (field_111274_c[par1] == null) + { + field_111274_c[par1] = new ResourceLocation(String.format("textures/font/unicode_page_%02x.png", new Object[] { Integer.valueOf(par1) })); + } + + return field_111274_c[par1]; + } + + /** + * Load one of the /font/glyph_XX.png into a new GL texture and store the texture ID in glyphTextureName array. + */ + private void loadGlyphTexture (int par1) + { + this.renderEngine.bindTexture(this.func_111271_a(par1)); + } + + /** + * Render a single Unicode character at current (posX,posY) location using one of the /font/glyph_XX.png files... + */ + private float renderUnicodeChar (char par1, boolean par2) + { + if (this.glyphWidth[par1] == 0) + { + return 0.0F; + } + else + { + int i = par1 / 256; + this.loadGlyphTexture(i); + int j = this.glyphWidth[par1] >>> 4; + int k = this.glyphWidth[par1] & 15; + float f = (float) j; + float f1 = (float) (k + 1); + float f2 = (float) (par1 % 16 * 16) + f; + float f3 = (float) ((par1 & 255) / 16 * 16); + float f4 = f1 - f - 0.02F; + float f5 = par2 ? 1.0F : 0.0F; + GL11.glBegin(GL11.GL_TRIANGLE_STRIP); + GL11.glTexCoord2f(f2 / 256.0F, f3 / 256.0F); + GL11.glVertex3f(this.posX + f5, this.posY, 0.0F); + GL11.glTexCoord2f(f2 / 256.0F, (f3 + 15.98F) / 256.0F); + GL11.glVertex3f(this.posX - f5, this.posY + 7.99F, 0.0F); + GL11.glTexCoord2f((f2 + f4) / 256.0F, f3 / 256.0F); + GL11.glVertex3f(this.posX + f4 / 2.0F + f5, this.posY, 0.0F); + GL11.glTexCoord2f((f2 + f4) / 256.0F, (f3 + 15.98F) / 256.0F); + GL11.glVertex3f(this.posX + f4 / 2.0F - f5, this.posY + 7.99F, 0.0F); + GL11.glEnd(); + return (f1 - f) / 2.0F + 1.0F; + } + } + + /** + * Draws the specified string with a shadow. + */ + public int drawStringWithShadow (String par1Str, int par2, int par3, int par4) + { + return this.drawString(par1Str, par2, par3, par4, true); + } + + /** + * Draws the specified string. + */ + public int drawString (String par1Str, int par2, int par3, int par4) + { + return this.drawString(par1Str, par2, par3, par4, false); + } + + /** + * Draws the specified string. Args: string, x, y, color, dropShadow + */ + public int drawString (String par1Str, int par2, int par3, int par4, boolean par5) + { + this.resetStyles(); + + if (this.bidiFlag) + { + par1Str = this.bidiReorder(par1Str); + } + + int l; + + if (par5) + { + l = this.renderString(par1Str, par2 + 1, par3 + 1, par4, true); + l = Math.max(l, this.renderString(par1Str, par2, par3, par4, false)); + } + else + { + l = this.renderString(par1Str, par2, par3, par4, false); + } + + return l; + } + + /** + * Apply Unicode Bidirectional Algorithm to string and return a new possibly reordered string for visual rendering. + */ + private String bidiReorder (String par1Str) + { + if (par1Str != null && Bidi.requiresBidi(par1Str.toCharArray(), 0, par1Str.length())) + { + Bidi bidi = new Bidi(par1Str, -2); + byte[] abyte = new byte[bidi.getRunCount()]; + String[] astring = new String[abyte.length]; + int i; + + for (int j = 0; j < abyte.length; ++j) + { + int k = bidi.getRunStart(j); + i = bidi.getRunLimit(j); + int l = bidi.getRunLevel(j); + String s1 = par1Str.substring(k, i); + abyte[j] = (byte) l; + astring[j] = s1; + } + + String[] astring1 = (String[]) astring.clone(); + Bidi.reorderVisually(abyte, 0, astring, 0, abyte.length); + StringBuilder stringbuilder = new StringBuilder(); + i = 0; + + while (i < astring.length) + { + byte b0 = abyte[i]; + int i1 = 0; + + while (true) + { + if (i1 < astring1.length) + { + if (!astring1[i1].equals(astring[i])) + { + ++i1; + continue; + } + + b0 = abyte[i1]; + } + + if ((b0 & 1) == 0) + { + stringbuilder.append(astring[i]); + } + else + { + for (i1 = astring[i].length() - 1; i1 >= 0; --i1) + { + char c0 = astring[i].charAt(i1); + + if (c0 == 40) + { + c0 = 41; + } + else if (c0 == 41) + { + c0 = 40; + } + + stringbuilder.append(c0); + } + } + + ++i; + break; + } + } + + return stringbuilder.toString(); + } + else + { + return par1Str; + } + } + + /** + * Reset all style flag fields in the class to false; called at the start of string rendering + */ + private void resetStyles () + { + this.randomStyle = false; + this.boldStyle = false; + this.italicStyle = false; + this.underlineStyle = false; + this.strikethroughStyle = false; + } + + /** + * Render a single line string at the current (posX,posY) and update posX + */ + private void renderStringAtPos (String par1Str, boolean par2) + { + for (int i = 0; i < par1Str.length(); ++i) + { + char c0 = par1Str.charAt(i); + int j; + int k; + + if (c0 == 167 && i + 1 < par1Str.length()) + { + j = "0123456789abcdefklmnor".indexOf(par1Str.toLowerCase().charAt(i + 1)); + + if (j < 16) + { + this.randomStyle = false; + this.boldStyle = false; + this.strikethroughStyle = false; + this.underlineStyle = false; + this.italicStyle = false; + + if (j < 0 || j > 15) + { + j = 15; + } + + if (par2) + { + j += 16; + } + + k = this.colorCode[j]; + this.textColor = k; + GL11.glColor4f((float) (k >> 16) / 255.0F, (float) (k >> 8 & 255) / 255.0F, (float) (k & 255) / 255.0F, this.alpha); + } + else if (j == 16) + { + this.randomStyle = true; + } + else if (j == 17) + { + this.boldStyle = true; + } + else if (j == 18) + { + this.strikethroughStyle = true; + } + else if (j == 19) + { + this.underlineStyle = true; + } + else if (j == 20) + { + this.italicStyle = true; + } + else if (j == 21) + { + this.randomStyle = false; + this.boldStyle = false; + this.strikethroughStyle = false; + this.underlineStyle = false; + this.italicStyle = false; + GL11.glColor4f(this.red, this.blue, this.green, this.alpha); + } + + ++i; + } + else + { + j = ChatAllowedCharacters.allowedCharacters.indexOf(c0); + + if (this.randomStyle && j > 0) + { + do + { + k = this.fontRandom.nextInt(ChatAllowedCharacters.allowedCharacters.length()); + } while (this.charWidth[j + 32] != this.charWidth[k + 32]); + + j = k; + } + + float f = this.unicodeFlag ? 0.5F : 1.0F; + boolean flag1 = (j <= 0 || this.unicodeFlag) && par2; + + if (flag1) + { + this.posX -= f; + this.posY -= f; + } + + float f1 = this.renderCharAtPos(j, c0, this.italicStyle); + + if (flag1) + { + this.posX += f; + this.posY += f; + } + + if (this.boldStyle) + { + this.posX += f; + + if (flag1) + { + this.posX -= f; + this.posY -= f; + } + + this.renderCharAtPos(j, c0, this.italicStyle); + this.posX -= f; + + if (flag1) + { + this.posX += f; + this.posY += f; + } + + ++f1; + } + + Tessellator tessellator; + + if (this.strikethroughStyle) + { + tessellator = Tessellator.instance; + GL11.glDisable(GL11.GL_TEXTURE_2D); + tessellator.startDrawingQuads(); + tessellator.addVertex((double) this.posX, (double) (this.posY + (float) (this.FONT_HEIGHT / 2)), 0.0D); + tessellator.addVertex((double) (this.posX + f1), (double) (this.posY + (float) (this.FONT_HEIGHT / 2)), 0.0D); + tessellator.addVertex((double) (this.posX + f1), (double) (this.posY + (float) (this.FONT_HEIGHT / 2) - 1.0F), 0.0D); + tessellator.addVertex((double) this.posX, (double) (this.posY + (float) (this.FONT_HEIGHT / 2) - 1.0F), 0.0D); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + if (this.underlineStyle) + { + tessellator = Tessellator.instance; + GL11.glDisable(GL11.GL_TEXTURE_2D); + tessellator.startDrawingQuads(); + int l = this.underlineStyle ? -1 : 0; + tessellator.addVertex((double) (this.posX + (float) l), (double) (this.posY + (float) this.FONT_HEIGHT), 0.0D); + tessellator.addVertex((double) (this.posX + f1), (double) (this.posY + (float) this.FONT_HEIGHT), 0.0D); + tessellator.addVertex((double) (this.posX + f1), (double) (this.posY + (float) this.FONT_HEIGHT - 1.0F), 0.0D); + tessellator.addVertex((double) (this.posX + (float) l), (double) (this.posY + (float) this.FONT_HEIGHT - 1.0F), 0.0D); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + this.posX += (float) ((int) f1); + } + } + } + + /** + * Render string either left or right aligned depending on bidiFlag + */ + private int renderStringAligned (String par1Str, int par2, int par3, int par4, int par5, boolean par6) + { + if (this.bidiFlag) + { + par1Str = this.bidiReorder(par1Str); + int i1 = this.getStringWidth(par1Str); + par2 = par2 + par4 - i1; + } + + return this.renderString(par1Str, par2, par3, par5, par6); + } + + /** + * Render single line string by setting GL color, current (posX,posY), and calling renderStringAtPos() + */ + private int renderString (String par1Str, int par2, int par3, int par4, boolean par5) + { + if (par1Str == null) + { + return 0; + } + else + { + if ((par4 & -67108864) == 0) + { + par4 |= -16777216; + } + + if (par5) + { + par4 = (par4 & 16579836) >> 2 | par4 & -16777216; + } + + this.red = (float) (par4 >> 16 & 255) / 255.0F; + this.blue = (float) (par4 >> 8 & 255) / 255.0F; + this.green = (float) (par4 & 255) / 255.0F; + this.alpha = (float) (par4 >> 24 & 255) / 255.0F; + GL11.glColor4f(this.red, this.blue, this.green, this.alpha); + this.posX = (float) par2; + this.posY = (float) par3; + this.renderStringAtPos(par1Str, par5); + return (int) this.posX; + } + } + + /** + * Returns the width of this string. Equivalent of FontMetrics.stringWidth(String s). + */ + public int getStringWidth (String par1Str) + { + if (par1Str == null) + { + return 0; + } + else + { + int i = 0; + boolean flag = false; + + for (int j = 0; j < par1Str.length(); ++j) + { + char c0 = par1Str.charAt(j); + int k = this.getCharWidth(c0); + + if (k < 0 && j < par1Str.length() - 1) + { + ++j; + c0 = par1Str.charAt(j); + + if (c0 != 108 && c0 != 76) + { + if (c0 == 114 || c0 == 82) + { + flag = false; + } + } + else + { + flag = true; + } + + k = 0; + } + + i += k; + + if (flag) + { + ++i; + } + } + + return i; + } + } + + /** + * Returns the width of this character as rendered. + */ + public int getCharWidth (char par1) + { + if (par1 == 167) + { + return -1; + } + else if (par1 == 32) + { + return 4; + } + else + { + int i = ChatAllowedCharacters.allowedCharacters.indexOf(par1); + + if (i >= 0 && !this.unicodeFlag) + { + return this.charWidth[i + 32]; + } + else if (this.glyphWidth[par1] != 0) + { + int j = this.glyphWidth[par1] >>> 4; + int k = this.glyphWidth[par1] & 15; + + if (k > 7) + { + k = 15; + j = 0; + } + + ++k; + return (k - j) / 2 + 1; + } + else + { + return 0; + } + } + } + + /** + * Trims a string to fit a specified Width. + */ + public String trimStringToWidth (String par1Str, int par2) + { + return this.trimStringToWidth(par1Str, par2, false); + } + + /** + * Trims a string to a specified width, and will reverse it if par3 is set. + */ + public String trimStringToWidth (String par1Str, int par2, boolean par3) + { + StringBuilder stringbuilder = new StringBuilder(); + int j = 0; + int k = par3 ? par1Str.length() - 1 : 0; + int l = par3 ? -1 : 1; + boolean flag1 = false; + boolean flag2 = false; + + for (int i1 = k; i1 >= 0 && i1 < par1Str.length() && j < par2; i1 += l) + { + char c0 = par1Str.charAt(i1); + int j1 = this.getCharWidth(c0); + + if (flag1) + { + flag1 = false; + + if (c0 != 108 && c0 != 76) + { + if (c0 == 114 || c0 == 82) + { + flag2 = false; + } + } + else + { + flag2 = true; + } + } + else if (j1 < 0) + { + flag1 = true; + } + else + { + j += j1; + + if (flag2) + { + ++j; + } + } + + if (j > par2) + { + break; + } + + if (par3) + { + stringbuilder.insert(0, c0); + } + else + { + stringbuilder.append(c0); + } + } + + return stringbuilder.toString(); + } + + /** + * Remove all newline characters from the end of the string + */ + private String trimStringNewline (String par1Str) + { + while (par1Str != null && par1Str.endsWith("\n")) + { + par1Str = par1Str.substring(0, par1Str.length() - 1); + } + + return par1Str; + } + + /** + * Splits and draws a String with wordwrap (maximum length is parameter k) + */ + public void drawSplitString (String par1Str, int par2, int par3, int par4, int par5) + { + this.resetStyles(); + this.textColor = par5; + par1Str = this.trimStringNewline(par1Str); + this.renderSplitString(par1Str, par2, par3, par4, false); + } + + /** + * Perform actual work of rendering a multi-line string with wordwrap and with darker drop shadow color if flag is + * set + */ + private void renderSplitString (String par1Str, int par2, int par3, int par4, boolean par5) + { + List list = this.listFormattedStringToWidth(par1Str, par4); + + for (Iterator iterator = list.iterator(); iterator.hasNext(); par3 += this.FONT_HEIGHT) + { + String s1 = (String) iterator.next(); + this.renderStringAligned(s1, par2, par3, par4, this.textColor, par5); + } + } + + /** + * Returns the width of the wordwrapped String (maximum length is parameter k) + */ + public int splitStringWidth (String par1Str, int par2) + { + return this.FONT_HEIGHT * this.listFormattedStringToWidth(par1Str, par2).size(); + } + + /** + * Set unicodeFlag controlling whether strings should be rendered with Unicode fonts instead of the default.png + * font. + */ + public void setUnicodeFlag (boolean par1) + { + this.unicodeFlag = par1; + } + + /** + * Get unicodeFlag controlling whether strings should be rendered with Unicode fonts instead of the default.png + * font. + */ + public boolean getUnicodeFlag () + { + return this.unicodeFlag; + } + + /** + * Set bidiFlag to control if the Unicode Bidirectional Algorithm should be run before rendering any string. + */ + public void setBidiFlag (boolean par1) + { + this.bidiFlag = par1; + } + + /** + * Breaks a string into a list of pieces that will fit a specified width. + */ + public List listFormattedStringToWidth (String par1Str, int par2) + { + return Arrays.asList(this.wrapFormattedStringToWidth(par1Str, par2).split("\n")); + } + + /** + * Inserts newline and formatting into a string to wrap it within the specified width. + */ + String wrapFormattedStringToWidth (String par1Str, int par2) + { + int j = this.sizeStringToWidth(par1Str, par2); + + if (par1Str.length() <= j) + { + return par1Str; + } + else + { + String s1 = par1Str.substring(0, j); + char c0 = par1Str.charAt(j); + boolean flag = c0 == 32 || c0 == 10; + String s2 = getFormatFromString(s1) + par1Str.substring(j + (flag ? 1 : 0)); + return s1 + "\n" + this.wrapFormattedStringToWidth(s2, par2); + } + } + + /** + * Determines how many characters from the string will fit into the specified width. + */ + private int sizeStringToWidth (String par1Str, int par2) + { + int j = par1Str.length(); + int k = 0; + int l = 0; + int i1 = -1; + + for (boolean flag = false; l < j; ++l) + { + char c0 = par1Str.charAt(l); + + switch (c0) + { + case 10: + --l; + break; + case 167: + if (l < j - 1) + { + ++l; + char c1 = par1Str.charAt(l); + + if (c1 != 108 && c1 != 76) + { + if (c1 == 114 || c1 == 82 || isFormatColor(c1)) + { + flag = false; + } + } + else + { + flag = true; + } + } + + break; + case 32: + i1 = l; + default: + k += this.getCharWidth(c0); + + if (flag) + { + ++k; + } + } + + if (c0 == 10) + { + ++l; + i1 = l; + break; + } + + if (k > par2) + { + break; + } + } + + return l != j && i1 != -1 && i1 < l ? i1 : l; + } + + /** + * Checks if the char code is a hexadecimal character, used to set colour. + */ + private static boolean isFormatColor (char par0) + { + return par0 >= 48 && par0 <= 57 || par0 >= 97 && par0 <= 102 || par0 >= 65 && par0 <= 70; + } + + /** + * Checks if the char code is O-K...lLrRk-o... used to set special formatting. + */ + private static boolean isFormatSpecial (char par0) + { + return par0 >= 107 && par0 <= 111 || par0 >= 75 && par0 <= 79 || par0 == 114 || par0 == 82; + } + + /** + * Digests a string for nonprinting formatting characters then returns a string containing only that formatting. + */ + private static String getFormatFromString (String par0Str) + { + String s1 = ""; + int i = -1; + int j = par0Str.length(); + + while ((i = par0Str.indexOf(167, i + 1)) != -1) + { + if (i < j - 1) + { + char c0 = par0Str.charAt(i + 1); + + if (isFormatColor(c0)) + { + s1 = "\u00a7" + c0; + } + else if (isFormatSpecial(c0)) + { + s1 = s1 + "\u00a7" + c0; + } + } + } + + return s1; + } + + /** + * Get bidiFlag that controls if the Unicode Bidirectional Algorithm should be run before rendering any string + */ + public boolean getBidiFlag () + { + return this.bidiFlag; + } + +} diff --git a/src/mantle/client/gui/GuiManual.java b/src/mantle/client/gui/GuiManual.java new file mode 100644 index 0000000..4f2923a --- /dev/null +++ b/src/mantle/client/gui/GuiManual.java @@ -0,0 +1,193 @@ +package mantle.client.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import mantle.client.RenderItemCopy; +import mantle.client.MProxyClient; +import mantle.client.block.SmallFontRenderer; +import mantle.client.pages.BookPage; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class GuiManual extends GuiScreen +{ + ItemStack itemstackBook; + Document manual; + public RenderItemCopy renderitem = new RenderItemCopy(); + int bookImageWidth = 206; + int bookImageHeight = 200; + int bookTotalPages = 1; + int currentPage; + int maxPages; + + private TurnPageButton buttonNextPage; + private TurnPageButton buttonPreviousPage; + + BookPage pageLeft; + BookPage pageRight; + + public SmallFontRenderer fonts = MProxyClient.smallFontRenderer; + + public GuiManual(ItemStack stack, Document doc) + { + this.mc = Minecraft.getMinecraft(); + this.itemstackBook = stack; + currentPage = 0; //Stack page + manual = doc; + //renderitem.renderInFrame = true; + } + + /*@Override + public void setWorldAndResolution (Minecraft minecraft, int w, int h) + { + this.guiParticles = new GuiParticle(minecraft); + this.mc = minecraft; + this.width = w; + this.height = h; + this.buttonList.clear(); + this.initGui(); + }*/ + + public void initGui () + { + maxPages = manual.getElementsByTagName("page").getLength(); + updateText(); + int xPos = (this.width) / 2; + this.buttonList.add(this.buttonNextPage = new TurnPageButton(1, xPos + bookImageWidth - 50, 180, true)); + this.buttonList.add(this.buttonPreviousPage = new TurnPageButton(2, xPos - bookImageWidth + 24, 180, false)); + } + + protected void actionPerformed (GuiButton button) + { + if (button.enabled) + { + if (button.id == 1) + currentPage += 2; + if (button.id == 2) + currentPage -= 2; + + updateText(); + } + } + + void updateText () + { + if (maxPages % 2 == 1) + { + if (currentPage > maxPages) + currentPage = maxPages; + } + else + { + if (currentPage >= maxPages) + currentPage = maxPages - 2; + } + if (currentPage % 2 == 1) + currentPage--; + if (currentPage < 0) + currentPage = 0; + + NodeList nList = manual.getElementsByTagName("page"); + + Node node = nList.item(currentPage); + if (node.getNodeType() == Node.ELEMENT_NODE) + { + Element element = (Element) node; + Class clazz = MProxyClient.getPageClass(element.getAttribute("type")); + if (clazz != null) + { + try + { + pageLeft = (BookPage) clazz.newInstance(); + pageLeft.init(this, 0); + pageLeft.readPageFromXML(element); + } + catch (Exception e) + { + } + } + else + { + pageLeft = null; + } + } + + node = nList.item(currentPage + 1); + if (node != null && node.getNodeType() == Node.ELEMENT_NODE) + { + Element element = (Element) node; + Class clazz = MProxyClient.getPageClass(element.getAttribute("type")); + if (clazz != null) + { + try + { + pageRight = (BookPage) clazz.newInstance(); + pageRight.init(this, 1); + pageRight.readPageFromXML(element); + } + catch (Exception e) + { + } + } + else + { + pageLeft = null; + } + } + else + { + pageRight = null; + } + } + + private static final ResourceLocation bookRight = new ResourceLocation("tinker", "textures/gui/bookright.png"); + private static final ResourceLocation bookLeft = new ResourceLocation("tinker", "textures/gui/bookleft.png"); + + public void drawScreen (int par1, int par2, float par3) + { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(bookRight); + int localWidth = (this.width) / 2; + byte localHeight = 8; + this.drawTexturedModalRect(localWidth, localHeight, 0, 0, this.bookImageWidth, this.bookImageHeight); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(bookLeft); + localWidth = localWidth - this.bookImageWidth; + this.drawTexturedModalRect(localWidth, localHeight, 256 - this.bookImageWidth, 0, this.bookImageWidth, this.bookImageHeight); + + super.drawScreen(par1, par2, par3); //16, 12, 220, 12 + + if (pageLeft != null) + pageLeft.renderBackgroundLayer(localWidth + 16, localHeight + 12); + if (pageRight != null) + pageRight.renderBackgroundLayer(localWidth + 220, localHeight + 12); + + if (pageLeft != null) + pageLeft.renderContentLayer(localWidth + 16, localHeight + 12); + if (pageRight != null) + pageRight.renderContentLayer(localWidth + 220, localHeight + 12); + } + + public Minecraft getMC () + { + return mc; + } + + public boolean doesGuiPauseGame () + { + return false; + } +} diff --git a/src/mantle/client/gui/TurnPageButton.java b/src/mantle/client/gui/TurnPageButton.java new file mode 100644 index 0000000..74f90bf --- /dev/null +++ b/src/mantle/client/gui/TurnPageButton.java @@ -0,0 +1,54 @@ +package mantle.client.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class TurnPageButton extends GuiButton +{ + /** + * True for pointing right (next page), false for pointing left (previous page). + */ + private final boolean nextPage; + + public TurnPageButton(int par1, int par2, int par3, boolean par4) + { + super(par1, par2, par3, 23, 13, ""); + this.nextPage = par4; + } + + private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/bookleft.png"); + + /** + * Draws this button to the screen. + */ + public void drawButton (Minecraft par1Minecraft, int par2, int par3) + { + if (this.drawButton) + { + boolean var4 = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height; + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + par1Minecraft.getTextureManager().bindTexture(background); + int var5 = 0; + int var6 = 192; + + if (var4) + { + var5 += 23; + } + + if (!this.nextPage) + { + var6 += 13; + } + + this.drawTexturedModalRect(this.xPosition, this.yPosition, var5, var6, 23, 13); + } + } +} diff --git a/src/mantle/client/pages/BlankPage.java b/src/mantle/client/pages/BlankPage.java new file mode 100644 index 0000000..0960050 --- /dev/null +++ b/src/mantle/client/pages/BlankPage.java @@ -0,0 +1,18 @@ +package mantle.client.pages; + +import org.w3c.dom.Element; + +public class BlankPage extends BookPage +{ + + @Override + public void readPageFromXML (Element element) + { + } + + @Override + public void renderContentLayer (int localwidth, int localheight) + { + } + +} diff --git a/src/mantle/client/pages/BookPage.java b/src/mantle/client/pages/BookPage.java new file mode 100644 index 0000000..b252ed4 --- /dev/null +++ b/src/mantle/client/pages/BookPage.java @@ -0,0 +1,25 @@ +package mantle.client.pages; + +import org.w3c.dom.Element; + +import mantle.client.gui.GuiManual; + +public abstract class BookPage +{ + protected GuiManual manual; + protected int side; + + public void init (GuiManual manual, int side) + { + this.manual = manual; + this.side = side; + } + + public abstract void readPageFromXML (Element element); + + public void renderBackgroundLayer (int localwidth, int localheight) + { + } + + public abstract void renderContentLayer (int localwidth, int localheight); +} diff --git a/src/mantle/client/pages/ContentsTablePage.java b/src/mantle/client/pages/ContentsTablePage.java new file mode 100644 index 0000000..63e1b6d --- /dev/null +++ b/src/mantle/client/pages/ContentsTablePage.java @@ -0,0 +1,57 @@ +package mantle.client.pages; + +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.ItemStack; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import mantle.lib.client.MantleClientRegistry; + +public class ContentsTablePage extends BookPage +{ + String text; + String[] iconText; + ItemStack[] icons; + + @Override + public void readPageFromXML (Element element) + { + NodeList nodes = element.getElementsByTagName("text"); + if (nodes != null) + text = nodes.item(0).getTextContent(); + + nodes = element.getElementsByTagName("link"); + iconText = new String[nodes.getLength()]; + icons = new ItemStack[nodes.getLength()]; + for (int i = 0; i < nodes.getLength(); i++) + { + NodeList children = nodes.item(i).getChildNodes(); + iconText[i] = children.item(1).getTextContent(); + icons[i] = MantleClientRegistry.getManualIcon(children.item(3).getTextContent()); + } + } + + @Override + public void renderContentLayer (int localWidth, int localHeight) + { + if (text != null) + manual.fonts.drawString("\u00a7n" + text, localWidth + 25 + manual.fonts.getStringWidth(text) / 2, localHeight + 4, 0); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + RenderHelper.enableGUIStandardItemLighting(); + manual.renderitem.zLevel = 100; + for (int i = 0; i < icons.length; i++) + { + manual.renderitem.renderItemIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[i], localWidth + 16, localHeight + 18 * i + 18); + int yOffset = 18; + if (iconText[i].length() > 40) + yOffset = 13; + manual.fonts.drawString(iconText[i], localWidth + 38, localHeight + 18 * i + yOffset, 0); + } + manual.renderitem.zLevel = 0; + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + } +} diff --git a/src/mantle/client/pages/CraftingPage.java b/src/mantle/client/pages/CraftingPage.java new file mode 100644 index 0000000..539f6a2 --- /dev/null +++ b/src/mantle/client/pages/CraftingPage.java @@ -0,0 +1,105 @@ +package mantle.client.pages; + +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import mantle.lib.client.MantleClientRegistry; + +public class CraftingPage extends BookPage +{ + String text; + String size; + ItemStack[] icons; + + @Override + public void readPageFromXML (Element element) + { + NodeList nodes = element.getElementsByTagName("text"); + if (nodes != null) + text = nodes.item(0).getTextContent(); + + nodes = element.getElementsByTagName("name"); + if (nodes != null) + icons = MantleClientRegistry.getRecipeIcons(nodes.item(0).getTextContent()); + + nodes = element.getElementsByTagName("size"); + if (nodes != null) + size = nodes.item(0).getTextContent(); + } + + @Override + public void renderContentLayer (int localWidth, int localHeight) + { + if (size.equals("two")) + drawCraftingPage(text, icons, 2, localWidth, localHeight + 12); + if (size.equals("three")) + drawCraftingPage(text, icons, 3, localWidth + (side != 1 ? 6 : 0), localHeight + 12); + } + + public void drawCraftingPage (String info, ItemStack[] icons, int recipeSize, int localWidth, int localHeight) + { + if (info != null) + manual.fonts.drawString("\u00a7n" + info, localWidth + 50, localHeight + 4, 0); + + GL11.glScalef(2f, 2f, 2f); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + RenderHelper.enableGUIStandardItemLighting(); + manual.renderitem.zLevel = 100; + + if (recipeSize == 2) + { + manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[0], (localWidth + 126) / 2, (localHeight + 68) / 2); + if (icons[0].stackSize > 1) + manual.renderitem.renderItemOverlayIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[0], (localWidth + 126) / 2, (localHeight + 68) / 2, String.valueOf(icons[0].stackSize)); + for (int i = 0; i < icons.length - 1; i++) + { + if (icons[i + 1] != null) + manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[i + 1], (localWidth + 14 + 36 * (i % 2)) / 2, (localHeight + 36 * (i / 2) + 52) / 2); + } + } + + if (recipeSize == 3) + { + manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[0], (localWidth + 138) / 2, (localHeight + 70) / 2); + if (icons[0].stackSize > 1) + manual.renderitem.renderItemOverlayIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[0], (localWidth + 126) / 2, (localHeight + 68) / 2, String.valueOf(icons[0].stackSize)); + for (int i = 0; i < icons.length - 1; i++) + { + if (icons[i + 1] != null) + manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[i + 1], (localWidth - 2 + 36 * (i % 3)) / 2, (localHeight + 36 * (i / 3) + 34) / 2); + } + } + + manual.renderitem.zLevel = 0; + GL11.glScalef(0.5F, 0.5F, 0.5F); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + } + + public void renderBackgroundLayer (int localwidth, int localheight) + { + if (size.equals("two")) + drawBackground(2, localwidth, localheight + 12); + + if (size.equals("three")) + drawBackground(3, localwidth + (side != 1 ? 6 : 0), localheight + 12); + } + + private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/bookcrafting.png"); + + public void drawBackground (int size, int localWidth, int localHeight) + { + manual.getMC().getTextureManager().bindTexture(background); + if (size == 2) + manual.drawTexturedModalRect(localWidth + 8, localHeight + 46, 0, 116, 154, 78); + if (size == 3) + manual.drawTexturedModalRect(localWidth - 8, localHeight + 28, 0, 0, 183, 114); + } + +} diff --git a/src/mantle/client/pages/FurnacePage.java b/src/mantle/client/pages/FurnacePage.java new file mode 100644 index 0000000..805f6f2 --- /dev/null +++ b/src/mantle/client/pages/FurnacePage.java @@ -0,0 +1,62 @@ +package mantle.client.pages; + +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import mantle.lib.client.MantleClientRegistry; + +public class FurnacePage extends BookPage +{ + String text; + ItemStack[] icons; + + @Override + public void readPageFromXML (Element element) + { + NodeList nodes = element.getElementsByTagName("text"); + if (nodes != null) + text = nodes.item(0).getTextContent(); + + nodes = element.getElementsByTagName("recipe"); + if (nodes != null) + icons = MantleClientRegistry.getRecipeIcons(nodes.item(0).getTextContent()); + } + + @Override + public void renderContentLayer (int localWidth, int localHeight) + { + if (text != null) + manual.fonts.drawString("\u00a7n" + text, localWidth + 50, localHeight + 4, 0); + + GL11.glScalef(2f, 2f, 2f); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + RenderHelper.enableGUIStandardItemLighting(); + manual.renderitem.zLevel = 100; + + manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, MantleClientRegistry.getManualIcon("coal"), (localWidth + 38) / 2, (localHeight + 110) / 2); + manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[0], (localWidth + 106) / 2, (localHeight + 74) / 2); + manual.renderitem.renderItemAndEffectIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[1], (localWidth + 38) / 2, (localHeight + 38) / 2); + + if (icons[0].stackSize > 1) + manual.renderitem.renderItemOverlayIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[0], (localWidth + 106) / 2, (localHeight + 74) / 2, String.valueOf(icons[0].stackSize)); + + manual.renderitem.zLevel = 0; + GL11.glScalef(0.5F, 0.5F, 0.5F); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + } + + private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/bookfurnace.png"); + + public void renderBackgroundLayer (int localWidth, int localHeight) + { + manual.getMC().getTextureManager().bindTexture(background); + manual.drawTexturedModalRect(localWidth + 32, localHeight + 32, 0, 0, 111, 114); + } +} diff --git a/src/mantle/client/pages/PicturePage.java b/src/mantle/client/pages/PicturePage.java new file mode 100644 index 0000000..d2d635d --- /dev/null +++ b/src/mantle/client/pages/PicturePage.java @@ -0,0 +1,41 @@ +package mantle.client.pages; + +import net.minecraft.util.ResourceLocation; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class PicturePage extends BookPage +{ + String text; + String location; + + @Override + public void readPageFromXML (Element element) + { + NodeList nodes = element.getElementsByTagName("text"); + if (nodes != null) + text = nodes.item(0).getTextContent(); + + nodes = element.getElementsByTagName("location"); + if (nodes != null) + location = nodes.item(0).getTextContent(); + + background = new ResourceLocation(location); + } + + @Override + public void renderContentLayer (int localWidth, int localHeight) + { + manual.fonts.drawSplitString(text, localWidth + 8, localHeight, 178, 0); + } + + ResourceLocation background; + + public void renderBackgroundLayer (int localWidth, int localHeight) + { + manual.getMC().getTextureManager().bindTexture(background); + //manual.getMC().renderEngine.bindTexture(location); + manual.drawTexturedModalRect(localWidth, localHeight + 12, 0, 0, 170, 144); + } +} diff --git a/src/mantle/client/pages/SectionPage.java b/src/mantle/client/pages/SectionPage.java new file mode 100644 index 0000000..c8badb4 --- /dev/null +++ b/src/mantle/client/pages/SectionPage.java @@ -0,0 +1,29 @@ +package mantle.client.pages; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class SectionPage extends BookPage +{ + String title; + String body; + + @Override + public void readPageFromXML (Element element) + { + NodeList nodes = element.getElementsByTagName("title"); + if (nodes != null) + title = nodes.item(0).getTextContent(); + + nodes = element.getElementsByTagName("text"); + if (nodes != null) + body = nodes.item(0).getTextContent(); + } + + @Override + public void renderContentLayer (int localWidth, int localHeight) + { + manual.fonts.drawSplitString("\u00a7n" + title, localWidth + 70, localHeight + 4, 178, 0); + manual.fonts.drawSplitString(body, localWidth, localHeight + 16, 190, 0); + } +} diff --git a/src/mantle/client/pages/SidebarPage.java b/src/mantle/client/pages/SidebarPage.java new file mode 100644 index 0000000..d44babe --- /dev/null +++ b/src/mantle/client/pages/SidebarPage.java @@ -0,0 +1,56 @@ +package mantle.client.pages; + +import mantle.lib.client.MantleClientRegistry; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.ItemStack; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class SidebarPage extends BookPage +{ + String text; + String[] iconText; + ItemStack[] icons; + + @Override + public void readPageFromXML (Element element) + { + NodeList nodes = element.getElementsByTagName("text"); + if (nodes != null) + text = nodes.item(0).getTextContent(); + + nodes = element.getElementsByTagName("item"); + iconText = new String[nodes.getLength()]; + icons = new ItemStack[nodes.getLength()]; + for (int i = 0; i < nodes.getLength(); i++) + { + NodeList children = nodes.item(i).getChildNodes(); + iconText[i] = children.item(1).getTextContent(); + icons[i] = MantleClientRegistry.getManualIcon(children.item(3).getTextContent()); + } + } + + @Override + public void renderContentLayer (int localWidth, int localHeight) + { + manual.fonts.drawSplitString(text, localWidth, localHeight, 178, 0); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + RenderHelper.enableGUIStandardItemLighting(); + manual.renderitem.zLevel = 100; + int offset = text.length() / 4 + 10; + for (int i = 0; i < icons.length; i++) + { + manual.renderitem.renderItemIntoGUI(manual.fonts, manual.getMC().renderEngine, icons[i], localWidth + 8, localHeight + 18 * i + offset); + int yOffset = 39; + if (iconText[i].length() > 40) + yOffset = 34; + manual.fonts.drawSplitString(iconText[i], localWidth + 30, localHeight + 18 * i + offset, 140, 0); + } + manual.renderitem.zLevel = 0; + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + } +} diff --git a/src/mantle/client/pages/TextPage.java b/src/mantle/client/pages/TextPage.java new file mode 100644 index 0000000..51a2d16 --- /dev/null +++ b/src/mantle/client/pages/TextPage.java @@ -0,0 +1,23 @@ +package mantle.client.pages; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class TextPage extends BookPage +{ + String text; + + @Override + public void readPageFromXML (Element element) + { + NodeList nodes = element.getElementsByTagName("text"); + if (nodes != null) + text = nodes.item(0).getTextContent(); + } + + @Override + public void renderContentLayer (int localWidth, int localHeight) + { + manual.fonts.drawSplitString(text, localWidth, localHeight, 178, 0); + } +} diff --git a/src/mantle/client/pages/TitlePage.java b/src/mantle/client/pages/TitlePage.java new file mode 100644 index 0000000..a8a8f98 --- /dev/null +++ b/src/mantle/client/pages/TitlePage.java @@ -0,0 +1,23 @@ +package mantle.client.pages; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class TitlePage extends BookPage +{ + String text; + + @Override + public void readPageFromXML (Element element) + { + NodeList nodes = element.getElementsByTagName("text"); + if (nodes != null) + text = nodes.item(0).getTextContent(); + } + + @Override + public void renderContentLayer (int localWidth, int localHeight) + { + manual.fonts.drawSplitString(text, localWidth, localHeight, 178, 0); + } +} diff --git a/src/mantle/common/MProxyCommon.java b/src/mantle/common/MProxyCommon.java new file mode 100644 index 0000000..e87515f --- /dev/null +++ b/src/mantle/common/MProxyCommon.java @@ -0,0 +1,6 @@ +package mantle.common; + +public class MProxyCommon +{ + +} diff --git a/src/mantle/lib/client/MantleClientRegistry.java b/src/mantle/lib/client/MantleClientRegistry.java new file mode 100644 index 0000000..433b86d --- /dev/null +++ b/src/mantle/lib/client/MantleClientRegistry.java @@ -0,0 +1,57 @@ +package mantle.lib.client; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class MantleClientRegistry +{ + public static Map manualIcons = new HashMap(); + public static Map recipeIcons = new HashMap(); + public static ItemStack defaultStack = new ItemStack(Item.ingotIron); + + public static void registerManualIcon (String name, ItemStack stack) + { + manualIcons.put(name, stack); + } + + public static ItemStack getManualIcon (String textContent) + { + ItemStack stack = manualIcons.get(textContent); + if (stack != null) + return stack; + return defaultStack; + } + + public static void registerManualSmallRecipe (String name, ItemStack output, ItemStack... stacks) + { + ItemStack[] recipe = new ItemStack[5]; + recipe[0] = output; + System.arraycopy(stacks, 0, recipe, 1, 4); + recipeIcons.put(name, recipe); + } + + public static void registerManualLargeRecipe (String name, ItemStack output, ItemStack... stacks) + { + ItemStack[] recipe = new ItemStack[10]; + recipe[0] = output; + System.arraycopy(stacks, 0, recipe, 1, 9); + recipeIcons.put(name, recipe); + } + + public static void registerManualFurnaceRecipe (String name, ItemStack output, ItemStack input) + { + ItemStack[] recipe = new ItemStack[2]; + recipe[0] = output; + recipe[1] = input; + recipeIcons.put(name, recipe); + } + + public static ItemStack[] getRecipeIcons (String recipeName) + { + return recipeIcons.get(recipeName); + } + +}