Jump to content

[SOLVED]1.7.2 My custom rendered block will not face the player, HELP!


Recommended Posts

Posted

Hello, I recently started working on my new mod in which I have a custom rendered block. However whenever I enter game the block resets to its normal direction instead of the direction I placed it in. Someone else had this problem but they fixed it by registering the tile entity in their proxies, but this doesn't work for me...

 

Anyway, here's the code for my block:

public class EvilDeerBlock extends BlockContainer {

 

public EvilDeerBlock(Material p_i45386_1_) {

super(p_i45386_1_);

 

this.setHardness(2.0F);

this.setResistance(5.0F);

setBlockTextureName(EvilDeadMain.MODID + ":DeerHead");

 

this.setCreativeTab(EvilDeadMain.EvilDeadTab);

}

 

public int getRenderType(){

return -1;

 

}

public boolean isOpaqueCube(){

return false;

}

public boolean renderAsNormalBlock(){

return false;

}

 

@Override

public TileEntity createNewTileEntity(World var1, int var2) {

return new TileEntityEvilDeerBlock();

}

 

@Override

    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack)

    {

        int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;

        int newFacing = 0;

        if (facing == 0)

        {

        newFacing = 2;

        }

        if (facing == 1)

        {

        newFacing = 5;

        }

        if (facing == 2)

        {

        newFacing = 3;

        }

        if (facing == 3)

        {

        newFacing = 4;

        }

        TileEntity te = world.getTileEntity(i, j, k);

        if (te != null && te instanceof TileEntityEvilDeerBlock)

        {

        TileEntityEvilDeerBlock tet = (TileEntityEvilDeerBlock) te;

            tet.setFacingDirection(newFacing);

            world.markBlockForUpdate(i, j, k);

        }

    }

}

Tile Entity:

public class TileEntityEvilDeerBlock extends TileEntity {

 

private int facingDirection;

 

public int getFacingDirection()

    {

        return this.facingDirection;

    }

 

public void setFacingDirection(int par1)

    {

        this.facingDirection = par1;

    }

 

@Override

    public void readFromNBT(NBTTagCompound nbttagcompound)

    {

        super.readFromNBT(nbttagcompound); 

        facingDirection = nbttagcompound.getInteger("facingDirection");

    }

 

    @Override

    public void writeToNBT(NBTTagCompound nbttagcompound)

    {

        super.writeToNBT(nbttagcompound);

        nbttagcompound.setInteger("facingDirection", facingDirection);

    }

}

 

Render Block:

public class RenderEvilDeerBlock extends TileEntitySpecialRenderer{

 

private static final ResourceLocation texture = new ResourceLocation(EvilDeadMain.MODID + ":" + "textures/model/DeerHead.png");

 

private ModelDeerHead model;

 

public RenderEvilDeerBlock(){

this.model = new ModelDeerHead();

}

 

public void render(TileEntityEvilDeerBlock te, double x, double y, double z, float scale)

    {

    GL11.glPushMatrix();

        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);

        this.bindTexture(texture);

        //Rotates model, as for some reason it is initially upside (180 = angle, 1.0F at end = about z axis)

        GL11.glRotatef(180, 0.0F, 0.0F, 1.0F);

        int facing = te.getFacingDirection();

        int k = 0;

        //South

        if (facing == 2) {

            k = 0;

        }

        //North

        if (facing == 3) {

            k = 180;

        }

        //East

        if (facing == 4) {

            k = -90;

        }

        //West

        if (facing == 5) {

            k = 90;

        }

        //Rotates model on the spot, depending on direction, making the front always to player) (k = angle, 1.0F in middle = about y axis)

        GL11.glRotatef(k, 0.0F, 1.0F, 0.0F);

        GL11.glDisable(GL11.GL_CULL_FACE);

        GL11.glEnable(GL11.GL_ALPHA_TEST);

        this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        GL11.glPopMatrix();

}

 

   

    public void renderTileEntityAt(TileEntity p_147500_1_, double p_147500_2_, double p_147500_4_, double p_147500_6_, float p_147500_8_)

    {

    this.render((TileEntityEvilDeerBlock)p_147500_1_, p_147500_2_, p_147500_4_, p_147500_6_, p_147500_8_);

    }

}

 

 

And my client and common proxy:

Client:

 

public class ClientProxy extends CommonProxy {

 

public void registerRenderThings(){

 

TileEntitySpecialRenderer render = new RenderEvilDeerBlock();

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEvilDeerBlock.class, render);

MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EvilDeadMain.blockEvilDeer), new RenderItemDeerBlock(render, new TileEntityEvilDeerBlock()));

}

public void registerTileEntitySpecialRenderer(){

 

}

@Override

public void registerItemRenderers(){

 

MinecraftForgeClient.registerItemRenderer(EvilDeadMain.ChainsawHand, new RenderChainsawHand());

 

 

}

 

}

 

Common:

public class CommonProxy {

 

public void registerRenderThings(){

 

}

public void registerTileEntitySpecialRenderer(){

 

}

public void registerItemRenderers() {

 

 

}

}

 

 

Thanks for taking a look, I appreciate it!!!

 

- LiamR99

Posted

Hi

 

From memory you need to implement these methods in your custom TileEntity, so that the saved value of facing on the server is communicated to the client upon world reload.

 

    /**
     * Called when you receive a TileEntityData packet for the location this
     * TileEntity is currently in. On the client, the NetworkManager will always
     * be the remote server. On the server, it will be whomever is responsible for
     * sending the packet.
     *
     * @param net The NetworkManager the packet originated from
     * @param pkt The data packet
     */
    public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
    {
    }


    public Packet getDescriptionPacket()
    {
    }

 

A tutorial on TileEntities should show the way.  Unfortunately I don't remember specifics off the top of my head.

 

-TGG

Posted

Thanks for the help! It turned out my tileentity wasn't registered either and I needed to put this code in my tileentity class:

 

@Override

    public void readFromNBT(NBTTagCompound nbttagcompound)

    {

        super.readFromNBT(nbttagcompound); 

        facingDirection = nbttagcompound.getInteger("facingDirection");

    }

 

    @Override

    public void writeToNBT(NBTTagCompound nbttagcompound)

    {

        super.writeToNBT(nbttagcompound);

        nbttagcompound.setInteger("facingDirection", facingDirection);

    }

    @Override

    public Packet getDescriptionPacket()

    {

        NBTTagCompound tag = new NBTTagCompound();

        writeToNBT(tag);

        return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);

    }

 

    @Override

    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)

    {

        readFromNBT(packet.func_148857_g());

    }

 

}

 

Thank you so much!

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.