Jump to content

Custom model with transparent textures?


Enkey

Recommended Posts

So I made a lamp:

ZzZlpTq.png

 

And I would like to make the glass (the light blue thing) transparent (there is a candle behind it). Do you know how to do that?

 

Code:

Model class:

package morelights.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;

public class ModelOldWallLamp extends ModelBase
{
  //fields
    ModelRenderer Glass1;
    ModelRenderer Glass2;
    ModelRenderer Glass3;
    ModelRenderer Glass4;
    ModelRenderer Candle;
    ModelRenderer Body4;
    ModelRenderer Body2;
    ModelRenderer Body3;
    ModelRenderer Body5;
    ModelRenderer Body6;
    ModelRenderer Body7;
    ModelRenderer Body8;
    ModelRenderer Body9;
    ModelRenderer Shape1;
    ModelRenderer Shape2;
    ModelRenderer Shape3;
    ModelRenderer Shape4;
    ModelRenderer Shape5;
    ModelRenderer Shape6;
    ModelRenderer Side1;
    ModelRenderer Side2;
    ModelRenderer Side3;
    ModelRenderer Side4;
    ModelRenderer Side5;
    ModelRenderer Side6;
    ModelRenderer Side7;
  
  public ModelOldWallLamp()
  {
    textureWidth = 64;
    textureHeight = 32;
    
    	
    
    Glass1 = new ModelRenderer(this, 49, -3);
    Glass1.addBox(1.6F, 0F, -1.5F, 0, 6, 3);
    Glass1.setRotationPoint(0F, 13F, 0F);
    Glass1.setTextureSize(64, 32);
    Glass1.mirror = true;
    setRotation(Glass1, 0F, 0F, 0F);
    Glass2 = new ModelRenderer(this, 49, -3);
    Glass2.addBox(-1.6F, 0F, -1.5F, 0, 6, 3);
    Glass2.setRotationPoint(0F, 13F, 0F);
    Glass2.setTextureSize(64, 32);
    Glass2.mirror = true;
    setRotation(Glass2, 0F, 0F, 0F);
    Glass3 = new ModelRenderer(this, 49, 0);
    Glass3.addBox(-1.5F, 0F, -1.6F, 3, 6, 0);
    Glass3.setRotationPoint(0F, 13F, 0F);
    Glass3.setTextureSize(64, 32);
    Glass3.mirror = true;
    setRotation(Glass3, 0F, 0F, 0F);
    Glass4 = new ModelRenderer(this, 49, 0);
    Glass4.addBox(-1.5F, 0F, 1.6F, 3, 6, 0);
    Glass4.setRotationPoint(0F, 13F, 0F);
    Glass4.setTextureSize(64, 32);
    Glass4.mirror = true;
    setRotation(Glass4, 0F, 0F, 0F);
    Candle = new ModelRenderer(this, 45, 0);
    Candle.addBox(-0.5F, 0F, -0.5F, 1, 3, 1);
    Candle.setRotationPoint(0F, 16F, 0F);
    Candle.setTextureSize(64, 32);
    Candle.mirror = true;
    setRotation(Candle, 0F, 0F, 0F);
    Body4 = new ModelRenderer(this, 0, 4);
    Body4.addBox(-2F, -1.5F, -2F, 4, 1, 4);
    Body4.setRotationPoint(0F, 21F, 0F);
    Body4.setTextureSize(64, 32);
    Body4.mirror = true;
    setRotation(Body4, 0F, 0F, 0F);
    Body2 = new ModelRenderer(this, 0, 0);
    Body2.addBox(-1F, 0.5F, -1F, 2, 1, 2);
    Body2.setRotationPoint(0F, 20F, 0F);
    Body2.setTextureSize(64, 32);
    Body2.mirror = true;
    setRotation(Body2, 0F, 0F, 0F);
    Body3 = new ModelRenderer(this, 8, 0);
    Body3.addBox(-1.5F, 0F, -1.5F, 3, 1, 3);
    Body3.setRotationPoint(0F, 20F, 0F);
    Body3.setTextureSize(64, 32);
    Body3.mirror = true;
    setRotation(Body3, 0F, 0F, 0F);
    Body5 = new ModelRenderer(this, 4, 9);
    Body5.addBox(-2.5F, 0F, -2.5F, 5, 1, 5);
    Body5.setRotationPoint(0F, 19F, 0F);
    Body5.setTextureSize(64, 32);
    Body5.mirror = true;
    setRotation(Body5, 0F, 0F, 0F);
    Body6 = new ModelRenderer(this, 16, 4);
    Body6.addBox(1.2F, 0F, -2.2F, 1, 6, 1);
    Body6.setRotationPoint(0F, 13F, 0F);
    Body6.setTextureSize(64, 32);
    Body6.mirror = true;
    setRotation(Body6, 0F, 0F, 0F);
    Body7 = new ModelRenderer(this, 16, 4);
    Body7.addBox(-2.2F, 0F, 1.2F, 1, 6, 1);
    Body7.setRotationPoint(0F, 13F, 0F);
    Body7.setTextureSize(64, 32);
    Body7.mirror = true;
    setRotation(Body7, 0F, 0F, 0F);
    Body8 = new ModelRenderer(this, 16, 4);
    Body8.addBox(-2.2F, 0F, -2.2F, 1, 6, 1);
    Body8.setRotationPoint(0F, 13F, 0F);
    Body8.setTextureSize(64, 32);
    Body8.mirror = true;
    setRotation(Body8, 0F, 0F, 0F);
    Body9 = new ModelRenderer(this, 16, 4);
    Body9.addBox(1.2F, 0F, 1.2F, 1, 6, 1);
    Body9.setRotationPoint(0F, 13F, 0F);
    Body9.setTextureSize(64, 32);
    Body9.mirror = true;
    setRotation(Body9, 0F, 0F, 0F);
    Shape1 = new ModelRenderer(this, 0, 0);
    Shape1.addBox(-3F, 0.4666667F, -3F, 6, 1, 6);
    Shape1.setRotationPoint(0F, 12F, 0F);
    Shape1.setTextureSize(64, 32);
    Shape1.mirror = true;
    setRotation(Shape1, 0F, 0F, 0F);
    Shape2 = new ModelRenderer(this, 4, 9);
    Shape2.addBox(-2.5F, 0F, -2.5F, 5, 1, 5);
    Shape2.setRotationPoint(0F, 12F, 0F);
    Shape2.setTextureSize(64, 32);
    Shape2.mirror = true;
    setRotation(Shape2, 0F, 0F, 0F);
    Shape3 = new ModelRenderer(this, 0, 0);
    Shape3.addBox(-2F, 0.4F, -2F, 4, 1, 4);
    Shape3.setRotationPoint(0F, 11F, 0F);
    Shape3.setTextureSize(64, 32);
    Shape3.mirror = true;
    setRotation(Shape3, 0F, 0F, 0F);
    Shape4 = new ModelRenderer(this, 0, 5);
    Shape4.addBox(-1.5F, -0.3F, -1.5F, 3, 1, 3);
    Shape4.setRotationPoint(0F, 11F, 0F);
    Shape4.setTextureSize(64, 32);
    Shape4.mirror = true;
    setRotation(Shape4, 0F, 0F, 0F);
    Shape5 = new ModelRenderer(this, 0, 0);
    Shape5.addBox(-1F, -0.1F, -1F, 2, 1, 2);
    Shape5.setRotationPoint(0F, 10F, 0F);
    Shape5.setTextureSize(64, 32);
    Shape5.mirror = true;
    setRotation(Shape5, 0F, 0F, 0F);
    Shape6 = new ModelRenderer(this, 0, 0);
    Shape6.addBox(-0.5F, 0F, -0.5F, 1, 1, 1);
    Shape6.setRotationPoint(0F, 9F, 0F);
    Shape6.setTextureSize(64, 32);
    Shape6.mirror = true;
    setRotation(Shape6, 0F, 0F, 0F);
    Side1 = new ModelRenderer(this, 0, 9);
    Side1.addBox(-0.5F, 0F, 0.5F, 1, 1, 5);
    Side1.setRotationPoint(0F, 19F, 2F);
    Side1.setTextureSize(64, 32);
    Side1.mirror = true;
    setRotation(Side1, 0F, 0F, 0F);
    Side2 = new ModelRenderer(this, 12, 4);
    Side2.addBox(-1F, 0F, 0F, 2, 10, 1);
    Side2.setRotationPoint(0F, 13F, 7F);
    Side2.setTextureSize(64, 32);
    Side2.mirror = true;
    setRotation(Side2, 0F, 0F, 0F);
    Side3 = new ModelRenderer(this, 45, 5);
    Side3.addBox(-0.5F, 0F, -0.5F, 1, 1, 1);
    Side3.setRotationPoint(0F, 14F, 7F);
    Side3.setTextureSize(64, 32);
    Side3.mirror = true;
    setRotation(Side3, 0F, 0F, 0F);
    Side4 = new ModelRenderer(this, 20, 7);
    Side4.addBox(-0.5F, 0F, 0F, 1, 1, 1);
    Side4.setRotationPoint(0F, 20F, 5F);
    Side4.setTextureSize(64, 32);
    Side4.mirror = true;
    setRotation(Side4, 0F, 0F, 0F);
    Side5 = new ModelRenderer(this, 20, 10);
    Side5.addBox(-0.5F, 0.5F, 1F, 1, 2, 1);
    Side5.setRotationPoint(0F, 20F, 5F);
    Side5.setTextureSize(64, 32);
    Side5.mirror = true;
    setRotation(Side5, 0F, 0F, 0F);
    Side6 = new ModelRenderer(this, 18, 5);
    Side6.addBox(-0.5F, 2.5F, -1F, 1, 1, 2);
    Side6.setRotationPoint(0F, 20F, 5F);
    Side6.setTextureSize(64, 32);
    Side6.mirror = true;
    setRotation(Side6, 0F, 0F, 0F);
    Side7 = new ModelRenderer(this, 20, 2);
    Side7.addBox(-0.5F, 0.5F, 0F, 1, 1, 1);
    Side7.setRotationPoint(0F, 21F, 3.5F);
    Side7.setTextureSize(64, 32);
    Side7.mirror = true;
    setRotation(Side7, 0F, 0F, 0F);
  }
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5, TileEntity tile)
  {
  
  Tessellator t = Tessellator.instance;
      t.setColorRGBA_F(1, 1, 1, 0.4F);
  
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    Glass1.render(f5);
    Glass2.render(f5);
    Glass3.render(f5);
    Glass4.render(f5);
    Candle.render(f5);
    Body4.render(f5);
    Body2.render(f5);
    Body3.render(f5);
    Body5.render(f5);
    Body6.render(f5);
    Body7.render(f5);
    Body8.render(f5);
    Body9.render(f5);
    Shape1.render(f5);
    Shape2.render(f5);
    Shape3.render(f5);
    Shape4.render(f5);
    Shape5.render(f5);
    Shape6.render(f5);
    Side1.render(f5);
    Side2.render(f5);
    Side3.render(f5);
    Side4.render(f5);
    Side5.render(f5);
    Side6.render(f5);
    Side7.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);
  }
}

 

Model renderer class:

package morelights.renderers;

import morelights.lib.Reference;
import morelights.model.ModelOldWallLamp;
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.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

public class ModelOldWallLampRenderer extends TileEntitySpecialRenderer{

private final ModelOldWallLamp model;

public ModelOldWallLampRenderer()
{
	this.model = new ModelOldWallLamp();
}

private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
        int meta = world.getBlockMetadata(x, y, z);
        GL11.glPushMatrix();
        GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);
        GL11.glPopMatrix();
}

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
	//The PushMatrix tells the renderer to "start" doing something.
        GL11.glPushMatrix();
        //This is setting the initial location.
        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        //Use in 1.6.2  this
        ResourceLocation textures = (new ResourceLocation(Reference.modid + ":textures/models/ModelOldWallLamp.png")); 
        Minecraft.getMinecraft().renderEngine.bindTexture(textures);
        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                      
        GL11.glPushMatrix();
        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
        //A reference to your Model file. Again, very important.
        this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F, te);
        //Tell it to stop rendering for both the PushMatrix's
        GL11.glPopMatrix();
        GL11.glPopMatrix();
}

//Set the lighting stuff, so it changes it's brightness properly.      
    private void adjustLightFixture(World world, int i, int j, int k, Block block) {
            Tessellator tess = Tessellator.instance;
            float brightness = block.getBlockBrightness(world, i, j, k);
            int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
            int modulousModifier = skyLight % 65536;
            int divModifier = skyLight / 65536;
            tess.setColorOpaque_F(brightness, brightness, brightness);
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);
    }

}

 

 

If someone helps you, click that thank you button ;)

 

EasyTessellator library: http://www.minecraftforge.net/forum/index.php/topic,14705.0.html

Link to comment
Share on other sites

You need to activate the alpha channel so transparent textures will work.

 GL11.glEnable(GL11.GL_BLEND); 

But dont forget to deactivate it after the transparent part renderes because it will consume a lot of cpu.

GL11.glDisable(GL11.GL_BLEND);

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

Probably wont work but worth a try;

 

In your model class, move the candle so it's rendered in the opposite order to the glass currently. IE, if it's currently above the glass, put it below, and if it's below the glass, put it above.

 

It works in techne but I've never tried that kind of thing in-game.

 

 

(Also, off-topic but as a suggestion, it'd be cool to see some flames rendering on the candle like you get on a Torch :))

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

Probably wont work but worth a try;

 

In your model class, move the candle so it's rendered in the opposite order to the glass currently. IE, if it's currently above the glass, put it below, and if it's below the glass, put it above.

 

It works in techne but I've never tried that kind of thing in-game.

 

 

 

Thanks! That worked!

 

(Also, off-topic but as a suggestion, it'd be cool to see some flames rendering on the candle like you get on a Torch :))

 

It was on my TODO list ;) But they don't render through the glass :(

 

S9Pry6X.png

 

If someone helps you, click that thank you button ;)

 

EasyTessellator library: http://www.minecraftforge.net/forum/index.php/topic,14705.0.html

Link to comment
Share on other sites

Is it possible to make it render through the glass?

 

Probably not.  Particles are rendered elsewhere in the code.  Your best bet would be to create a thin plane and render the particle manually just prior to the candle cube.

 

I don't have any example code, but there's math that can be used to determine which direction to rotate to face the player.  I used it to create a plaque on one of my models, but I stripped out the rotation code. :x

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So I come up with this:

NVOhew0.png

 

I think its better than nothing :D , but it would be better if it would be animated but I dont how to do that :/

 

And another question: How can I make item for this block render with the model?

If someone helps you, click that thank you button ;)

 

EasyTessellator library: http://www.minecraftforge.net/forum/index.php/topic,14705.0.html

Link to comment
Share on other sites

You can implement the ISimpleBlockRenderingHandler. That will give you all the functions you need to render it as an Item as well.

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {}

@Override
public boolean shouldRender3DInInventory() {
return true;
}

 

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

I tried it like this, but this dont work:

 

renderer class:

package morelights.renderers;

import morelights.lib.Reference;
import morelights.model.ModelOldWallLamp;
import morelights.model.ModelOldWallLampFire;
import morelights.model.ModelOldWallLampGlass;
import morelights.proxy.ClientProxy;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class ModelOldWallLampRenderer extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler{

private final ModelOldWallLamp model;
private final ModelOldWallLampGlass modelGlass;
private final ModelOldWallLampFire modelFire;

public ModelOldWallLampRenderer()
{
	this.model = new ModelOldWallLamp();
	this.modelGlass = new ModelOldWallLampGlass();
	this.modelFire = new ModelOldWallLampFire();
}

private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
        int meta = world.getBlockMetadata(x, y, z);
        GL11.glPushMatrix();
        GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);
        GL11.glPopMatrix();
}

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
	//The PushMatrix tells the renderer to "start" doing something.
        GL11.glPushMatrix();
        //This is setting the initial location.
        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glDisable(GL11.GL_CULL_FACE);
        //Use in 1.6.2  this
        ResourceLocation textures = (new ResourceLocation(Reference.modid + ":textures/models/ModelOldWallLamp.png")); 
        Minecraft.getMinecraft().renderEngine.bindTexture(textures);
        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                      
        GL11.glPushMatrix();
        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
        switch(te.getBlockMetadata()){
        case 2:
        	break;
        case 4:
        	GL11.glRotatef(90F, 0F, 1F, 0F);
        	break;
        case 5:
        	GL11.glRotatef(270F, 0F, 1F, 0F);
        	break;
        case 3:
        	GL11.glRotatef(180F, 0F, 1F, 0F);
        	break;
        default:
        	break;
        }
        
        this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        this.modelFire.render((Entity)null,  0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.015625F);
        this.modelGlass.render((Entity)null, 0F, 0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        GL11.glDisable(GL11.GL_BLEND);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
}

//Set the lighting stuff, so it changes it's brightness properly.      
    private void adjustLightFixture(World world, int i, int j, int k, Block block) {
            Tessellator tess = Tessellator.instance;
            float brightness = block.getBlockBrightness(world, i, j, k);
            int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
            int modulousModifier = skyLight % 65536;
            int divModifier = skyLight / 65536;
            tess.setColorOpaque_F(brightness, brightness, brightness);
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);
    }

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID,
		RenderBlocks renderer) {

	this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        this.modelFire.render((Entity)null,  0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.015625F);
        this.modelGlass.render((Entity)null, 0F, 0F, -0.1F, 0.0F, 0.0F, 0.0625F);
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z,
		Block block, int modelId, RenderBlocks renderer) {
	return false;
}

@Override
public boolean shouldRender3DInInventory() {
	return true;
}

@Override
public int getRenderId() {
	return ClientProxy.oldWallLampRendererType;
}

}

 

and I registered it in Client Proxy:

 

oldWallLampRendererType = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(oldWallLampRendererType, (ISimpleBlockRenderingHandler)new ModelOldWallLampRenderer());

 

I am probably doing it totaly wrong, am I not? :D

If someone helps you, click that thank you button ;)

 

EasyTessellator library: http://www.minecraftforge.net/forum/index.php/topic,14705.0.html

Link to comment
Share on other sites

I don't think that'll work.  At all.  Ever.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Oh sorry my bad O.o

You need to register it like this in the proxy:

        int ModelOldWallLampRendererID = RenderingRegistry.getNextAvailableRenderId();
        ModelOldWallLampRenderer OldWallLampRender = new ModelOldWallLampRenderer(ModelOldWallLampRendererID); //You need to have the id in the class as a variable so you have quick access to it.
        TheCorrespondingBlock(ModelOldWallLampRendererID); //You also need to give the block the id and save it there as a variable.
        ClientRegistry.bindTileEntitySpecialRenderer(YourTileEntity.class, OldWallLampRender);
        RenderingRegistry.registerBlockHandler(OldWallLampRender);

 

Now to save the id in the renderer:

      protected int renderID;

      public ModelOldWallLampRenderer(int renderID) {
  model = new SoulMagnetModel();
  this.renderID = renderID;
      }

 

Now you need to override this function in the renderer and let it return the render id. You should have saved it as a variable in the renderer.

@Override
public int getRenderId() {
	return this.renderID;
}

 

Now you need to set the blocks renderId to the given render id: (just add this to your block)

        protected int renderType;

public SoulMagnetBlock setRenderType(int id) {
	this.renderType = id;
	return this;
}

    @Override
    public boolean renderAsNormalBlock()
    {
        return false;
    }
    
    @Override
    public int getRenderType()
    {
        return renderType;
    }

    @Override
    public boolean isOpaqueCube()
    {
        return false;
    }

 

Sorry if it is a bit messy but this is the system I use to handle the rendering if blocks.

 

BTW: keep the ISimpleBlockRenderingHandler implemented ;)

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

Oh sorry my bad O.o

You need to register it like this in the proxy:

        int ModelOldWallLampRendererID = RenderingRegistry.getNextAvailableRenderId();
        ModelOldWallLampRenderer OldWallLampRender = new ModelOldWallLampRenderer(ModelOldWallLampRendererID); //You need to have the id in the class as a variable so you have quick access to it.
        TheCorrespondingBlock(ModelOldWallLampRendererID); //You also need to give the block the id and save it there as a variable.
        ClientRegistry.bindTileEntitySpecialRenderer(YourTileEntity.class, OldWallLampRender);
        RenderingRegistry.registerBlockHandler(OldWallLampRender);

 

Now to save the id in the renderer:

      protected int renderID;

      public ModelOldWallLampRenderer(int renderID) {
  model = new SoulMagnetModel();
  this.renderID = renderID;
      }

 

Now you need to override this function in the renderer and let it return the render id. You should have saved it as a variable in the renderer.

@Override
public int getRenderId() {
	return this.renderID;
}

 

Now you need to set the blocks renderId to the given render id: (just add this to your block)

        protected int renderType;

public SoulMagnetBlock setRenderType(int id) {
	this.renderType = id;
	return this;
}

    @Override
    public boolean renderAsNormalBlock()
    {
        return false;
    }
    
    @Override
    public int getRenderType()
    {
        return renderType;
    }

    @Override
    public boolean isOpaqueCube()
    {
        return false;
    }

 

Sorry if it is a bit messy but this is the system I use to handle the rendering if blocks.

 

BTW: keep the ISimpleBlockRenderingHandler implemented ;)

 

Thank you. That works.

 

I just didnt know what I was supposed to do here:

TheCorrespondingBlock(ModelOldWallLampRendererID);

I tried to put there serveral things like the name of the block class or the variable of the block (and the method setRenderType), but it was still giving me an error. So I didnt put it there and at the getRenderType method I retruned the renderID form the renderer and it works.

 

But now I have problem with the rendering:

utK1Ppd.png

 

Its probably doing the GL_BLEND , but then the glass is not transparent :/

 

renderer class:

 

package morelights.renderers;

import morelights.lib.Reference;
import morelights.model.ModelOldWallLamp;
import morelights.model.ModelOldWallLampFire;
import morelights.model.ModelOldWallLampGlass;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class ModelOldWallLampRenderer extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler{

private final ModelOldWallLamp model;
private final ModelOldWallLampGlass modelGlass;
private final ModelOldWallLampFire modelFire;
public static int renderID;

public ModelOldWallLampRenderer(int ID)
{
	this.model = new ModelOldWallLamp();
	this.modelGlass = new ModelOldWallLampGlass();
	this.modelFire = new ModelOldWallLampFire();

	this.renderID = ID;
}

@Override
public int getRenderId() {
	return this.renderID;
}

private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
        int meta = world.getBlockMetadata(x, y, z);
        GL11.glPushMatrix();
        GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);
        GL11.glPopMatrix();
}

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
	//The PushMatrix tells the renderer to "start" doing something.
        GL11.glPushMatrix();
        //This is setting the initial location.
        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glDisable(GL11.GL_CULL_FACE);
        //Use in 1.6.2  this
        ResourceLocation textures = (new ResourceLocation(Reference.modid + ":textures/models/ModelOldWallLamp.png")); 
        Minecraft.getMinecraft().renderEngine.bindTexture(textures);
        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                      
        GL11.glPushMatrix();
        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
        switch(te.getBlockMetadata()){
        case 2:
        	break;
        case 4:
        	GL11.glRotatef(90F, 0F, 1F, 0F);
        	break;
        case 5:
        	GL11.glRotatef(270F, 0F, 1F, 0F);
        	break;
        case 3:
        	GL11.glRotatef(180F, 0F, 1F, 0F);
        	break;
        default:
        	break;
        }
        
        this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        this.modelFire.render((Entity)null,  0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.015625F);
        this.modelGlass.render((Entity)null, 0F, 0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        GL11.glDisable(GL11.GL_BLEND);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
}

//Set the lighting stuff, so it changes it's brightness properly.      
    private void adjustLightFixture(World world, int i, int j, int k, Block block) {
            Tessellator tess = Tessellator.instance;
            float brightness = block.getBlockBrightness(world, i, j, k);
            int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
            int modulousModifier = skyLight % 65536;
            int divModifier = skyLight / 65536;
            tess.setColorOpaque_F(brightness, brightness, brightness);
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);
    }

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID,
		RenderBlocks renderer) {

	GL11.glPushMatrix();
	GL11.glTranslatef(0F, 1.2F, 0F);

        GL11.glDisable(GL11.GL_CULL_FACE);

	ResourceLocation textures = (new ResourceLocation(Reference.modid + ":textures/models/ModelOldWallLamp.png")); 
    Minecraft.getMinecraft().renderEngine.bindTexture(textures);
    
    GL11.glPushMatrix();
        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
	GL11.glEnable(GL11.GL_BLEND);

	this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        this.modelFire.render((Entity)null,  0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.015625F);
        this.modelGlass.render((Entity)null, 0F, 0F, -0.1F, 0.0F, 0.0F, 0.0625F);
       
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z,
		Block block, int modelId, RenderBlocks renderer) {
	return false;
}

@Override
public boolean shouldRender3DInInventory() {
	return true;
}
}

If someone helps you, click that thank you button ;)

 

EasyTessellator library: http://www.minecraftforge.net/forum/index.php/topic,14705.0.html

Link to comment
Share on other sites

You are disabling GL11.GL_CULL_FACE, but you aren't enabling it after you're done with rendering.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Oh sorry its hard to keep track of so much code in a forum O.o

Its supposed to be:

TheCorrespondingBlock.setRenderType(ModelOldWallLampRendererID);

 

EDIT 1: You need to set it to the already initialized block in your mod Class. You basically have to set the Blocks renderID the same as teh TESR's

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

Oh sorry its hard to keep track of so much code in a forum O.o

Its supposed to be:

TheCorrespondingBlock.setRenderType(ModelOldWallLampRendererID);

 

EDIT 1: You need to set it to the already initialized block in your mod Class. You basically have to set the Blocks renderID the same as teh TESR's

 

well I tried it like that, but it said that I have to make setRenderType static, so I did, but than there was another error... But whatever it works when I reference it from the TESR ;)

 

And do you know why is it in hand rendering like ghost? (picture above)

If someone helps you, click that thank you button ;)

 

EasyTessellator library: http://www.minecraftforge.net/forum/index.php/topic,14705.0.html

Link to comment
Share on other sites

Hey guys again :D

 

So I released v0.1-alpha of my mod (so my friend can do bug hunting :P ) and I don't know why, but in recompiled version it renders weirdly:

 

waaeJLS.png

 

When I look at it in certain angels it renders normally but most of the time it renders weirdly :(

 

Any idea why is that happening and how to solve this? :)

 

Thanks in advance ;)

If someone helps you, click that thank you button ;)

 

EasyTessellator library: http://www.minecraftforge.net/forum/index.php/topic,14705.0.html

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.