Jump to content

[1.7.2] Custom blockrenderer not showing


Casual Dutchman

Recommended Posts

I was working on my mod, getting it from 1.6 to 1.7. I solved all the errors, but it still does not work

It has an gui on it, but right clicking does nog work. I have a custom renderer on it, but it does not work.

 

This is the code from the Block:

 

public class BlockShield extends BlockContainer {

IBlockAccess par1IBlockAccess;

float pixel = 0.0625F;

    private final Random random = new Random();

    
public BlockShield() {
	super(Material.wood);
	this.setCreativeTab(AgeCraft.tabAgeCraft);
	this.setHardness(2.5F);
}

public boolean isOpaqueCube()
{
	return false;
}

public boolean renderAsNormalBlock()
{
	return false;
}

public int getRenderType(){
	return -10;
}

@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister)
{
	this.blockIcon = par1IconRegister.registerIcon(this.textureName);
}


public TileEntity createNewTileEntity(World par1World)
{
	return new TileEntityShield();
}

@Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float what, float these, float are) {
	TileEntity tileEntity = world.getTileEntity(x, y, z);

        if(tileEntity instanceof TileEntityShield) {
    		player.openGui(AgeCraft.instance, 0, world, x, y, z);
        }
        else{ return false; }
    	return true;
}

public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int i, int j, int k)
    {
	int meta = par1IBlockAccess.getBlockMetadata(i, j, k);

	float f = 0.125F;

        if (meta == 2)
        {
            this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
        }
        if (meta == 3)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
        }
        if (meta == 4)
        {
            this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
        if (meta == 5)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
        }
    }

public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    {
        return par1World.isSideSolid(par2 - 1, par3, par4, EAST ) ||
               par1World.isSideSolid(par2 + 1, par3, par4, WEST ) ||
               par1World.isSideSolid(par2, par3, par4 - 1, SOUTH) ||
               par1World.isSideSolid(par2, par3, par4 + 1, NORTH);
    }

public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
    {
        int j1 = par9;

        if ((j1 == 0 || par5 == 2) && par1World.isSideSolid(par2, par3, par4 + 1, NORTH))
        {
            j1 = 2;
        }

        if ((j1 == 0 || par5 == 3) && par1World.isSideSolid(par2, par3, par4 - 1, SOUTH))
        {
            j1 = 3;
        }

        if ((j1 == 0 || par5 == 4) && par1World.isSideSolid(par2 + 1, par3, par4, WEST))
        {
            j1 = 4;
        }

        if ((j1 == 0 || par5 == 5) && par1World.isSideSolid(par2 - 1, par3, par4, EAST))
        {
            j1 = 5;
        }

        return j1;
    }

public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, Block par5)
    {
        int i1 = par1World.getBlockMetadata(par2, par3, par4);
        boolean flag = false;

        if (i1 == 2 && par1World.isSideSolid(par2, par3, par4 + 1, NORTH))
        {
            flag = true;
        }

        if (i1 == 3 && par1World.isSideSolid(par2, par3, par4 - 1, SOUTH))
        {
            flag = true;
        }

        if (i1 == 4 && par1World.isSideSolid(par2 + 1, par3, par4, WEST))
        {
            flag = true;
        }

        if (i1 == 5 && par1World.isSideSolid(par2 - 1, par3, par4, EAST))
        {
            flag = true;
        }

        if (!flag)
        {
            this.dropBlockAsItem(par1World, par2, par3, par4, i1, 0);
            par1World.setBlockToAir(par2, par3, par4);
        }

        super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
    }

public void breakBlock(World par1World, int par2, int par3, int par4, Block par5, int par6)
    {
	TileEntityShield tileentitychest = (TileEntityShield)par1World.getTileEntity(par2, par3, par4);

        if (tileentitychest != null)
        {
            for (int j1 = 0; j1 < tileentitychest.getSizeInventory(); ++j1)
            {
                ItemStack itemstack = tileentitychest.getStackInSlot(j1);

                if (itemstack != null)
                {
                    float f = this.random.nextFloat() * 0.8F + 0.1F;
                    float f1 = this.random.nextFloat() * 0.8F + 0.1F;
                    EntityItem entityitem;

                    for (float f2 = this.random.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; par1World.spawnEntityInWorld(entityitem))
                    {
                        int k1 = this.random.nextInt(21) + 10;

                        if (k1 > itemstack.stackSize)
                        {
                            k1 = itemstack.stackSize;
                        }

                        itemstack.stackSize -= k1;
                        entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.getItem(), k1, itemstack.getItemDamage()));
                        float f3 = 0.05F;
                        entityitem.motionX = (double)((float)this.random.nextGaussian() * f3);
                        entityitem.motionY = (double)((float)this.random.nextGaussian() * f3 + 0.2F);
                        entityitem.motionZ = (double)((float)this.random.nextGaussian() * f3);

                        if (itemstack.hasTagCompound())
                        {
                            entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                        }
                    }
                }
            }

            par1World.func_147453_f(par2, par3, par4, par5);
        }

        super.breakBlock(par1World, par2, par3, par4, par5, par6);
    }

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

 

 

Here is the code for tthe renderer.

Trust me, it is initialized in the main class, the clientproxy class, the guihandler class.

This is bassicly a rendere with only items attached to it. (entityItems)

 

public class RenderShield extends TileEntitySpecialRenderer{

public RenderShield()
{
}
private float pixel = 0.0625F;

private float scale = 1.3F;
private float scaleword = 1.6F;

int i;

public void renderTileEntityAt(TileEntityShield tileentity, double x, double y, double z, float f) 
{
	float itemx = (float) x;
	float itemy = (float) y;
	float itemz = (float) z;

	if (!tileentity.hasWorldObj())
	{
		i = 0;
	}
	else
	{
		i = tileentity.getBlockMetadata();
	}
	short rot = 0;
	if (i == 4)
	{
		rot = 180;
		itemx = (float)(x + 1.0F);
	}
	if (i == 5)
	{
		rot = 0;
		itemz = (float)(z + 1.0F);
	}
	if (i == 3)
	{
		rot = -90;
	}
	if (i == 2)
	{
		rot = 90;
		itemx = (float)(x + 1.0F);
		itemz = (float)(z + 1.0F);
	}

	GL11.glPushMatrix();
	GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	this.renderItems(tileentity, itemx, itemy, itemz, rot);
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	GL11.glPopMatrix();
}

private float getX(float x, float pixelcount)
{
	if(i == 5){ return x + (pixel * pixelcount); }
	if(i == 3){ return x + (pixel * pixelcount); }
	if(i == 4){ return x - (pixel * pixelcount); }
	if(i == 2){ return x - (pixel * pixelcount); }
	else{ return x + (pixel * pixelcount) ;}
}

private float getZ(float z, float pixelcount)
{
	if(i == 4){ return z + (pixel * pixelcount); }
	if(i == 3){ return z + (pixel * pixelcount); }
	if(i == 5){ return z - (pixel * pixelcount); }
	if(i == 2){ return z - (pixel * pixelcount); }
	else{ return z + (pixel * pixelcount) ;}
}

private void renderItems(TileEntityShield tileentity, float itemx, float itemy, float itemz, float rot)
{
	GameSettings settings = Minecraft.getMinecraft().gameSettings;

	ItemStack[] itemstack = new ItemStack[2];

	for(int i = 0; i < itemstack.length; i++){
		itemstack[i] = tileentity.getOneItem(i);
	}

	float shieldxyz = 0.5F;
	if(itemstack[0] != null || itemstack[1] != null)
	{
		shieldxyz = 1.2F;
	}

	EntityItem shield = new EntityItem(tileentity.getWorldObj(), tileentity.xCoord, tileentity.yCoord, tileentity.zCoord, new ItemStack(AgeCraft.Decorative_Shield));
	shield.hoverStart = 0;


	EntityItem entItem;

	boolean fancystart = false;

	if(settings.fancyGraphics)
	{
		fancystart = true;
	}

	if(!fancystart)
	{
		settings.fancyGraphics = true;
	}

	if(shield != null) {
		GL11.glPushMatrix();
		if(i == 4 | i == 5){
			GL11.glTranslatef((float)getX(itemx, shieldxyz), (float)itemy + (pixel * 4), (float)getZ(itemz, );	
		}else{
			GL11.glTranslatef((float)getX(itemx, , (float)itemy + (pixel * 4), (float)getZ(itemz, shieldxyz));	
		}
		GL11.glScalef(scale, scale, scale);
		GL11.glRotatef((float)(rot-90), 0.0F, 1.0F, 0.0F);
		RenderManager.instance.renderEntityWithPosYaw(shield, 0, 0, 0, 0, 0);
		GL11.glPopMatrix();
	}

	Item sword1 = Items.wooden_sword;
	Item sword2 = Items.stone_sword;
	Item sword3 = Items.iron_sword;
	Item sword4 = Items.golden_sword;
	Item sword5 = Items.diamond_sword;

	if(itemstack[1] != null) {
		if(itemstack[1].getItem() == sword1 || itemstack[1].getItem() == sword2 || itemstack[1].getItem() == sword3 || 
				itemstack[1].getItem() == sword4 || itemstack[1].getItem() == sword5)
		{
			GL11.glPushMatrix();
			if(i == 4 | i == 5){
				GL11.glTranslatef((float)getX(itemx, 0.6F), (float)itemy + (pixel * 15), (float)getZ(itemz, 9));	
			}else{
				GL11.glTranslatef((float)getX(itemx, 9), (float)itemy + (pixel * 15), (float)getZ(itemz, 0.6F));	
			}
			GL11.glScalef(scaleword, scaleword, scaleword);

			GL11.glRotatef((float)(rot-90), 0.0F, 1.0F, 0.0F);
			GL11.glRotatef(180, 0.0F, 0.0F, 1.0F);
			entItem = new EntityItem(tileentity.getWorldObj(), tileentity.xCoord, tileentity.yCoord, tileentity.zCoord, itemstack[1]);
			entItem.hoverStart = 0;
			RenderManager.instance.renderEntityWithPosYaw(entItem, 0, 0, 0, 0, 0);
			GL11.glPopMatrix();
		}
	}
	if(itemstack[0] != null) {
		if(itemstack[0].getItem() == sword1 || itemstack[0].getItem() == sword2 || itemstack[0].getItem() == sword3 || 
				itemstack[0].getItem() == sword4 || itemstack[0].getItem() == sword5)
		{
			GL11.glPushMatrix();
			if(i == 4 || i == 5){
				GL11.glTranslatef((float)getX(itemx, 0.6F), (float)itemy + (pixel * 9.2F), (float)getZ(itemz, 1));	
			}else{
				GL11.glTranslatef((float)getX(itemx, 1), (float)itemy + (pixel * 9.2F), (float)getZ(itemz, 0.6F));	
			}
			GL11.glScalef(scaleword, scaleword, scaleword);
			GL11.glRotatef((float)(rot-90), 0.0F, 1.0F, 0.0F);
			GL11.glRotatef(90, 0.0F, 0.0F, 1.0F);
			entItem = new EntityItem(tileentity.getWorldObj(), tileentity.xCoord, tileentity.yCoord, tileentity.zCoord, itemstack[0]);
			entItem.hoverStart = 0;
			RenderManager.instance.renderEntityWithPosYaw(entItem, 0, 0, 0, 0, 0);
			GL11.glPopMatrix();
		}
	}

	if(!fancystart)
	{
		settings.fancyGraphics = false;
	}

}

@Override
public void renderTileEntityAt(TileEntity tileentity, double d0, double d1, double d2, float f) {
	this.renderTileEntityAt((TileEntityShield)tileentity, d0, d1, d2, f);
}

}

 

 

I hope you can give me more info on the problem.

If these file are not the one you want, I can post others too.

 

thanks in advance

Coding, Testing, Smiling, Publishing!

Link to comment
Share on other sites

As far as opening a GUI, the server side has to tell the client side to open the GUI while the server uses the Container. Packets... use them.

Link to comment
Share on other sites

As far as opening a GUI, the server side has to tell the client side to open the GUI while the server uses the Container. Packets... use them.

 

Yes, I did that, but it still does not work.

Look, this is the guihandler I use.

 

public class GuiHandler implements IGuiHandler {

@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { 
	switch(id){
	case 0:
		return new ContainerShield(player.inventory, (TileEntityShield) world.getTileEntity(x, y, z));

	}

	return null;
}

@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
	switch(id){
	case 0:
		return new GuiShield(player.inventory, (TileEntityShield) world.getTileEntity(x, y, z));

	}

	return null;

}
}

Coding, Testing, Smiling, Publishing!

Link to comment
Share on other sites

Use this:

 

@Override
public TileEntity createNewTileEntity(World var1, int metadata)
{
return new TileEntityShield();
}

 

Your other TileEntity method isn't getting called because it was removed for a meta-sensitive version. Also, please, please, PLEASE use @Override notations in your code...it'll save so much headache both for us and you. You can automagically tell which method is not getting called by using that notation.

 

*sigh*

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.