Jump to content

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


LiamR99

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • \Downloads\RAD2-Serverpack-1.11\RAD2-Serverpack-1.11>java -Xmx4G -jar forge-1.16.5-36.2.39.jar nogui 2024-06-07 07:44:01,788 main WARN Advanced terminal features are not available in this environment [07:44:01] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.39, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [07:44:01] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.1.3+8.1.3+main-8.1.x.c94d18ec starting: java version 17.0.1 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0xadd0edd) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0xadd0edd         at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:45)         at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95)         at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:45)         at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55)         at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47)         at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62)         at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55)         at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)         at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:49)         at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:46)         at net.minecraftforge.server.ServerMain.main(ServerMain.java:43) C:\Users\coleh\Downloads\RAD2-Serverpack-1.11\RAD2-Serverpack-1.11>pause Press any key to continue . . .
    • https://pastebin.com/GHKKM4Xg found it!
    • i wanted to create a new survival with all those mods. but this happend. i runned minecraft forge but in the loading it crashed. help me. P.S. i don't know why i don't have the log.
    • That appears to have fixed the issue, thank you :]
  • Topics

×
×
  • Create New...

Important Information

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