Jump to content

[1.7.10] [SOLVED] "custom" lever render, bassed on original, doesn't work


SackCastellon

Recommended Posts

I've created some lever variants bassed on NBT Tags, using as base code the origina levers, also i created a new render handler, for the new levers, because as the textures depends on the NBT tags, the original render handler, doesn't work.

 

LeverBlock.class

package com.sackcastellon.betterwood.block;

import static net.minecraftforge.common.util.ForgeDirection.DOWN;
import static net.minecraftforge.common.util.ForgeDirection.EAST;
import static net.minecraftforge.common.util.ForgeDirection.NORTH;
import static net.minecraftforge.common.util.ForgeDirection.SOUTH;
import static net.minecraftforge.common.util.ForgeDirection.UP;
import static net.minecraftforge.common.util.ForgeDirection.WEST;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import com.sackcastellon.betterwood.api.Tabs;
import com.sackcastellon.betterwood.handler.LeverHandler;

public class BlockLever extends BlockWoodBase
{
public BlockLever()
{
	super(Material.circuits, "lever", false);

	this.setCreativeTab(Tabs.tabBW);
	this.setStepSound(soundTypeWood);
}

@Override
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
    {
        return null;
    }

@Override
    public int getRenderType()
    {
        return LeverHandler.renderId;
    }

@Override
    public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side)
    {
        ForgeDirection dir = ForgeDirection.getOrientation(side);
        return (dir == DOWN  && world.isSideSolid(x, y + 1, z, DOWN )) ||
               (dir == UP    && world.isSideSolid(x, y - 1, z, UP   )) ||
               (dir == NORTH && world.isSideSolid(x, y, z + 1, NORTH)) ||
               (dir == SOUTH && world.isSideSolid(x, y, z - 1, SOUTH)) ||
               (dir == WEST  && world.isSideSolid(x + 1, y, z, WEST )) ||
               (dir == EAST  && world.isSideSolid(x - 1, y, z, EAST ));
    }

@Override
    public boolean canPlaceBlockAt(World world, int x, int y, int z)
    {
        return world.isSideSolid(x - 1, y, z, EAST ) ||
               world.isSideSolid(x + 1, y, z, WEST ) ||
               world.isSideSolid(x, y, z - 1, SOUTH) ||
               world.isSideSolid(x, y, z + 1, NORTH) ||
               world.isSideSolid(x, y - 1, z, UP   ) ||
               world.isSideSolid(x, y + 1, z, DOWN );
    }

@Override
    public int onBlockPlaced(World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
    {
        int k1 = metadata & 8;
        byte b0 = -1;

        if (side == 0 && world.isSideSolid(x, y + 1, z, DOWN))
        {
            b0 = 0;
        }

        if (side == 1 && world.isSideSolid(x, y - 1, z, UP))
        {
            b0 = 5;
        }

        if (side == 2 && world.isSideSolid(x, y, z + 1, NORTH))
        {
            b0 = 4;
        }

        if (side == 3 && world.isSideSolid(x, y, z - 1, SOUTH))
        {
            b0 = 3;
        }

        if (side == 4 && world.isSideSolid(x + 1, y, z, WEST))
        {
            b0 = 2;
        }

        if (side == 5 && world.isSideSolid(x - 1, y, z, EAST))
        {
            b0 = 1;
        }

        return b0 + k1;
    }

    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack)
    {
        int l = world.getBlockMetadata(x, y, z);
        int i1 = l & 7;
        int j1 = l & 8;

        if (i1 == invertMetadata(1))
        {
            if ((MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 1) == 0)
            {
                world.setBlockMetadataWithNotify(x, y, z, 5 | j1, 2);
            }
            else
            {
                world.setBlockMetadataWithNotify(x, y, z, 6 | j1, 2);
            }
        }
        else if (i1 == invertMetadata(0))
        {
            if ((MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 1) == 0)
            {
                world.setBlockMetadataWithNotify(x, y, z, 7 | j1, 2);
            }
            else
            {
                world.setBlockMetadataWithNotify(x, y, z, 0 | j1, 2);
            }
        }
    }

    public static int invertMetadata(int metadata)
    {
        switch (metadata)
        {
            case 0:
                return 0;
            case 1:
                return 5;
            case 2:
                return 4;
            case 3:
                return 3;
            case 4:
                return 2;
            case 5:
                return 1;
            default:
                return -1;
        }
    }

    @Override
    public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
    {
        if (this.canPlaceBlock(world, x, y, z))
        {
            int l = world.getBlockMetadata(x, y, z) & 7;
            boolean flag = false;

            if (!world.isSideSolid(x - 1, y, z, EAST) && l == 1)
            {
                flag = true;
            }

            if (!world.isSideSolid(x + 1, y, z, WEST) && l == 2)
            {
                flag = true;
            }

            if (!world.isSideSolid(x, y, z - 1, SOUTH) && l == 3)
            {
                flag = true;
            }

            if (!world.isSideSolid(x, y, z + 1, NORTH) && l == 4)
            {
                flag = true;
            }

            if (!world.isSideSolid(x, y - 1, z, UP) && l == 5)
            {
                flag = true;
            }

            if (!world.isSideSolid(x, y - 1, z, UP) && l == 6)
            {
                flag = true;
            }

            if (!world.isSideSolid(x, y + 1, z, DOWN) && l == 0)
            {
                flag = true;
            }

            if (!world.isSideSolid(x, y + 1, z, DOWN) && l == 7)
            {
                flag = true;
            }

            if (flag)
            {
                this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
                world.setBlockToAir(x, y, z);
            }
        }
    }

    private boolean canPlaceBlock(World world, int x, int y, int z)
    {
        if (!this.canPlaceBlockAt(world, x, y, z))
        {
            this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
            world.setBlockToAir(x, y, z);
            return false;
        }
        else
        {
            return true;
        }
    }
    
    @Override
    public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
    {
        int l = world.getBlockMetadata(x, y, z) & 7;
        float f = 0.1875F;

        if (l == 1)
        {
            this.setBlockBounds(0.0F, 0.2F, 0.5F - f, f * 2.0F, 0.8F, 0.5F + f);
        }
        else if (l == 2)
        {
            this.setBlockBounds(1.0F - f * 2.0F, 0.2F, 0.5F - f, 1.0F, 0.8F, 0.5F + f);
        }
        else if (l == 3)
        {
            this.setBlockBounds(0.5F - f, 0.2F, 0.0F, 0.5F + f, 0.8F, f * 2.0F);
        }
        else if (l == 4)
        {
            this.setBlockBounds(0.5F - f, 0.2F, 1.0F - f * 2.0F, 0.5F + f, 0.8F, 1.0F);
        }
        else if (l != 5 && l != 6)
        {
            if (l == 0 || l == 7)
            {
                f = 0.25F;
                this.setBlockBounds(0.5F - f, 0.4F, 0.5F - f, 0.5F + f, 1.0F, 0.5F + f);
            }
        }
        else
        {
            f = 0.25F;
            this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.6F, 0.5F + f);
        }
    }
    
    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
    {
        if (world.isRemote)
        {
            return true;
        }
        else
        {
            int i1 = world.getBlockMetadata(x, y, z);
            int j1 = i1 & 7;
            int k1 = 8 - (i1 & ;
            world.setBlockMetadataWithNotify(x, y, z, j1 + k1, 3);
            world.playSoundEffect((double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D, "random.click", 0.3F, k1 > 0 ? 0.6F : 0.5F);
            world.notifyBlocksOfNeighborChange(x, y, z, this);

            if (j1 == 1)
            {
                world.notifyBlocksOfNeighborChange(x - 1, y, z, this);
            }
            else if (j1 == 2)
            {
                world.notifyBlocksOfNeighborChange(x + 1, y, z, this);
            }
            else if (j1 == 3)
            {
                world.notifyBlocksOfNeighborChange(x, y, z - 1, this);
            }
            else if (j1 == 4)
            {
                world.notifyBlocksOfNeighborChange(x, y, z + 1, this);
            }
            else if (j1 != 5 && j1 != 6)
            {
                if (j1 == 0 || j1 == 7)
                {
                    world.notifyBlocksOfNeighborChange(x, y + 1, z, this);
                }
            }
            else
            {
                world.notifyBlocksOfNeighborChange(x, y - 1, z, this);
            }

            return true;
        }
    }

    @Override
    public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
    {
        if ((metadata &  > 0)
        {
            world.notifyBlocksOfNeighborChange(x, y, z, this);
            int i1 = metadata & 7;

            if (i1 == 1)
            {
                world.notifyBlocksOfNeighborChange(x - 1, y, z, this);
            }
            else if (i1 == 2)
            {
                world.notifyBlocksOfNeighborChange(x + 1, y, z, this);
            }
            else if (i1 == 3)
            {
                world.notifyBlocksOfNeighborChange(x, y, z - 1, this);
            }
            else if (i1 == 4)
            {
                world.notifyBlocksOfNeighborChange(x, y, z + 1, this);
            }
            else if (i1 != 5 && i1 != 6)
            {
                if (i1 == 0 || i1 == 7)
                {
                    world.notifyBlocksOfNeighborChange(x, y + 1, z, this);
                }
            }
            else
            {
                world.notifyBlocksOfNeighborChange(x, y - 1, z, this);
            }
        }

        super.breakBlock(world, x, y, z, block, metadata);
    }

    @Override
    public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side)
    {
        return (world.getBlockMetadata(x, y, z) &  > 0 ? 15 : 0;
    }

    @Override
    public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side)
    {
        int i1 = world.getBlockMetadata(x, y, z);

        if ((i1 &  == 0)
        {
            return 0;
        }
        else
        {
            int j1 = i1 & 7;
            return j1 == 0 && side == 0 ? 15 : (j1 == 7 && side == 0 ? 15 : (j1 == 6 && side == 1 ? 15 : (j1 == 5 && side == 1 ? 15 : (j1 == 4 && side == 2 ? 15 : (j1 == 3 && side == 3 ? 15 : (j1 == 2 && side == 4 ? 15 : (j1 == 1 && side == 5 ? 15 : 0)))))));
        }
    }
    
    @Override
    public boolean canProvidePower()
    {
        return true;
    }
}

BlockWoodBase.class

package com.sackcastellon.betterwood.block;

import java.util.ArrayList;
import java.util.Random;

import com.sackcastellon.betterwood.lib.Reference;
import com.sackcastellon.betterwood.loader.ItemLoader;
import com.sackcastellon.betterwood.tileentities.TileEntityWoodBase;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockWoodBase extends BlockContainer
{
@SideOnly(Side.CLIENT)
public IIcon[] iconArray = new IIcon[itemLoader.woodTypes.length];

protected String path;

/**
 * 
 * @param material
 * @param block 
 * @param planks Use planks texture?
 */
protected BlockWoodBase(Material material, String block, boolean planks)
{
	super(material);

	this.setBlockName(block);

	this.path = Reference.TexturePath + (planks ? "planks" : block.replace('.', '/')) + "/";
}

@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
	TileEntity tile = world.getTileEntity(x, y, z);

	ItemStack stack = new ItemStack(Item.getItemFromBlock(this));

	if(tile instanceof TileEntityWoodBase)
	{
		TileEntityWoodBase wood = (TileEntityWoodBase) tile;

		stack.stackTagCompound = new NBTTagCompound();

		NBTTagCompound nbt = stack.getTagCompound();

		nbt.setInteger("variant", wood.getVariant());

		return stack;
	}

	return stack;
}

@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
{
	ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

	TileEntity tile = world.getTileEntity(x, y, z);

	ItemStack stack = new ItemStack(Item.getItemFromBlock(this));

	if(tile instanceof TileEntityWoodBase)
	{
		TileEntityWoodBase wood = (TileEntityWoodBase) tile;

		stack.stackTagCompound = new NBTTagCompound();

		NBTTagCompound nbt = stack.getTagCompound();

		nbt.setInteger("variant", wood.getVariant());
	}

        ret.add(stack);
        
        return ret;
}

@Override
public TileEntity createNewTileEntity(World world, int meta)
{
	return new TileEntityWoodBase();
}

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

@Override
    public boolean renderAsNormalBlock()
    {
        return this.getRenderType() == 0;
    }

@Override
public void registerBlockIcons(IIconRegister iconRegister)
{
	for(int i = 0; i < ItemLoader.woodTypes.length; ++i)
	{
		this.iconArray[i] = iconRegister.registerIcon(path + (String) ItemLoader.woodTypes[i][1]);
	}
}


@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
{		
	TileEntity tile = world.getTileEntity(x, y, z);

	TileEntityWoodBase wood = (TileEntityWoodBase) tile;

	int variant = wood.getVariant();

	return this.iconArray[variant];

//		if(tile instanceof TileEntityWoodBase)
//		{
//			TileEntityWoodBase wood = (TileEntityWoodBase) tile;
//			
//			int variant = wood.getVariant();
//			
//			System.out.println(this.iconArray[variant]);
//			
//			return this.iconArray[variant];
//		}
//		
//		return this.blockIcon;
}

    @Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack)
    {
	TileEntity tile = world.getTileEntity(x, y, z);

	if(tile instanceof TileEntityWoodBase)
	{
		TileEntityWoodBase wood = (TileEntityWoodBase) tile;

		NBTTagCompound nbt = stack.getTagCompound();

		if(nbt != null)
		{
			int variant = nbt.getInteger("variant");

			wood.setVariant(variant);
		}
	}
}
    
    @Override
    public int quantityDropped(Random random)
    {
        return 1;
    }
}

 

TileEntityWoodBase.class

package com.sackcastellon.betterwood.tileentities;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class TileEntityWoodBase extends TileEntity
{
/**
 * 0. Oak<br>
 * 1. Spruce<br>
 * 2. Birch<br>
 * 3. Jungle<br>
 * 4. Acacia<br>
 * 5. DarkOak<br>
 */
private int variant;

private boolean active;

public TileEntityWoodBase() {}

@Override
public void readFromNBT(NBTTagCompound nbt)
{
	super.readFromNBT(nbt);

	this.setVariant(nbt.getInteger("variant"));
	this.setIsActive(nbt.getBoolean("active"));
}

@Override
public void writeToNBT(NBTTagCompound nbt)
{
	super.writeToNBT(nbt);

	nbt.setInteger("variant", this.getVariant());
	nbt.setBoolean("active", this.getIsActive());
}

public int getVariant()
{
	return variant;
}

public void setVariant(int variant)
{
	if(variant < 0 || variant > 5)
	{
		this.variant = 0;
	}

	else
	{
		this.variant = variant;
	}
}

public boolean getIsActive()
{
	return active;
}

public void setIsActive(boolean active)
{
	this.active = active;
}

@Override
public Packet getDescriptionPacket()
{
	NBTTagCompound nbt = new NBTTagCompound();
	this.writeToNBT(nbt);
	return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
	this.readFromNBT(pkt.func_148857_g());
}
}

 

LeverHandler.class

package com.sackcastellon.betterwood.handler;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;

public class LeverHandler implements ISimpleBlockRenderingHandler
{
public static int renderId = RenderingRegistry.getNextAvailableRenderId();
private RenderBlocks render = RenderBlocks.getInstance();

@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)
{
        int l = world.getBlockMetadata(x, y, z);
        int i1 = l & 7;
        boolean flag = (l &  > 0;
        Tessellator tessellator = Tessellator.instance;
        boolean flag1 = render.hasOverrideBlockTexture();

        if (!flag1)
        {
            render.setOverrideBlockTexture(render.getBlockIcon(Blocks.cobblestone));
        }

        float f = 0.25F;
        float f1 = 0.1875F;
        float f2 = 0.1875F;

        if (i1 == 5)
        {
            render.setRenderBounds((double)(0.5F - f1), 0.0D, (double)(0.5F - f), (double)(0.5F + f1), (double)f2, (double)(0.5F + f));
        }
        else if (i1 == 6)
        {
            render.setRenderBounds((double)(0.5F - f), 0.0D, (double)(0.5F - f1), (double)(0.5F + f), (double)f2, (double)(0.5F + f1));
        }
        else if (i1 == 4)
        {
            render.setRenderBounds((double)(0.5F - f1), (double)(0.5F - f), (double)(1.0F - f2), (double)(0.5F + f1), (double)(0.5F + f), 1.0D);
        }
        else if (i1 == 3)
        {
            render.setRenderBounds((double)(0.5F - f1), (double)(0.5F - f), 0.0D, (double)(0.5F + f1), (double)(0.5F + f), (double)f2);
        }
        else if (i1 == 2)
        {
            render.setRenderBounds((double)(1.0F - f2), (double)(0.5F - f), (double)(0.5F - f1), 1.0D, (double)(0.5F + f), (double)(0.5F + f1));
        }
        else if (i1 == 1)
        {
            render.setRenderBounds(0.0D, (double)(0.5F - f), (double)(0.5F - f1), (double)f2, (double)(0.5F + f), (double)(0.5F + f1));
        }
        else if (i1 == 0)
        {
            render.setRenderBounds((double)(0.5F - f), (double)(1.0F - f2), (double)(0.5F - f1), (double)(0.5F + f), 1.0D, (double)(0.5F + f1));
        }
        else if (i1 == 7)
        {
            render.setRenderBounds((double)(0.5F - f1), (double)(1.0F - f2), (double)(0.5F - f), (double)(0.5F + f1), 1.0D, (double)(0.5F + f));
        }

        render.renderStandardBlock(block, x, y, z);

        if (!flag1)
        {
            render.clearOverrideBlockTexture();
        }

        tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
        tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
        IIcon icon = render.getBlockIcon(block, world, x, y, z, 0);

        if (render.hasOverrideBlockTexture())
        {
            icon = render.overrideBlockTexture;
        }

        double d0 = (double)icon.getMinU();
        double d1 = (double)icon.getMinV();
        double d2 = (double)icon.getMaxU();
        double d3 = (double)icon.getMaxV();
        Vec3[] avec3 = new Vec3[8];
        float f3 = 0.0625F;
        float f4 = 0.0625F;
        float f5 = 0.625F;
        avec3[0] = Vec3.createVectorHelper((double)(-f3), 0.0D, (double)(-f4));
        avec3[1] = Vec3.createVectorHelper((double)f3, 0.0D, (double)(-f4));
        avec3[2] = Vec3.createVectorHelper((double)f3, 0.0D, (double)f4);
        avec3[3] = Vec3.createVectorHelper((double)(-f3), 0.0D, (double)f4);
        avec3[4] = Vec3.createVectorHelper((double)(-f3), (double)f5, (double)(-f4));
        avec3[5] = Vec3.createVectorHelper((double)f3, (double)f5, (double)(-f4));
        avec3[6] = Vec3.createVectorHelper((double)f3, (double)f5, (double)f4);
        avec3[7] = Vec3.createVectorHelper((double)(-f3), (double)f5, (double)f4);

        for (int j1 = 0; j1 < 8; ++j1)
        {
            if (flag)
            {
                avec3[j1].zCoord -= 0.0625D;
                avec3[j1].rotateAroundX(((float)Math.PI * 2F / 9F));
            }
            else
            {
                avec3[j1].zCoord += 0.0625D;
                avec3[j1].rotateAroundX(-((float)Math.PI * 2F / 9F));
            }

            if (i1 == 0 || i1 == 7)
            {
                avec3[j1].rotateAroundZ((float)Math.PI);
            }

            if (i1 == 6 || i1 == 0)
            {
                avec3[j1].rotateAroundY(((float)Math.PI / 2F));
            }

            if (i1 > 0 && i1 < 5)
            {
                avec3[j1].yCoord -= 0.375D;
                avec3[j1].rotateAroundX(((float)Math.PI / 2F));

                if (i1 == 4)
                {
                    avec3[j1].rotateAroundY(0.0F);
                }

                if (i1 == 3)
                {
                    avec3[j1].rotateAroundY((float)Math.PI);
                }

                if (i1 == 2)
                {
                    avec3[j1].rotateAroundY(((float)Math.PI / 2F));
                }

                if (i1 == 1)
                {
                    avec3[j1].rotateAroundY(-((float)Math.PI / 2F));
                }

                avec3[j1].xCoord += (double)x + 0.5D;
                avec3[j1].yCoord += (double)((float)y + 0.5F);
                avec3[j1].zCoord += (double)z + 0.5D;
            }
            else if (i1 != 0 && i1 != 7)
            {
                avec3[j1].xCoord += (double)x + 0.5D;
                avec3[j1].yCoord += (double)((float)y + 0.125F);
                avec3[j1].zCoord += (double)z + 0.5D;
            }
            else
            {
                avec3[j1].xCoord += (double)x + 0.5D;
                avec3[j1].yCoord += (double)((float)y + 0.875F);
                avec3[j1].zCoord += (double)z + 0.5D;
            }
        }

        Vec3 vec33 = null;
        Vec3 vec3 = null;
        Vec3 vec31 = null;
        Vec3 vec32 = null;

        for (int k1 = 0; k1 < 6; ++k1)
        {
            if (k1 == 0)
            {
                d0 = (double)icon.getInterpolatedU(7.0D);
                d1 = (double)icon.getInterpolatedV(6.0D);
                d2 = (double)icon.getInterpolatedU(9.0D);
                d3 = (double)icon.getInterpolatedV(8.0D);
            }
            else if (k1 == 2)
            {
                d0 = (double)icon.getInterpolatedU(7.0D);
                d1 = (double)icon.getInterpolatedV(6.0D);
                d2 = (double)icon.getInterpolatedU(9.0D);
                d3 = (double)icon.getMaxV();
            }

            if (k1 == 0)
            {
                vec33 = avec3[0];
                vec3 = avec3[1];
                vec31 = avec3[2];
                vec32 = avec3[3];
            }
            else if (k1 == 1)
            {
                vec33 = avec3[7];
                vec3 = avec3[6];
                vec31 = avec3[5];
                vec32 = avec3[4];
            }
            else if (k1 == 2)
            {
                vec33 = avec3[1];
                vec3 = avec3[0];
                vec31 = avec3[4];
                vec32 = avec3[5];
            }
            else if (k1 == 3)
            {
                vec33 = avec3[2];
                vec3 = avec3[1];
                vec31 = avec3[5];
                vec32 = avec3[6];
            }
            else if (k1 == 4)
            {
                vec33 = avec3[3];
                vec3 = avec3[2];
                vec31 = avec3[6];
                vec32 = avec3[7];
            }
            else if (k1 == 5)
            {
                vec33 = avec3[0];
                vec3 = avec3[3];
                vec31 = avec3[7];
                vec32 = avec3[4];
            }

            tessellator.addVertexWithUV(vec33.xCoord, vec33.yCoord, vec33.zCoord, d0, d3);
            tessellator.addVertexWithUV(vec3.xCoord, vec3.yCoord, vec3.zCoord, d2, d3);
            tessellator.addVertexWithUV(vec31.xCoord, vec31.yCoord, vec31.zCoord, d2, d1);
            tessellator.addVertexWithUV(vec32.xCoord, vec32.yCoord, vec32.zCoord, d0, d1);
        }

        return true;
}

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

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

 

 

Everything should work correctly, but it crashes:

 

CrashLog

[15:33:57] [Client thread/FATAL]: Unreported exception thrown!
java.lang.NullPointerException
at net.minecraft.block.Block.getMixedBrightnessForBlock(Block.java:612) ~[block.class:?]
at net.minecraft.client.renderer.RenderBlocks.renderStandardBlockWithColorMultiplier(RenderBlocks.java:6222) ~[RenderBlocks.class:?]
at net.minecraft.client.renderer.RenderBlocks.renderStandardBlock(RenderBlocks.java:4473) ~[RenderBlocks.class:?]
at com.sackcastellon.betterwood.handler.LeverHandler.renderWorldBlock(LeverHandler.java:72) ~[LeverHandler.class:?]
at cpw.mods.fml.client.registry.RenderingRegistry.renderWorldBlock(RenderingRegistry.java:118) ~[RenderingRegistry.class:?]
at net.minecraft.src.FMLRenderAccessLibrary.renderWorldBlock(FMLRenderAccessLibrary.java:53) ~[FMLRenderAccessLibrary.class:?]
at net.minecraft.client.renderer.RenderBlocks.renderBlockByRenderType(RenderBlocks.java:435) ~[RenderBlocks.class:?]
at net.minecraft.client.renderer.WorldRenderer.updateRenderer(WorldRenderer.java:207) ~[WorldRenderer.class:?]
at net.minecraft.client.renderer.RenderGlobal.updateRenderers(RenderGlobal.java:1624) ~[RenderGlobal.class:?]
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1271) ~[EntityRenderer.class:?]
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1095) ~[EntityRenderer.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1066) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:961) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_11]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]
---- Minecraft Crash Report ----
// Oh - I know what I did wrong!

Time: 29/08/14 15:33
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at net.minecraft.block.Block.getMixedBrightnessForBlock(Block.java:612)
at net.minecraft.client.renderer.RenderBlocks.renderStandardBlockWithColorMultiplier(RenderBlocks.java:6222)
at net.minecraft.client.renderer.RenderBlocks.renderStandardBlock(RenderBlocks.java:4473)
at com.sackcastellon.betterwood.handler.LeverHandler.renderWorldBlock(LeverHandler.java:72)
at cpw.mods.fml.client.registry.RenderingRegistry.renderWorldBlock(RenderingRegistry.java:118)
at net.minecraft.src.FMLRenderAccessLibrary.renderWorldBlock(FMLRenderAccessLibrary.java:53)
at net.minecraft.client.renderer.RenderBlocks.renderBlockByRenderType(RenderBlocks.java:435)
at net.minecraft.client.renderer.WorldRenderer.updateRenderer(WorldRenderer.java:207)
at net.minecraft.client.renderer.RenderGlobal.updateRenderers(RenderGlobal.java:1624)
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1271)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1095)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1066)
at net.minecraft.client.Minecraft.run(Minecraft.java:961)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at net.minecraft.block.Block.getMixedBrightnessForBlock(Block.java:612)
at net.minecraft.client.renderer.RenderBlocks.renderStandardBlockWithColorMultiplier(RenderBlocks.java:6222)
at net.minecraft.client.renderer.RenderBlocks.renderStandardBlock(RenderBlocks.java:4473)
at com.sackcastellon.betterwood.handler.LeverHandler.renderWorldBlock(LeverHandler.java:72)
at cpw.mods.fml.client.registry.RenderingRegistry.renderWorldBlock(RenderingRegistry.java:118)
at net.minecraft.src.FMLRenderAccessLibrary.renderWorldBlock(FMLRenderAccessLibrary.java:53)
at net.minecraft.client.renderer.RenderBlocks.renderBlockByRenderType(RenderBlocks.java:435)
at net.minecraft.client.renderer.WorldRenderer.updateRenderer(WorldRenderer.java:207)
at net.minecraft.client.renderer.RenderGlobal.updateRenderers(RenderGlobal.java:1624)
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1271)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player801'/0, l='MpServer', x=-977,51, y=57,62, z=1583,78]]
Chunk stats: MultiplayerChunkCache: 25, 25
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: World: (-983,4,1583), Chunk: (at 9,0,15 in -62,98; contains blocks -992,0,1568 to -977,255,1583), Region: (-2,3; contains chunks -64,96 to -33,127, blocks -1024,0,1536 to -513,255,2047)
Level time: 630 game time, 630 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 1 total; [EntityClientPlayerMP['Player801'/0, l='MpServer', x=-977,51, y=57,62, z=1583,78]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:417)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2567)
at net.minecraft.client.Minecraft.run(Minecraft.java:990)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_11, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 95152824 bytes (90 MB) / 327155712 bytes (312 MB) up to 878182400 bytes (837 MB)
JVM Flags: 0 total; 
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.25.1203 Minecraft Forge 10.13.0.1203 5 mods loaded, 5 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.10.25.1203} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1203.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.13.0.1203} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1203.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
SKC-Core{1.1.2.0} [sKC Core] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
SKC-BetterWood{1.1.0.7} [better Wood] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Launched Version: 1.6
LWJGL: 2.9.1
OpenGL: GeForce GT 330M/PCIe/SSE2 GL version 3.3.0, NVIDIA Corporation
GL Caps: Using GL 1.3 multitexturing.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Anisotropic filtering is supported and maximum anisotropy is 16.
Shaders are available because OpenGL 2.1 is supported.

Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: ~~ERROR~~ NullPointerException: null
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Anisotropic Filtering: Off (1)
#@!@# Game crashed! Crash report saved to: #@!@# C:\Modding\Github\BetterWood\.\crash-reports\crash-2014-08-29_15.33.57-client.txt
2014-08-29 15:33:58,296 WARN Unable to register shutdown hook due to JVM state
AL lib: (EE) alc_cleanup: 1 device not closed

 

Basically it says that the problem is on this line of the LeverHandler.class

        render.renderStandardBlock(block, x, y, z);

 

Thanks for helping.

Link to comment
Share on other sites

Try to go in Block and put a breakpoint in line 612 and check what is null there (either the world or the coordinates, but they should really be valid because many other methods use those before).

In Eclipse it's just number of the line->right click->toggle breakpoint and then run in debug mode. While in debug perspective you should see to your left some buttons like variables and breakpoints.

Check out my blog!

http://www.whov.altervista.org

Link to comment
Share on other sites

Try to go in Block and put a breakpoint in line 612 and check what is null there (either the world or the coordinates, but they should really be valid because many other methods use those before).

In Eclipse it's just number of the line->right click->toggle breakpoint and then run in debug mode. While in debug perspective you should see to your left some buttons like variables and breakpoints.

 

OK, did it but it says the null variable is the world (IBlockAccess):

 

width=800 height=449https://dl.dropboxusercontent.com/u/184200482/img/Captura%20de%20pantalla%202014-08-29%2020.43.13.png[/img]

 

Any suggestion??

Link to comment
Share on other sites

Oh, I see your problem (I think, because it's weird it doesn't break earlier), but you are getting renderer using forge getInstance(), but to have the world set you need the other constructor, the one with the parameter world (IBlockAccess to be exact). So just initialize it somewhere else and pass the world object as argument. Bye!

Check out my blog!

http://www.whov.altervista.org

Link to comment
Share on other sites

Hi

 

Why are you using your own saved "render" variable, which may be invalid if initialised too early, or may become invalid if the player teleports to another dimension or restarts the game?  You should use the one passed to your render method (renderer)

 

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)

 

-TGG

Link to comment
Share on other sites

Hi

 

Why are you using your own saved "render" variable, which may be invalid if initialised too early, or may become invalid if the player teleports to another dimension or restarts the game?  You should use the one passed to your render method (renderer)

 

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)

 

-TGG

 

Oops. I don't know why but i didn't noticed about that.

 

Now it world properly.

 

Thanks.

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.