Jump to content

[1.5.2] Rendering Problems


Dmitchell94

Recommended Posts

Hello.

 

I am creating a BlueStone alternative and am having some trouble with rendering. I got some help on this topic and rewrote the code for the rendering which fixed most of the problems but I am still having one major problem in which at all times the BlueStone wire renders as BlueStone_Wire_Cross.png and does not render as a straight line or turns. Someone suggested it may be a IBlockAccess Error and I do use IBlockAccess but am still having some problems any ideas? I am fairly new to Mod coding and some of this confuses me so any help is welcome

 

RenderBlueStone_Wire.java

 

/*
* This File is Part of the BlueStone Mod
* The BlueStone Mod is Developed By David Mitchell (BlackMage)
* Modification or distribution of the mod is prohibited
* This mod is only permitted on official BlueStone Servers
* Private and public mod packs prohibited
*/


package BlackMage.BlueStone;

import BlackMage.BlueStone.*;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;

public class RenderBlueStone_Wire extends RenderBlocks
{
    public RenderBlueStone_Wire()
    {
        //overrideBlockTexture = 0;
    }

    public boolean renderBlueStone_Wire(Block block, int i, int j, int k, IBlockAccess iblockaccess)
    {
        Tessellator tessellator = Tessellator.instance;
        int l = iblockaccess.getBlockMetadata(i, j, k);
        Icon icon = BlueStone_Wire.getBlueStone_Wire("cross.png");
        Icon icon1 = BlueStone_Wire.getBlueStone_Wire("line.png");
        Icon icon2 = BlueStone_Wire.getBlueStone_Wire("cross_overlay");
        Icon icon3 = BlueStone_Wire.getBlueStone_Wire("line_overlay");
        tessellator.setBrightness(block.getMixedBrightnessForBlock(iblockaccess, i, j, k));
        float f = 1.0F;
        float f1 = (float)l / 15F;
        float f2 = -f1 * 0.4F + 0.5F;
	float f3 = f1 * f1 * 0.5F + 0.2F;
        float f4 = f1 * f1 * 0.8F + 0.2F;
        if(l == 0)
        {
            f2 = 0.86F;
		f3 = 0.23F;
		f4 = 0.14F;
        }
        tessellator.setColorOpaque_F(f2, f3, f4);
        double d0 = 0.015625D;
        double d1 = 0.015625D;
        boolean flag = BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i - 1, j, k, 1) || !iblockaccess.isBlockNormalCube(i - 1, j, k) && BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i - 1, j - 1, k, -1);
        boolean flag1 = BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i + 1, j, k, 3) || !iblockaccess.isBlockNormalCube(i + 1, j, k) && BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i + 1, j - 1, k, -1);
        boolean flag2 = BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i, j, k - 1, 2) || !iblockaccess.isBlockNormalCube(i, j, k - 1) && BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i, j - 1, k - 1, -1);
        boolean flag3 = BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i, j, k + 1, 0) || !iblockaccess.isBlockNormalCube(i, j, k + 1) && BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i, j - 1, k + 1, -1);
        if(!iblockaccess.isBlockNormalCube(i, j + 1, k))
        {
            if(iblockaccess.isBlockNormalCube(i - 1, j, k) && BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i - 1, j + 1, k, -1))
            {
                flag = true;
            }
            if(iblockaccess.isBlockNormalCube(i + 1, j, k) && BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i + 1, j + 1, k, -1))
            {
                flag1 = true;
            }
            if(iblockaccess.isBlockNormalCube(i, j, k - 1) && BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i, j + 1, k - 1, -1))
            {
                flag2 = true;
            }
            if(iblockaccess.isBlockNormalCube(i, j, k + 1) && BlueStone_Wire.isPowerProviderOrWire(iblockaccess, i, j + 1, k + 1, -1))
            {
                flag3 = true;
            }
        }
        float f5 = i + 0;
        float f6 = i + 1;
        float f7 = k + 0;
        float f8 = k + 1;
        byte byte0 = 0;
        if((flag || flag1) && !flag2 && !flag3)
        {
            byte0 = 1;
        }
        if((flag2 || flag3) && !flag1 && !flag)
        {
            byte0 = 2;
        }
        if(byte0 == 0)
        {
        	int j1 = 0;
            int k1 = 0;
            int l1 = 16;
            int i2 = 16;
            boolean flag4 = true;

            if (!flag)
            {
                f5 += 0.3125F;
            }

            if (!flag)
            {
                j1 += 5;
            }

            if (!flag1)
            {
                f6 -= 0.3125F;
            }

            if (!flag1)
            {
                l1 -= 5;
            }

            if (!flag2)
            {
                f7 += 0.3125F;
            }

            if (!flag2)
            {
                k1 += 5;
            }

            if (!flag3)
            {
                f8 -= 0.3125F;
            }

            if (!flag3)
            {
                i2 -= 5;
            }
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f8, (double)icon.getInterpolatedU((double)l1), (double)icon.getInterpolatedV((double)i2));
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f7, (double)icon.getInterpolatedU((double)l1), (double)icon.getInterpolatedV((double)k1));
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f7, (double)icon.getInterpolatedU((double)j1), (double)icon.getInterpolatedV((double)k1));
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f8, (double)icon.getInterpolatedU((double)j1), (double)icon.getInterpolatedV((double)i2));
            tessellator.setColorOpaque_F(f, f, f);
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f8, (double)icon2.getInterpolatedU((double)l1), (double)icon2.getInterpolatedV((double)i2));
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f7, (double)icon2.getInterpolatedU((double)l1), (double)icon2.getInterpolatedV((double)k1));
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f7, (double)icon2.getInterpolatedU((double)j1), (double)icon2.getInterpolatedV((double)k1));
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f8, (double)icon2.getInterpolatedU((double)j1), (double)icon2.getInterpolatedV((double)i2));
        } 
        else if(byte0 == 1)
        {
        	tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f8, (double)icon1.getMaxU(), (double)icon1.getMaxV());
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f7, (double)icon1.getMaxU(), (double)icon1.getMinV());
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f7, (double)icon1.getMinU(), (double)icon1.getMinV());
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f8, (double)icon1.getMinU(), (double)icon1.getMaxV());
            tessellator.setColorOpaque_F(f, f, f);
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f8, (double)icon3.getMaxU(), (double)icon3.getMaxV());
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f7, (double)icon3.getMaxU(), (double)icon3.getMinV());
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f7, (double)icon3.getMinU(), (double)icon3.getMinV());
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f8, (double)icon3.getMinU(), (double)icon3.getMaxV());
        }
        else
        {
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f8, (double)icon1.getMaxU(), (double)icon1.getMaxV());
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f7, (double)icon1.getMinU(), (double)icon1.getMaxV());
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f7, (double)icon1.getMinU(), (double)icon1.getMinV());
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f8, (double)icon1.getMaxU(), (double)icon1.getMinV());
            tessellator.setColorOpaque_F(f, f, f);
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f8, (double)icon3.getMaxU(), (double)icon3.getMaxV());
            tessellator.addVertexWithUV((double)f6, (double)j + 0.015625D, (double)f7, (double)icon3.getMinU(), (double)icon3.getMaxV());
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f7, (double)icon3.getMinU(), (double)icon3.getMinV());
            tessellator.addVertexWithUV((double)f5, (double)j + 0.015625D, (double)f8, (double)icon3.getMaxU(), (double)icon3.getMinV());
        }
        if(!iblockaccess.isBlockNormalCube(i, j + 1, k))
        {
            if(iblockaccess.isBlockNormalCube(i - 1, j, k) && iblockaccess.getBlockId(i - 1, j + 1, k) == BlackMage.BlueStone.BlueStoneMod.BlueStone_Wire.blockID)
            {
                tessellator.setColorOpaque_F(f * f2, f * f3, f * f4);
                tessellator.addVertexWithUV((double)i + 0.015625D, (double)((float)(j + 1) + 0.021875F), (double)(k + 1), (double)icon1.getMaxU(), (double)icon1.getMinV());
                tessellator.addVertexWithUV((double)i + 0.015625D, (double)(j + 0), (double)(k + 1), (double)icon1.getMinU(), (double)icon1.getMinV());
                tessellator.addVertexWithUV((double)i + 0.015625D, (double)(j + 0), (double)(k + 0), (double)icon1.getMinU(), (double)icon1.getMaxV());
                tessellator.addVertexWithUV((double)i + 0.015625D, (double)((float)(j + 1) + 0.021875F), (double)(k + 0), (double)icon1.getMaxU(), (double)icon1.getMaxV());
                tessellator.setColorOpaque_F(f, f, f);
                tessellator.addVertexWithUV((double)i + 0.015625D, (double)((float)(j + 1) + 0.021875F), (double)(k + 1), (double)icon3.getMaxU(), (double)icon3.getMinV());
                tessellator.addVertexWithUV((double)i + 0.015625D, (double)(j + 0), (double)(k + 1), (double)icon3.getMinU(), (double)icon3.getMinV());
                tessellator.addVertexWithUV((double)i + 0.015625D, (double)(j + 0), (double)(k + 0), (double)icon3.getMinU(), (double)icon3.getMaxV());
                tessellator.addVertexWithUV((double)i + 0.015625D, (double)((float)(j + 1) + 0.021875F), (double)(k + 0), (double)icon3.getMaxU(), (double)icon3.getMaxV());
            }
            if(iblockaccess.isBlockNormalCube(i + 1, j, k) && iblockaccess.getBlockId(i + 1, j + 1, k) == BlackMage.BlueStone.BlueStoneMod.BlueStone_Wire.blockID)
            {
            	tessellator.setColorOpaque_F(f * f2, f * f3, f * f4);
                tessellator.addVertexWithUV((double)(i + 1) - 0.015625D, (double)(j + 0), (double)(k + 1), (double)icon1.getMinU(), (double)icon1.getMaxV());
                tessellator.addVertexWithUV((double)(i + 1) - 0.015625D, (double)((float)(j + 1) + 0.021875F), (double)(k + 1), (double)icon1.getMaxU(), (double)icon1.getMaxV());
                tessellator.addVertexWithUV((double)(i + 1) - 0.015625D, (double)((float)(j + 1) + 0.021875F), (double)(k + 0), (double)icon1.getMaxU(), (double)icon1.getMinV());
                tessellator.addVertexWithUV((double)(i + 1) - 0.015625D, (double)(j + 0), (double)(k + 0), (double)icon1.getMinU(), (double)icon1.getMinV());
                tessellator.setColorOpaque_F(f, f, f);
                tessellator.addVertexWithUV((double)(i + 1) - 0.015625D, (double)(j + 0), (double)(k + 1), (double)icon3.getMinU(), (double)icon3.getMaxV());
                tessellator.addVertexWithUV((double)(i + 1) - 0.015625D, (double)((float)(j + 1) + 0.021875F), (double)(k + 1), (double)icon3.getMaxU(), (double)icon3.getMaxV());
                tessellator.addVertexWithUV((double)(i + 1) - 0.015625D, (double)((float)(j + 1) + 0.021875F), (double)(k + 0), (double)icon3.getMaxU(), (double)icon3.getMinV());
                tessellator.addVertexWithUV((double)(i + 1) - 0.015625D, (double)(j + 0), (double)(k + 0), (double)icon3.getMinU(), (double)icon3.getMinV());
            }
            if(iblockaccess.isBlockNormalCube(i, j, k - 1) && iblockaccess.getBlockId(i, j + 1, k - 1) == BlackMage.BlueStone.BlueStoneMod.BlueStone_Wire.blockID)
            {
            	tessellator.setColorOpaque_F(f * f2, f * f3, f * f4);
                tessellator.addVertexWithUV((double)(i + 1), (double)(j + 0), (double)k + 0.015625D, (double)icon1.getMinU(), (double)icon1.getMaxV());
                tessellator.addVertexWithUV((double)(i + 1), (double)((float)(j + 1) + 0.021875F), (double)k + 0.015625D, (double)icon1.getMaxU(), (double)icon1.getMaxV());
                tessellator.addVertexWithUV((double)(i + 0), (double)((float)(j + 1) + 0.021875F), (double)k + 0.015625D, (double)icon1.getMaxU(), (double)icon1.getMinV());
                tessellator.addVertexWithUV((double)(i + 0), (double)(j + 0), (double)k + 0.015625D, (double)icon1.getMinU(), (double)icon1.getMinV());
                tessellator.setColorOpaque_F(f, f, f);
                tessellator.addVertexWithUV((double)(i + 1), (double)(j + 0), (double)k + 0.015625D, (double)icon3.getMinU(), (double)icon3.getMaxV());
                tessellator.addVertexWithUV((double)(i + 1), (double)((float)(j + 1) + 0.021875F), (double)k + 0.015625D, (double)icon3.getMaxU(), (double)icon3.getMaxV());
                tessellator.addVertexWithUV((double)(i + 0), (double)((float)(j + 1) + 0.021875F), (double)k + 0.015625D, (double)icon3.getMaxU(), (double)icon3.getMinV());
                tessellator.addVertexWithUV((double)(i + 0), (double)(j + 0), (double)k + 0.015625D, (double)icon3.getMinU(), (double)icon3.getMinV());
            }
            if(iblockaccess.isBlockNormalCube(i, j, k + 1) && iblockaccess.getBlockId(i, j + 1, k + 1) == BlackMage.BlueStone.BlueStoneMod.BlueStone_Wire.blockID)
            {
            	tessellator.setColorOpaque_F(f * f2, f * f3, f * f4);
                tessellator.addVertexWithUV((double)(i + 1), (double)((float)(j + 1) + 0.021875F), (double)(k + 1) - 0.015625D, (double)icon1.getMaxU(), (double)icon1.getMinV());
                tessellator.addVertexWithUV((double)(i + 1), (double)(j + 0), (double)(k + 1) - 0.015625D, (double)icon1.getMinU(), (double)icon1.getMinV());
                tessellator.addVertexWithUV((double)(i + 0), (double)(j + 0), (double)(k + 1) - 0.015625D, (double)icon1.getMinU(), (double)icon1.getMaxV());
                tessellator.addVertexWithUV((double)(i + 0), (double)((float)(j + 1) + 0.021875F), (double)(k + 1) - 0.015625D, (double)icon1.getMaxU(), (double)icon1.getMaxV());
                tessellator.setColorOpaque_F(f, f, f);
                tessellator.addVertexWithUV((double)(i + 1), (double)((float)(j + 1) + 0.021875F), (double)(k + 1) - 0.015625D, (double)icon3.getMaxU(), (double)icon3.getMinV());
                tessellator.addVertexWithUV((double)(i + 1), (double)(j + 0), (double)(k + 1) - 0.015625D, (double)icon3.getMinU(), (double)icon3.getMinV());
                tessellator.addVertexWithUV((double)(i + 0), (double)(j + 0), (double)(k + 1) - 0.015625D, (double)icon3.getMinU(), (double)icon3.getMaxV());
                tessellator.addVertexWithUV((double)(i + 0), (double)((float)(j + 1) + 0.021875F), (double)(k + 1) - 0.015625D, (double)icon3.getMaxU(), (double)icon3.getMaxV());
            }
        }
        return true;
    }

}

 

 

BlueStone_Wire.java

 

 

/*
* This File is Part of the BlueStone Mod
* The BlueStone Mod is Developed By David Mitchell (BlackMage)
* Modification or distribution of the mod is prohibited
* This mod is only permitted on official BlueStone Servers
* Private and public mod packs prohibited
*/


package BlackMage.BlueStone;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockRedstoneWire;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import BlackMage.BlueStone.ClientProxy;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlueStone_Wire extends BlockRedstoneWire
{
    public static int modelID;

public BlueStone_Wire(int i)
    {
        super(i);
        disableStats();
    }
    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister par1IconRegister)
    {
    	super.registerIcons(par1IconRegister);
        this.blockIcon = par1IconRegister.registerIcon("BlueStone_Wire");
    }
    
public static Icon getBlueStone_Wire(String string) {
	return null;
}

    @Override
    public int getRenderType()
    {
        return modelID;
    }
    @Override
    @SideOnly(Side.CLIENT)
    public int colorMultiplier(IBlockAccess iblockaccess, int i, int j, int k)
    {
        return 0x1d1d6a;
    }
    
    @Override
    public void randomDisplayTick(World world, int i, int j, int k, Random random)
    {
        int l = world.getBlockMetadata(i, j, k);
        if(l > 0)
        {
		double d = (double)i + 0.5D + ((double)random.nextFloat() - 0.5D) * 0.20000000000000001D;
            double d1 = (float)j + 0.0625F;
            double d2 = (double)k + 0.5D + ((double)random.nextFloat() - 0.5D) * 0.20000000000000001D;
            float f = 1 / 15F;
            float f1 = -1;
            float f2 = f * f * 0.7F - 0.5F;
            float f3 = f * f * 0.6F - 0.7F;
            if(f2 < 0.0F)
            {
                f2 = 0.7F;
            }
            if(f3 < 0.0F)
            {
                f3 = 1.0F;
            }
            world.spawnParticle("reddust", d, d1, d2, f1, f2, f3);
        }

}
}

 

 

If needed i can post the client and the common proxy as well.

Link to comment
Share on other sites

I think your over complicating the rendering. I would make some basic textures ex cross texture or straight or turn or etc, then rotate them based on the neighboring blocks. I personally would simply make it update its texture on a neighboring block update (make all the processes happen with the block) and simply make the renderer render the texture the block figured, and rotate it accordingly.

Hope this helps  :P

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

My original attempt was similar to that though it would only show up as redstone wire. Which is why i attempted this method which is working most of the way. I am trying to see how Redstone Wire handle the textures and i may try there method.

 

To be honest this has been the most difficult code I have ever worked on and its starting to get frustrating how I can not figure out why it is not working.

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.