Jump to content

Recommended Posts

Posted

I wanted to make a block similar that looks similar to a furnace. I need it to change the front face based on where you are looking, like a furnace.

If someone could post up code it would be [glow=yellow,2,300]awesome[/glow]!  ;)

;) I am new to forge however am experienced in Java! ;)
Posted

Ok cool thanks I've copied the code, it all works smoothly, except for one thing, the furnace faces always a set direction; it never changes. I checked the furnace code and well i have been unsuccessful...

-------------------------------------------------------------------------------------------------------------------------------

@SideOnly(Side.CLIENT)

    private Icon furnaceIconTop;

    @SideOnly(Side.CLIENT)

    private Icon furnaceIconFront;

 

    /**

    * Called whenever the block is added into the world. Args: world, x, y, z

    */

    public void onBlockAdded(World par1World, int par2, int par3, int par4)

    {

        super.onBlockAdded(par1World, par2, par3, par4);

        this.setDefaultDirection(par1World, par2, par3, par4);

    }

 

    /**

    * set a blocks direction

    */

    private void setDefaultDirection(World par1World, int par2, int par3, int par4)

    {

        if (!par1World.isRemote)

        {

            int l = par1World.getBlockId(par2, par3, par4 - 1);

            int i1 = par1World.getBlockId(par2, par3, par4 + 1);

            int j1 = par1World.getBlockId(par2 - 1, par3, par4);

            int k1 = par1World.getBlockId(par2 + 1, par3, par4);

            byte b0 = 3;

 

            if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])

            {

                b0 = 3;

            }

 

            if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])

            {

                b0 = 2;

            }

 

            if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])

            {

                b0 = 5;

            }

 

            if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])

            {

                b0 = 4;

            }

 

            par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);

        }

    }

 

    @SideOnly(Side.CLIENT)

 

    /**

    * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata

    */

    public Icon getIcon(int par1, int par2)

    {

        return par1 == 1 ? this.furnaceIconTop : (par1 == 0 ? this.furnaceIconTop : (par1 != par2 ? this.blockIcon : this.furnaceIconFront));

    }

 

    @SideOnly(Side.CLIENT)

 

    /**

    * When this method is called, your block should register all the icons it needs with the given IconRegister. This

    * is the only chance you get to register icons.

    */

    public void registerIcons(IconRegister par1IconRegister)

    {

        this.blockIcon = par1IconRegister.registerIcon("furnace_side");

        this.furnaceIconFront = par1IconRegister.registerIcon("furnace_front_off");

        this.furnaceIconTop = par1IconRegister.registerIcon("furnace_top");

    }

----------------------------------------------------------------------------------------------------------

If i could get some help that would be awesome!

For some reason the code thing isn't working....

;) I am new to forge however am experienced in Java! ;)
Posted

Ok cool thanks I've copied the code, it all works smoothly, except for one thing, the furnace faces always a set direction; it never changes. I checked the furnace code and well i have been unsuccessful...

------------------------------------------------------------------------------------------------------------------------------

So, what you want the face to change sides dynamically when you walk around it?

Posted

You want to copy onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)

 

That is where the direction is determined and set.

 

Posted

Thank you so much but one more problem.... the block. When you hold a furnace on the right hand side of the icon is the front and on the left side is the side icon. How can i make the icon of my item like that. both the left and right side is the icon for the side.

;) I am new to forge however am experienced in Java! ;)
Posted

The Furnace uses metadata to determine it's placed direction (even when rendering on the hotbar.) The facing when in inventory is due to a trick in RenderBlocks where renderBlockAsItem(Block, meta, color) changes the metadata of the furnace used to lookup icon to 2. So, it forces the furnace to face the proper way to render the item in the hotbar.

You might have to set your own block renderer to overcome that limitation.

A possible workaround I haven't tried is to always create your ItemStack with a furnace with metadata = 2. When it is actually placed it will change accordingly, of course.

Posted

The Furnace uses metadata to determine it's placed direction (even when rendering on the hotbar.) The facing when in inventory is due to a trick in RenderBlocks where renderBlockAsItem(Block, meta, color) changes the metadata of the furnace used to lookup icon to 2. So, it forces the furnace to face the proper way to render the item in the hotbar.

You might have to set your own block renderer to overcome that limitation.

A possible workaround I haven't tried is to always create your ItemStack with a furnace with metadata = 2. When it is actually placed it will change accordingly, of course.

You could also do something way more easy. If the furnace is in the inventory, the metadata is 0, but if it's placed down, the metadata is 2,3,4 or 5. So in your getIcon method, check for a metadata that's 0, and if the side is 2, you need to set the front texture.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.