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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.