Jump to content

[1.8] [SOLVED] Get TileEntity from IBlockState in ISmartBlockModel


ss7

Recommended Posts

Hello,

 

Is it possible to get an instance of my

TileEntity

from the

IBlockState

, which is passed to the

handleBlockState

function of

ISmartBlockModel

?

 

Basically, I need to render a block based on the data from my

TileEntity

.

 

My first idea was to use a

TileEntitySpecialRenderer

, but that was too inefficient for my case of rendering.

 

Then I found the excellent tutorial from @herbix, that explained the use of the new

IBakedModel

in 1.8.

 

Unfortunately, it seems that you can only use the block state from a block in the

handleBlockState

method.

 

But I need to store more than 4 bits in my block.

 

I hope you can help me :)

 

ss7

You sir are a god damn hero.

Link to comment
Share on other sites

You could store ANYTHING in IExtendedBlockState, in case the property is unlisted.

For example:

    public static final IUnlistedProperty<TileEntity> TILE_ENTITY = new IUnlistedProperty<TileEntity>() {
        @Override
        public String getName() {
            return "tileEntity";
        }
        @Override
        public boolean isValid(TileEntity value) {
            return true;
        }
        @Override
        public Class<TileEntity> getType() {
            return TileEntity.class;
        }
        @Override
        public String valueToString(TileEntity value) {
            return value.toString();
        }
    };
    ...
    @Override
    public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
        if(state instanceof IExtendedBlockState) {
            TileEntity te = ... // Get your tile entity here
            return ((IExtendedBlockState)state).withProperty(TILE_ENTITY, te);
        }
        return state;
    }

Author of Tao Land Mod.

width=200 height=69http://taoland.herbix.me/images/1/14/TaoLandLogo.png[/img]

Also, author of RenderTo

----

I'm not an English native speaker. I just try my best.

Link to comment
Share on other sites

Thank you very much guys!

 

At first, I tried overriding the

getActualState

method, but for some reason my

BakedModel

wasn't rendering anymore.

 

So I tried herbix' solution, and it worked like a charm!

 

Thank you very much again and this thread is now

 

SOLVED

You sir are a god damn hero.

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.