Jump to content

TileEntitySpecialRenderer does not face the correct direction.


Raycoms

Recommended Posts

I have a tileEntity which should face the way the player places it.

currently I used some constants so it faces north at least.

Without the constants if I fill in x and z as posX and posZ the block will follow the player.

Without the rotation my block seems upside down.

I set all the variables in the block so I am able to get the facing from the block state.

But I don't know how to set the renderer up.

 

 

@SideOnly(Side.CLIENT)
public class TileEntityScarecrowRenderer extends TileEntitySpecialRenderer<ScarecrowTileEntity>
{
    /**
     * The model of the scarecrow.
     */
    private final ModelScarecrowBoth model;

    /**
     * Offset to the block middle.
     */
    private static final double BLOCK_MIDDLE = 0.5;

    /**
     * Y-Offset in order to have the scarecrow over ground.
     */
    private static final double YOFFSET = 1.5;

    /**
     * Which size the scarecrow should have ingame.
     */
    private static final double SIZERATIO = .0625;

    /**
     * Rotate the model some degrees.
     */
    private static final int ROTATION = 180;

    /**
     * Rotate it on the following x offset.
     */
    private static final float XROTATIONOFFSET = 0.311F;

    /**
     * Rotate it on the following y offset.
     */
    private static final float YROTATIONOFFSET = 0.0F;

    /**
     * Rotate it on the following z offset.
     */
    private static final float ZROTATIONOFFSET = 2.845F;


    /**
     * The public constructor for the renderer.
     */
    public TileEntityScarecrowRenderer()
    {
        super();
        this.model = new ModelScarecrowBoth();
    }
    
    @Override
    public void renderTileEntityAt(ScarecrowTileEntity te, double posX, double posY, double posZ, float partialTicks, int destroyStage)
    {
        //Store the transformation
        GlStateManager.pushMatrix();
        //Set viewport to tile entity position to render it
        GlStateManager.translate(posX+BLOCK_MIDDLE, posY+YOFFSET, posZ+BLOCK_MIDDLE);

        this.bindTexture(getResourceLocation(te));

        GlStateManager.rotate(ROTATION, XROTATIONOFFSET, YROTATIONOFFSET, ZROTATIONOFFSET);
        this.model.render((float) SIZERATIO);
        
        /* ============ Rendering Code stops here =========== */
        //Restore the transformation, so other renderer's are not messed up.
        GlStateManager.popMatrix();
    }

    /**
     * Returns the ResourceLocation of the scarecrow texture.
     * @param tileEntity the tileEntity of the scarecrow.
     * @return the location.
     */
    private static ResourceLocation getResourceLocation(ScarecrowTileEntity tileEntity)
    {
        String loc;
        
        if(tileEntity.getType() == ScarecrowTileEntity.ScareCrowType.PUMPKINHEAD)
        {
            loc = "textures/blocks/blockScarecrowPumpkin.png";
        }
        else
        {
            loc = "textures/blocks/blockScarecrowNormal.png";
        }
        
        return new ResourceLocation(Constants.MOD_ID + ":" + loc);
    }

Link to comment
Share on other sites

I unfortunately only have a .java model of the scarecrow how should I do it then?

With the new block model system...

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I stored the rotation in the BlockState of my custom block and I am able to retrieve it in the tileEntitySpecialRenderer.

 

But the State is an EnumFacing and I don't actually know how I should rotate it.

GL11.rotatef(...)

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I use GlStateManager.rotate(180, 0.3, 0.0 2.845);

This fixed variables let my scarecrow face north being in the correct position.

 

What do I have to change to have him show into any EnumFacing?

EnumFacing says which way it is facing so after rotating it to face north, check if it is facing a direction lets say south, if it is rotate it again to the correct position.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.