Jump to content

[SOLVED][1.7.10] Custom model not rendering


espda

Recommended Posts

Hi fellow Minecrafters!

 

As you can probably tell by my post count, I'm pretty new to modding Minecraft. I have a reasonable knowledge of Java and OOP in general, though nowhere near professional level.

 

I've had good success with creating items, standard blocks, recopies and creating custom blocks.

 

I'm now trying to create a block with a custom model, but I'm running into some trouble. My block appears in creative, can be placed and has a collision box, but stubbornly refuses to render. I simply get a empty box where the model should be. I assume it is a problem with either my model or my custom renderer. I've replaced my model with a simple cube, to see if it was the model file, but it still won't work. I've poured over the tutorial I've been following several times, but as far as I can tell, I'm doing it right. I know I'm probably making a stupid mistake somewhere, but I just can't seem to find it.

 

If someone out there wouldn't mind giving me a hand, could you take a look at my code and let me know what I'm doing wrong? I'd really appreciate it.

 

package emptyskies.testblock;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class TestBlockBlock extends BlockContainer {

        //Treat it like a normal block here. The Block Bounds are a good idea - the first three are X Y and Z of the botton-left corner,
        //And the second three are the top-right corner.
        public TestBlockBlock(Block TrafficLight, Material iron) 
        {
        	    super(Material.iron);
         
        	    this.setCreativeTab(CreativeTabs.tabMisc);
                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                this.setBlockName("TestBlock");
                this.setHardness(10.0F); 				//Time to break. Stone = 1.5F, Obsidian = 50.0F
                this.setResistance(10.F); 				//Explosion resistance. Stone = 10.0F, Obsidian = 2000.0F
                this.setHarvestLevel("Pickaxe", 0); 	//Effective tool and needed level. Wood = 0, Stone = 1, Iron = 2, Diamond = 3
                this.setTickRandomly(false); 			//Does it get random updates? true / false
                this.setStepSound(soundTypeGravel);		//Sets how it sounds when you step on it
                
        }

       
        //You don't want the normal render type, or it wont render properly.
        @Override
        public int getRenderType() {
                return -1;
        }
       
        //It's not an opaque cube, so you need this.
        @Override
        public boolean isOpaqueCube() {
                return false;
        }
       
        //It's not a normal block, so you need this too.
        public boolean renderAsNormalBlock() {
                return false;
        }

	@Override
	public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
		// TODO Auto-generated method stub
		return null;
	}

}

 

Block Entity: -Seems silly to put this in, but what the hey

 

package emptyskies.testblock;

import net.minecraft.tileentity.TileEntity;

public class TestBlockEntity extends TileEntity {

}

 

Model:

 

package emptyskies.testblock;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class TestBlockModel extends ModelBase
{
  //fields
    ModelRenderer Shape1;
  
  public TestBlockModel()
  {
    textureWidth = 64;
    textureHeight = 64;
    
      Shape1 = new ModelRenderer(this, 0, 0);
      Shape1.addBox(0F, 0F, 0F, 10, 10, 10);
      Shape1.setRotationPoint(0F, 0F, 0F);
      Shape1.setTextureSize(64, 64);
      Shape1.mirror = true;
      setRotation(Shape1, 0F, 0F, 0F);
  }
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    Shape1.render(f5);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  }

}

 

 

Renderer:

package emptyskies.testblock;

import org.lwjgl.opengl.GL11;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class TestBlockRenderer extends TileEntitySpecialRenderer {
       
        private final TestBlockModel model;
       
        public TestBlockRenderer() {
                this.model = new TestBlockModel();
        }
       
        @Override
        public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
                GL11.glPushMatrix();
                GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
                ResourceLocation textures = (new ResourceLocation("emptyskies:textures/blocks/testBlock.png"));
                Minecraft.getMinecraft().renderEngine.bindTexture(textures);

                GL11.glPushMatrix();
                GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
                this.model.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
                GL11.glPopMatrix();
                GL11.glPopMatrix();
        }
}

 

Thanks for any help you can provide. I apologize in advance if I'm doing something really stupid.

Link to comment
Share on other sites

I am assuming that the problem is that you didn't revert with GL11.popMatrix here:

 

                GL11.glPushMatrix();
                GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
                ResourceLocation textures = (new ResourceLocation("emptyskies:textures/blocks/testBlock.png"));
                Minecraft.getMinecraft().renderEngine.bindTexture(textures);

 

You put 2x GL11.PopMatrix in the end but that doesn't count for this first one.

Remove one of your popmatrix in the second part of your renderer. Like this:

                GL11.glPushMatrix();
                GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
                ResourceLocation textures = (new ResourceLocation("emptyskies:textures/blocks/testBlock.png"));
                Minecraft.getMinecraft().renderEngine.bindTexture(textures);
                GL11.glPopMatrix();

                GL11.glPushMatrix();
                GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
                this.model.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
                GL11.glPopMatrix();

 

I may be wrong since i am not experienced with GL11 stuff but from tesselating i know that if your start it you must close it.

               

Link to comment
Share on other sites

Thanks a lot for the quick response.

 

I fixed the error you pointed out, but it doesn't seem to have corrected the issue. Still, thanks for pointing it out. You probably just prevented me from having another problem down the line.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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