Jump to content

[1.10] When does getActualState get called?


luchong

Recommended Posts

I want to make a block that changes its model depending on the blocks around it. The most similar block I found in vanilla was the fence block and it uses getActualState()

 

When does that method get called and how do I know when X method in the Block class gets called (besides Forge comments, which a lot of the methods dont have)

 

Thanks

Link to comment
Share on other sites

I tried that but I dont get it: I created a class for my block, overwritten getActualState to do nothing but print to console. I dont call it anywhere else and it still prints sometimes when I place blocks or break them. The only methods in the Block class (the parent of my class) that call getActualState are getBedDirection, isBedFoot, isSideSolid and setBedOccupied. I don't see why any of those methods would be called

Link to comment
Share on other sites

Actually yes, but its called from some low level forge methods and I'm a begginer modder (not programmer) so I thought perhaps someone in the forums already knew about this and could share the information so I dont have to be a forge source code expert to make just a simple block. Apparently you don't know but thank you anyways

Link to comment
Share on other sites

getActualState() is called whenever the block is rendered to get the correct state. For example, to load the right texture or the right model.

 

Code from the Vanillacode class "BlockRendererDispatcher->renderBlock".

 

if (enumblockrendertype == EnumBlockRenderType.INVISIBLE)
            {
                return false;
            }
            else
            {
                if (blockAccess.getWorldType() != WorldType.DEBUG_WORLD)
                {
                    try
                    {
                        state = state.getActualState(blockAccess, pos);
                    }
                    catch (Exception var8)
                    {
                        ;
                    }
                }

                switch (enumblockrendertype)
                {
                    case MODEL:
                        IBakedModel model = this.getModelForState(state);
                        state = state.getBlock().getExtendedState(state, blockAccess, pos);
                        return this.blockModelRenderer.renderModel(blockAccess, model, state, pos, worldRendererIn, true);
                    case ENTITYBLOCK_ANIMATED:
                        return false;
                    case LIQUID:
                        return this.fluidRenderer.renderFluid(blockAccess, state, pos, worldRendererIn);
                    default:
                        return false;
                }
            }

 

 

Thats how I can see this in the code.

Link to comment
Share on other sites

Example: I have a block implementation with connections. So, for each side there is a boolean property which indicates whether there is a same block at that side. If true, they are rendered with a 'pipe' between them. This check is performed in getActualState and the blockstate file applies the appropriate model for rendering.

Link to comment
Share on other sites

getActualState() is called whenever the block is rendered to get the correct state. For example, to load the right texture or the right model.

 

Thank you, thats the kind of answer I was hoping for. One question that I have about this though is: if the method is called whenever the block is rendered, why is it printing to console only when i place or destroy a block that is near my block. Is it because blocks are re-rendered only when neccessary?

Link to comment
Share on other sites

Even more clear than using Eclipse to see method references is to set a breakpoint on BlockFence's getActualState and then run Minecraft in the debugger. Step out of the method and see what called it and what variables have what values. Maybe set another breakpoint somewhere upstream and continue.

 

The debugger is very powerful because it cuts through the fog of runtime polymorphism etc.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.



×
×
  • Create New...

Important Information

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