Jump to content

multiple textures rendered


spenk

Recommended Posts

hello people,

 

I'm trying to code a new flower pot since i want to have my own flowers in it.

but i stumbled upon an issue, the  texture of the flower rendering inside of the pot is rendered more than 1 time.

 

width=800 height=449http://spenk.bplaced.net/images/2013-08-21_01.35.40.png[/img]

(default pot left, my pot right)

 

here is my render code.

package net.bplaced.spenk.drugmod.generator;

import net.bplaced.spenk.drugmod.ClientProxy;
import net.bplaced.spenk.drugmod.DrugsMod;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAnvil;
import net.minecraft.block.BlockBeacon;
import net.minecraft.block.BlockBrewingStand;
import net.minecraft.block.BlockCauldron;
import net.minecraft.block.BlockCocoa;
import net.minecraft.block.BlockComparator;
import net.minecraft.block.BlockDragonEgg;
import net.minecraft.block.BlockEndPortalFrame;
import net.minecraft.block.BlockFence;
import net.minecraft.block.BlockFenceGate;
import net.minecraft.block.BlockFire;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.BlockFlowerPot;
import net.minecraft.block.BlockHopper;
import net.minecraft.block.BlockPane;
import net.minecraft.block.BlockRailBase;
import net.minecraft.block.BlockRedstoneLogic;
import net.minecraft.block.BlockRedstoneRepeater;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.BlockWall;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.src.FMLRenderAccessLibrary;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class BlockSeedpotRender implements ISimpleBlockRenderingHandler {

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

}

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

public boolean renderBlockSeedpot(Block block, RenderBlocks renderer, IBlockAccess world, int par2, int par3, int par4) {
        renderer.renderStandardBlock(block, par2, par3, par4);
        Tessellator tessellator = Tessellator.instance;
        tessellator.setBrightness(block.getMixedBrightnessForBlock(world, par2, par3, par4));
        float f = 1.0F;
        int l = block.colorMultiplier(world, par2, par3, par4);
        Icon icon = renderer.getBlockIconFromSide(block, 0);
        float f1 = (float)(l >> 16 & 255) / 255.0F;
        float f2 = (float)(l >> 8 & 255) / 255.0F;
        float f3 = (float)(l & 255) / 255.0F;
        float f4;
        float f5;

        if (EntityRenderer.anaglyphEnable)
        {
            f4 = (f1 * 30.0F + f2 * 59.0F + f3 * 11.0F) / 100.0F;
            float f6 = (f1 * 30.0F + f2 * 70.0F) / 100.0F;
            f5 = (f1 * 30.0F + f3 * 70.0F) / 100.0F;
            f1 = f4;
            f2 = f6;
            f3 = f5;
        }

        tessellator.setColorOpaque_F(f * f1, f * f2, f * f3);
        f4 = 0.1865F;
        renderer.renderFaceXPos(block, (double)((float)par2 - 0.5F + f4), (double)par3, (double)par4, icon);
        renderer.renderFaceXNeg(block, (double)((float)par2 + 0.5F - f4), (double)par3, (double)par4, icon);
        renderer.renderFaceZPos(block, (double)par2, (double)par3, (double)((float)par4 - 0.5F + f4), icon);
        renderer.renderFaceZNeg(block, (double)par2, (double)par3, (double)((float)par4 + 0.5F - f4), icon);
        renderer.renderFaceYPos(block, (double)par2, (double)((float)par3 - 0.5F + f4 + 0.1875F), (double)par4, renderer.getBlockIcon(Block.tilledField));
        int i1 = world.getBlockMetadata(par2, par3, par4);

        if (i1 != 0)
        {
            f5 = 0.0F;
            float f7 = 4.0F;
            float f8 = 0.0F;
            BlockFlower blockflower = null;

            switch (i1)
            {
                case 1:
                    blockflower = Block.plantRed;
                    break;
                case 2:
                    blockflower = Block.plantYellow;
                case 3:
                case 4:
                case 5:
                case 6:
                default:
                    break;
                case 7:
                    blockflower = Block.mushroomRed;
                    break;
                case 8:
                    blockflower = Block.mushroomBrown;
            }

            tessellator.addTranslation(f5 / 16.0F, f7 / 16.0F, f8 / 16.0F);

            if (blockflower != null)
            {
                renderer.renderBlockByRenderType(blockflower, par2, par3, par4);
            }
            else if (i1 == 9)
            {
                renderer.renderAllFaces = true;
                float f9 = 0.125F;
                renderer.setRenderBounds((double)(0.5F - f9), 0.0D, (double)(0.5F - f9), (double)(0.5F + f9), 0.25D, (double)(0.5F + f9));
                renderer.renderStandardBlock(Block.cactus, par2, par3, par4);
                renderer.setRenderBounds((double)(0.5F - f9), 0.25D, (double)(0.5F - f9), (double)(0.5F + f9), 0.5D, (double)(0.5F + f9));
                renderer.renderStandardBlock(Block.cactus, par2, par3, par4);
                renderer.setRenderBounds((double)(0.5F - f9), 0.5D, (double)(0.5F - f9), (double)(0.5F + f9), 0.75D, (double)(0.5F + f9));
                renderer.renderStandardBlock(Block.cactus, par2, par3, par4);
                renderer.renderAllFaces = false;
                renderer.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
            }
            else if (i1 == 3)
            {
                renderer.drawCrossedSquares(Block.sapling, 0, (double)par2, (double)par3, (double)par4, 0.75F);
            }
            else if (i1 == 5)
            {
                renderer.drawCrossedSquares(Block.sapling, 2, (double)par2, (double)par3, (double)par4, 0.75F);
            }
            else if (i1 == 4)
            {
                renderer.drawCrossedSquares(Block.sapling, 1, (double)par2, (double)par3, (double)par4, 0.75F);
            }
            else if (i1 == 6)
            {
                renderer.drawCrossedSquares(Block.sapling, 3, (double)par2, (double)par3, (double)par4, 0.75F);
            }
            else if (i1 == 11)
            {
                l = Block.tallGrass.colorMultiplier(world, par2, par3, par4);
                f1 = (float)(l >> 16 & 255) / 255.0F;
                f2 = (float)(l >> 8 & 255) / 255.0F;
                f3 = (float)(l & 255) / 255.0F;
                tessellator.setColorOpaque_F(f * f1, f * f2, f * f3);
                renderer.drawCrossedSquares(Block.tallGrass, 2, (double)par2, (double)par3, (double)par4, 0.75F);
            }
            else if (i1 == 10)
            {
                renderer.drawCrossedSquares(Block.deadBush, 2, (double)par2, (double)par3, (double)par4, 0.75F);
            }

            tessellator.addTranslation(-f5 / 16.0F, -f7 / 16.0F, -f8 / 16.0F);
        }

        return true;
}

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

@Override
public int getRenderId() {
	return 0;
}
}

 

and here is my block code.

package net.bplaced.spenk.drugmod.Blocks;

import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.bplaced.spenk.drugmod.ClientProxy;
import net.bplaced.spenk.drugmod.DrugsMod;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.IPlantable;

public class BlockSeedpot extends Block {

public BlockSeedpot(int i) {
	super(i, Material.circuits);
	setBlockConfigurations();
	setBlockBoundsForItemRender();
}

private void setBlockConfigurations() {
	setUnlocalizedName("BlockSeedPot");
	func_111022_d("drugsmod:drugs_pot_template");
	setStepSound(Block.soundPowderFootstep);
	setHardness(0F).setResistance(0.1F);
}

    public void setBlockBoundsForItemRender()
    {
        float f = 0.375F;
        float f1 = f / 2.0F;
        this.setBlockBounds(0.5F - f1, 0.0F, 0.5F - f1, 0.5F + f1, f, 0.5F + f1);
    }

public boolean renderAsNormalBlock() {
	return false;
}

public int getRenderType() {
	return ClientProxy.seedPotRender;
}

/*
public void registerIcons(IconRegister icon) {
	this.blockIcon = icon.registerIcon("drugsmod:drugs_pot");
}*/

public boolean isOpaqueCube() {
	return false;
}

public int getRenderBlockPass() {
	return 1;
}

 /**
     * Called upon block activation (right click on the block.)
     */
    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    {
        ItemStack itemstack = par5EntityPlayer.inventory.getCurrentItem();

        if (itemstack == null)
        {
            return false;
        }
        else if (par1World.getBlockMetadata(par2, par3, par4) != 0)
        {
            return false;
        }
        else
        {
            int i1 = getMetaForPlant(itemstack);

            if (i1 > 0)
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, i1, 2);

                if (!par5EntityPlayer.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
                {
                    par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, (ItemStack)null);
                }

                return true;
            }
            else
            {
                return false;
            }
        }
    }

    @SideOnly(Side.CLIENT)

    public int idPicked(World par1World, int par2, int par3, int par4)
    {
        ItemStack itemstack = getPlantForMeta(par1World.getBlockMetadata(par2, par3, par4));
        return itemstack == null ? DrugsMod.itemSeedpot.itemID : itemstack.itemID;
    }

    public int getDamageValue(World par1World, int par2, int par3, int par4)
    {
        ItemStack itemstack = getPlantForMeta(par1World.getBlockMetadata(par2, par3, par4));
        return itemstack == null ? DrugsMod.itemSeedpot.itemID : itemstack.getItemDamage();
    }

    @SideOnly(Side.CLIENT)

    public boolean isFlowerPot()
    {
        return true;
    }

    public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    {
        return super.canPlaceBlockAt(par1World, par2, par3, par4) && par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4);
    }

    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    {
        if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4))
        {
            this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
            par1World.setBlockToAir(par2, par3, par4);
        }
    }

    public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
    {
        super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7);

        if (par5 > 0)
        {
            ItemStack itemstack = getPlantForMeta(par5);

            if (itemstack != null)
            {
                this.dropBlockAsItem_do(par1World, par2, par3, par4, itemstack);
            }
        }
    }

    public int idDropped(int par1, Random par2Random, int par3)
    {
        return Item.flowerPot.itemID;
    }

    public static ItemStack getPlantForMeta(int par0)
    {
        switch (par0)
        {
            case 1:
                return new ItemStack(Block.plantRed);
            case 2:
                return new ItemStack(Block.plantYellow);
            case 3:
                return new ItemStack(Block.sapling, 1, 0);
            case 4:
                return new ItemStack(Block.sapling, 1, 1);
            case 5:
                return new ItemStack(Block.sapling, 1, 2);
            case 6:
                return new ItemStack(Block.sapling, 1, 3);
            case 7:
                return new ItemStack(Block.mushroomRed);
            case 8:
                return new ItemStack(Block.mushroomBrown);
            case 9:
                return new ItemStack(Block.cactus);
            case 10:
                return new ItemStack(Block.deadBush);
            case 11:
                return new ItemStack(Block.tallGrass, 1, 2);
            default:
                return null;
        }
    }

    public static int getMetaForPlant(ItemStack par0ItemStack)
    {
        int i = par0ItemStack.getItem().itemID;

        if (i == Block.plantRed.blockID)
        {
            return 1;
        }
        else if (i == Block.plantYellow.blockID)
        {
            return 2;
        }
        else if (i == Block.cactus.blockID)
        {
            return 9;
        }
        else if (i == Block.mushroomBrown.blockID)
        {
            return 8;
        }
        else if (i == Block.mushroomRed.blockID)
        {
            return 7;
        }
        else if (i == Block.deadBush.blockID)
        {
            return 10;
        }
        else
        {
            if (i == Block.sapling.blockID)
            {
                switch (par0ItemStack.getItemDamage())
                {
                    case 0:
                        return 3;
                    case 1:
                        return 4;
                    case 2:
                        return 5;
                    case 3:
                        return 6;
                }
            }

            if (i == Block.tallGrass.blockID)
            {
                switch (par0ItemStack.getItemDamage())
                {
                    case 2:
                        return 11;
                }
            }

            return 0;
        }
    }
}

 

the same happens with saplings.

 

i hope you guys can help me with a fix, this issue has been delaying me for 3 days already.

thanks in advance.

Link to comment
Share on other sites

i have done multiple debug tests the results were as following,

 

i put renderStandardBlock inside the renderWorldBlock void, it was rendering without problems.

i removed all remaining code in my own render void but left the flower pot render code, the flower pot rendered as usual without problems.

but when i added a piece of code to render a red flower in it, it started to bug the texture again.

 

it seems like the overlapping textures are bugging eachother ?

is there any way to solve this?

Link to comment
Share on other sites

i got my problem solved by moving the inner walls of my plantpot because they were colliding with the new rendered flower

        renderer.renderFaceXPos(block, (double)((float)par2 - 0.5F + f4), (double)par3, (double)par4, icon);
        renderer.renderFaceXNeg(block, (double)((float)par2 + 0.5F - f4), (double)par3, (double)par4, icon);
        renderer.renderFaceZPos(block, (double)par2, (double)par3, (double)((float)par4 - 0.5F + f4), icon);
        renderer.renderFaceZNeg(block, (double)par2, (double)par3, (double)((float)par4 + 0.5F - f4), icon);

INTO

        renderer.renderFaceXPos(block, (double)((float)par2 - 0.5001F + f4), (double)par3, (double)par4, icon);
        renderer.renderFaceXNeg(block, (double)((float)par2 + 0.5001F - f4), (double)par3, (double)par4, icon);
        renderer.renderFaceZPos(block, (double)par2, (double)par3, (double)((float)par4 - 0.5001F + f4), icon);
        renderer.renderFaceZNeg(block, (double)par2, (double)par3, (double)((float)par4 + 0.5001F - f4), icon);

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.