Jump to content

Lenardjee

Members
  • Posts

    18
  • Joined

  • Last visited

Everything posted by Lenardjee

  1. man, you are a hero! I have searched for this for ages
  2. public class Point3d { public double x, y, z; public Point3d(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } public double distance(Point3d p) { return Math.sqrt(Math.pow(p.z - this.z, 2) + Math.pow(Math.sqrt(Math.pow(p.x - this.x, 2) + Math.pow(p.y - this.y, 2)), 2)); } /**Rotates the point around the given {@code rotationCentre} * with the given {@code jaw} and {@code pitch} * The vertical rotation ({@code pitch}) will be done after the horizontal rotation ({@code jaw}), * over the x axis that is first rotated over the y axis by {@code pitch} radians. * <p> * @param rotationCentre - what does it say? * @param pitch - the vertical rotation angle * @param jaw - the horizontal rotation angle * @return the Point3d that is calculated to be the position of this point after the rotations * and changes the location of this point to the return value */ public Point3d rotate(Point3d rotationCentre, double pitch, double jaw) { double d = this.distance(rotationCentre); Point3d firstRotationPoint = new Point3d( rotationCentre.x + (d * Math.cos(jaw)), this.y, rotationCentre.z + (d * Math.sin(jaw)) ); this.x = rotationCentre.x + (firstRotationPoint.x - rotationCentre.x) * Math.cos(pitch); this.y = rotationCentre.y + (d * Math.sin(pitch)); this.z = rotationCentre.z + (firstRotationPoint.z - rotationCentre.z) * Math.cos(pitch); return new Point3d( rotationCentre.x + (firstRotationPoint.x - rotationCentre.x) * Math.cos(pitch), rotationCentre.y + (d * Math.sin(pitch)), rotationCentre.z + (firstRotationPoint.z - rotationCentre.z) * Math.cos(pitch) ); } } Ok, this is really only useful for calculating the position of 1 of the rotation points, that is, if and only if the dragon hasn't rotated their entire body. I'm working on a formula to make it relative to previous rotations of parent parts, but that might take some time, I'll try my best to get it done.
  3. Hold on, baking some formulas here, will be done in an hour or so EDIT: probably a bit longer
  4. how do you create the dragon model? can I see the code that creates it?
  5. Yeah, now that I looked up the cause of the error in GuiTextField String s = this.fontRenderer.trimStringToWidth(this.text.substring(this.lineScrollOffset), this.getWidth()); It seems that the problem is that lineScrollOffset or this.getWidth() or this.text is null. You can debug that by putting System.out.println("textbox.text : " + textbox.getText()); System.out.println("lineScrollOffset : " + textbox.getWidth()); before line 65 in your class, if both of these don't return null, then lineScrollOffset must be null, or there is something in hte trimStringToWidth method that makes it return null
  6. Have you tried initialising the texfield inside the init method? I've had quite some issues with initialization of variables myself too...
  7. I'm not sure if this will help you, but you can at least try. I've had this problem myself too, and I'm not quite sure what fixed it, but I think it might be the way that you do the drawScreen(). Try this: 1. Backup that entire class in case I mess everything up by letting you do the next 3 steps 2. Let your class extend the GuiContainer class 3. Fix any errors that step 2 causes 4. remove this part: public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); this.drawCenteredString(this.fontRenderer, I18n.format("sign.edit"),this.width / 2, 40, 16777215); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.pushMatrix(); GlStateManager.translate((float)(this.width / 2), 0.0F, 50.0F); GlStateManager.scale(-93.75F, -93.75F, -93.75F); GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); GlStateManager.popMatrix(); super.drawScreen(mouseX, mouseY, partialTicks); } 5. add this to the class: @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { //Whatever you want to draw goes here } I hope this was helpful, Lenardjee
  8. Ok, I found out how to get the correct TextureAtlasSprite. the path variable should have been like this: String path = block.getRegistryName().getResourceDomain() + ":blocks/" + block.getRegistryName().getResourcePath(); but the problem is that a lot of blocks have block properties such as sides etc.. So, when I try to do this on sandstone, I have to add "_side" to the end to be able to get the TextureAtlasSprite and the problem is that when there are other mods active, the blocks from that mod will probably have all sorts of properties, and I don't know how to get around that problem, because I want to be able to display the chiseled block just the same as the normal block, but then with parts of the block changed or removed.
  9. Hey everyone, In my previous post I had a question about rendering a JSON model using a TESR, but I was told that using a JSON model would be a very inefficient way of doing it. The situation is this: I have a block with a TileEntity, and the blocks is like a block from chisel and bits, so it can change shape. The shape is made from a ArrayList<Obj> where Obj is a class extending AxisAlignedBB with the only change being that it has a field for the blockstate and that a blockstate must be passed in into the constructor. I've done that to be able to retrieve the texture for each of the pieces that the block is constructed with. Now what I want to do is render the block using a TESR, but I can't figure out how to get the texture specific for that blockstate from the TextureMap. This is my code so far: @Override public void render(TileEntityMiniBlock te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { // System.out.println("render"); renderBlock(te, x, y, z, partialTicks, destroyStage, alpha); } public void renderBlock(TileEntityMiniBlock te1, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { // System.out.println("renderBlock"); if(Minecraft.getMinecraft().getIntegratedServer().getWorld(Minecraft.getMinecraft().world.provider.getDimension()).getTileEntity(te1.getPos()) != null) { if(Minecraft.getMinecraft().getIntegratedServer().getWorld(Minecraft.getMinecraft().world.provider.getDimension()).getTileEntity(te1.getPos()) instanceof TileEntityMiniBlock) { te = (TileEntityMiniBlock) Minecraft.getMinecraft().getIntegratedServer().getWorld(Minecraft.getMinecraft().world.provider.getDimension()).getTileEntity(te1.getPos()); BufferBuilder ver = Tessellator.getInstance().getBuffer(); ArrayList<Obj> objs = te.objs; for(int i = 0; i < objs.size(); i++) { Obj o = objs.get(i); ResourceLocation n = o.blockType.getBlock().getRegistryName(); GlStateManager.pushMatrix(); ver.reset(); // GlStateManager.enableLighting(); RenderHelper.enableStandardItemLighting(); GlStateManager.enableRescaleNormal(); GlStateManager.enableBlend(); ver.setTranslation(x, y, z); Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); String path = o.blockType.getBlock().getRegistryName().getResourceDomain() + ":textures/block/" + o.blockType.getBlock().getRegistryName().getResourcePath(); // System.out.println(path); path = "minecraft:textures/blocks/stone.png"; // float minU = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getInterpolatedU(o.minZ * 16.0); // float minV = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getInterpolatedV(16.0 - (o.maxZ * 16.0)); // float maxU = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getInterpolatedU(16.0 - (o.minZ * 16.0)); // float maxV = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getInterpolatedV(o.maxZ * 16.0); float minU = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getMinU(); float minV = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getMinV(); float maxU = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getMaxU(); float maxV = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getMaxV(); // System.out.println(minU); // System.out.println(minV); // System.out.println(maxU); // System.out.println(maxV); // Minecraft.getMinecraft().getTextureManager().bindTexture(o.blockType.getBlock().getRegistryName()); int posU = 0; int posV = 0; ver.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); // ver.pos(o.minX, o.minY, o.maxZ).tex(1.0 / 32.0 * (posU + o.maxZ), 1.0 / 32.0 * (posV + (16 - o.minY))).endVertex(); // ver.pos(o.minX, o.maxY, o.maxZ).tex(1.0 / 32.0 * (posU + o.maxZ), 1.0 / 32.0 * (posV + (16 - o.maxY))).endVertex(); // ver.pos(o.minX, o.maxY, o.minZ).tex(1.0 / 32.0 * (posU + o.minZ), 1.0 / 32.0 * (posV + (16 - o.maxY))).endVertex(); // ver.pos(o.minX, o.minY, o.minZ).tex(1.0 / 32.0 * (posU + o.minZ), 1.0 / 32.0 * (posV + (16 - o.minY))).endVertex(); ver.pos(o.minX, o.minY, o.maxZ).tex(maxU, maxV).endVertex(); ver.pos(o.minX, o.maxY, o.maxZ).tex(maxU, minV).endVertex(); ver.pos(o.minX, o.maxY, o.minZ).tex(minU, minV).endVertex(); ver.pos(o.minX, o.minY, o.minZ).tex(minU, maxV).endVertex(); // ver.pos(o.minX, o.minY, o.maxZ).tex(0.34375, 0.84375).endVertex(); // ver.pos(o.minX, o.maxY, o.maxZ).tex(0.34375, 0.8125).endVertex(); // ver.pos(o.minX, o.maxY, o.minZ).tex(0.3125, 0.8125).endVertex(); // ver.pos(o.minX, o.minY, o.minZ).tex(0.3125, 0.84375).endVertex(); // ver.pos(o.minX, o.minY, o.maxZ).tex(0.1, 0.11).endVertex(); // ver.pos(o.minX, o.maxY, o.maxZ).tex(0.1, 0.1).endVertex(); // ver.pos(o.minX, o.maxY, o.minZ).tex(0.11, 0.1).endVertex(); // ver.pos(o.minX, o.minY, o.minZ).tex(0.11, 0.11).endVertex(); ver.endVertex(); Tessellator.getInstance().draw(); RenderHelper.enableStandardItemLighting(); GlStateManager.disableRescaleNormal(); GlStateManager.disableBlend(); GlStateManager.popMatrix(); } } } As you can see, I've tried quite some different ways of rendering the textures, but I am still not getting what I want. What I can do with this code is render a part of the block texture map onto my block (although it glitches quite a bit) but I don't know how to retrieve the Icon for the blockstate. If I could get the Icon name, which is a string, then I could use these lines of code to retrieve the U and V of the icon on the texture map: float minU = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getMinU(); float minV = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getMinV(); float maxU = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getMaxU(); float maxV = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(path).getMaxV(); So, if you have any idea on how to retrieve the U and V coordinates based on a blockstate, please tell me, because I just can't figure it out. Thanks in advance, Lenardjee
  10. And this is the code in my TESR: @Override public void render(TileEntityMiniBlock te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { // System.out.println("render"); renderBlock(te, x, y, z, partialTicks, destroyStage, alpha); } public void renderBlock(TileEntityMiniBlock te1, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { // System.out.println("renderBlock"); if(Minecraft.getMinecraft().getIntegratedServer().getWorld(Minecraft.getMinecraft().world.provider.getDimension()).getTileEntity(te1.getPos()) != null) { if(Minecraft.getMinecraft().getIntegratedServer().getWorld(Minecraft.getMinecraft().world.provider.getDimension()).getTileEntity(te1.getPos()) instanceof TileEntityMiniBlock) { te = (TileEntityMiniBlock) Minecraft.getMinecraft().getIntegratedServer().getWorld(Minecraft.getMinecraft().world.provider.getDimension()).getTileEntity(te1.getPos()); BufferBuilder ver = Tessellator.getInstance().getBuffer(); ArrayList<Obj> objs = te.objs; for(int i = 0; i < objs.size(); i++) { // GlStateManager.pushMatrix(); // GlStateManager.enableRescaleNormal(); // GlStateManager.enableBlend(); ver.setTranslation(x, y, z); ver.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); // ver.pos(objs.get(i).maxX, objs.get(i).minY + 1.0, objs.get(i).minZ).tex(0.3, 0.1).color(200, 0, 200, 100).endVertex(); // ver.pos(objs.get(i).maxX, objs.get(i).maxY + 1.0, objs.get(i).minZ).tex(0.3, 0.0).color(200, 0, 200, 100).endVertex(); // ver.pos(objs.get(i).minX, objs.get(i).maxY + 1.0, objs.get(i).minZ).tex(0.2, 0.0).color(200, 0, 200, 100).endVertex(); // ver.pos(objs.get(i).minX, objs.get(i).minY + 1.0, objs.get(i).minZ).tex(0.2, 0.1).color(200, 0, 200, 100).endVertex(); Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); // Minecraft.getMinecraft()TESRMiniBlock.get ver.pos(0.0f, 1.0f, 20.0f).tex( 0.1 / 3.125 * 20, 0.1 / 3.125 * 20).normal((float) x, (float) y, (float) z).endVertex(); ver.pos(0.0f, 21.0f, 20.0f).tex(0.1 / 3.125 * 20, 0.1 / 3.125 * 0).normal((float) x, (float) y, (float) z).endVertex(); ver.pos(0.0f, 21.0f, 0.0f).tex( 0.1 / 3.125 * 0, 0.1 / 3.125 * 0).normal((float) x, (float) y, (float) z).endVertex(); ver.pos(0.0f, 1.0f, 0.0f).tex( 0.1 / 3.125 * 0, 0.1 / 3.125 * 20).normal((float) x, (float) y, (float) z).endVertex(); ver.endVertex(); Tessellator.getInstance().draw(); ver.reset(); // GlStateManager.disableRescaleNormal(); // GlStateManager.disableBlend(); // GlStateManager.popMatrix(); } } }
  11. Ok, I understand that, but now I am trying to use vertexes to draw some textures and it kind of works, but there are a lot of weird things going on now, such as mobs showing up in strange locations, with parts of their body just flying around and moving weirdly and items in my inventory shift a few pixels sometimes... I don't know how to prevent that from happening... EDIT the selectedBoundingBox of blocks is moving around as well
  12. Ok, I think I understand what I have to do, but I do not understand how to do these quads. The last 4 hours I've been trying to find an tutorial on how to use them to draw boxes with a certain texture, but I just can't get it to work. this is the code in my TESR as far as it is now: public void render(TileEntityMiniBlock te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { GlStateManager.enableRescaleNormal(); GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1f); GlStateManager.enableBlend(); RenderHelper.enableStandardItemLighting(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); GlStateManager.pushMatrix(); te = (TileEntityMiniBlock) Minecraft.getMinecraft().getIntegratedServer().getWorld(Minecraft.getMinecraft().world.provider.getDimension()).getTileEntity(te1.getPos()); BufferBuilder ver = Tessellator.getInstance().getBuffer(); ArrayList<Obj> objs = te.objs; for(int i = 0; i < objs.size(); i++) { ver.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); ver.pos(objs.get(i).minX, objs.get(i).minY + 1.0, objs.get(i).minZ).tex(16, 16).color(200, 0, 200, 100).endVertex(); ver.pos(objs.get(i).maxX, objs.get(i).maxY + 1.0, objs.get(i).maxZ).tex(16, 16).color(200, 0, 200, 100).endVertex(); // ver.finishDrawing(); Tessellator.getInstance().draw(); } GlStateManager.popMatrix(); GlStateManager.disableRescaleNormal(); GlStateManager.disableBlend(); } By the way, I have not a single idea on how to give it a texture either...
  13. Yeah, I get that, but how do I 'render' these calculations? What I have is an accurate ArrayList<Obj> where Obj extends AxisAlignedBB with as only change that you have to pass a IBlockState into the constructer which I want to use to get the texture of each small piece of the block. Patches of bits the same type of block that are next to each other are being combined into 1 Obj, so after each change of the block the ArrayList<Obj> is changed so that it contains all the small pieces of the block. I can reach that list from the TESR and so retrieve the individual pieces that it should render. The only problem is that I don't know how to render it, let alone what the most efficient way of rendering is.
  14. Soo, what should I do then?
  15. Well, that is because I am trying to recreate the chisel and bits mod, and I have all the logic set up already. Only the displaying of the different bits doesn't work yet. I even made a function that changes the json file when the a piece is added or removed from the block.
  16. Hey guys, I am trying to render a model of a block, which I want to retrieve directly from the json file which is located in the normal location for block models for my mod. I don't want to have it go through the model registry, because the model must be dynamic, for it changes while the game is running, and I don't want to have to reload all the resources every time that that one model has to change. I think there should be other ways to do this rather then using a TESR, but I don't know any of them, so if you know another, possibly simpler way, please tell me. Thanks in advance, Lenardjee
  17. I know that it is a big project, but I have done all the hard work already. I have everything set up to make the parts of the block using AxisAlignedBB's and the only thing I have left to do is to display the block. The problem is: I don't know how to use IBakedModel (neither do I know if I should even be using it). And: does that mean that using IBakedModel for this is not a problem now? Furthermore, how do I update the block model while the game is running? How would that work without having to reload the texturepacks everytime I make a change to the model? I can do make mods of some types, but there are parts in forge modding that I just don't quite get yet.
  18. Hey guys, I am fairly new to modding and at the moment, I am trying to make the 'chisel and bits' mod, as kind of a challenge. So, I have done quite a lot already, what I now need to do is render every part of the chiseled block with the correct texture. the problem is that I have no idea what the best way is to render blocks, with the only information being the AxisAlignedBB's and the textures for each component of the block. I thought a TESR would be a good idea, so this is my TESR class as far as it is now in which I just tried to render a model which wasn't registered yet: package com.extraBlocks.block.miniBlock; import java.util.List; import org.lwjgl.opengl.GL11; import com.extraBlocks.Main; import com.extraBlocks.item.ModItems; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockRendererDispatcher; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.client.renderer.block.model.ModelManager; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.IModel; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.ModelLoaderRegistry; public class TESRMiniBlock extends TileEntitySpecialRenderer<TileEntityMiniBlock> { TileEntityMiniBlock te = null; @Override public void render(TileEntityMiniBlock te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { renderBlock(te, x, y, z, partialTicks, destroyStage, alpha); } public void renderBlock(TileEntityMiniBlock te1, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { te = (TileEntityMiniBlock) Minecraft.getMinecraft().getIntegratedServer().getWorld(Minecraft.getMinecraft().world.provider.getDimension()).getTileEntity(te1.getPos()); ItemStack stack = te.inventory.getStackInSlot(0); if (!stack.isEmpty()) { BlockRendererDispatcher r = Minecraft.getMinecraft().getBlockRendererDispatcher(); Tessellator tes = Tessellator.getInstance(); GlStateManager.enableRescaleNormal(); GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1f); GlStateManager.enableBlend(); RenderHelper.enableStandardItemLighting(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); GlStateManager.translate(x + 0.5, y + 0.5, z + 0.5); IBakedModel model0 = null; try { // model0 = ModelLoaderRegistry.getModel(new ResourceLocation(Main.MODID, "block/tinyblock")); model0 = r.getBlockModelShapes().getModelManager().getModel(new ModelResourceLocation(Main.MODID + ":blocks/shadow_ore", "normal")); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if(model0 != null) { r.getBlockModelRenderer().renderModelBrightnessColor(model0, 1.0F, 1.0F, 1.0F, 1.0F); } Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); Minecraft.getMinecraft().getRenderItem().renderItem(stack, model0); GlStateManager.disableRescaleNormal(); GlStateManager.disableBlend(); } } } Now, as you can probably tell, I don't quit know how to do this, so any help is greatly appreciated.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.