Jump to content

[1.12] Block does not load correctly from tile entity on world load.


Recommended Posts

Posted (edited)

Edit: The problem was that i didn't override the method Block#getActualState.

 

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

 

Original post:

 

Hi.

I'm trying to make a logic block. Some sides of the block will be the input and a face will be the output. The input faces can be changed with a right-click on the cube, for example the initial state will be 'inputs from left and behind the block', and with a right click  the state will change to 'inputs from left and right the block'. This is stored as an integer in a tile entity. It also changes texture for every state.

 

Everything works fine, except when I exit the game and enter again. When I enter the game and load the world, the block shows as the default state, and not the state from the tile entity. But if the block get right-clicked, it goes into the state it should go as if nothing happend.

For example, the default state is 0 (and the max is 3). I log out when the block is in state 2. When I enter, the block shows as state 0, but if I right-click it, it goes to state 3.

 

My code is here.

My problem is related with the `blocks/base_blocks/LogicBlock` class and  `blocks/datablock/LogicTileEntity` class.

 

Thanks for your time.

Edited by AngheloAlf
Posted

Try calling super inside onDataPacket.

Only thing I can see that might be related.

 

You do have some other code style issues, though. Such as this entire class:

https://github.com/AngheloAlf/MC_ALF_Logic_Gates/blob/bddec5d68621280db1f396e23da0f41506a74775/src/main/java/angheloalf/alf_logic_gates/blocks/base_blocks/AlfBaseBlock.java

Inheritance for code reuse is an antipattern.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Try adding...

public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
    	LogicTileEntity logicTileEntity = getTE(worldIn, pos);
    	if(logicTileEntity!=null)
    		return state.withProperty(BLOCK_STATE, logicTileEntity.getClickCount());
    	else
    		return state.withProperty(BLOCK_STATE, 0);
    }

to 'blocks/base_blocks/LogicBlock'

Posted

 

11 hours ago, Draco18s said:

Try calling super inside onDataPacket.

Only thing I can see that might be related.

 

Well, this didn't work.

 

 

10 hours ago, supercat765 said:

Try adding...


public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
    	LogicTileEntity logicTileEntity = getTE(worldIn, pos);
    	if(logicTileEntity!=null)
    		return state.withProperty(BLOCK_STATE, logicTileEntity.getClickCount());
    	else
    		return state.withProperty(BLOCK_STATE, 0);
    }

to 'blocks/base_blocks/LogicBlock'

And this breaks the textures changing.

 

Any other ideas? :(

Posted
14 hours ago, AngheloAlf said:

For example, the default state is 0 (and the max is 3). I log out when the block is in state 2. When I enter, the block shows as state 0, but if I right-click it, it goes to state 3.

I might be blind here but I see absolutely nothing that would make the blockstate have the clicked property from your TE upon reloading the world. You are not referencing your TE in Block#getActualState, you don't even have that method and you are not serializing the property into metadata. What makes you think it would magically persist then? The TE saves the counter just fine, it's the blockstate that doesn't. As @supercat765 said you need to include the property in your Block#getActualState. That also means that you need to include the variants in your blockstate file for the model to work.

Posted (edited)
2 hours ago, V0idWa1k3r said:

You are not referencing your TE in Block#getActualState, you don't even have that method and you are not serializing the property into metadata.

I tried this when @supercat765 said it, but the bug still persists, and even this add a new bug, the textures not changing when right-clicking the block.

 

2 hours ago, V0idWa1k3r said:

That also means that you need to include the variants in your blockstate file for the model to work.

Emm, what?

Edited by AngheloAlf
Posted
15 minutes ago, AngheloAlf said:

Emm, what?

My bad, I misread this

4 hours ago, AngheloAlf said:

And this breaks the textures changing.

As "this breaks textures". Now when I've looked at your blockstates I see that you are good on variants.

 

21 minutes ago, AngheloAlf said:

the bug still persists, and even this add a new bug, the textures not changing when right-clicking the block.

I am actually unable to reproduce the issue described in my local copy of your repository. After adding this

@Override
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        return super.getActualState(state, worldIn, pos).withProperty(BLOCK_STATE, ((LogicTileEntity)worldIn.getTileEntity(pos)).getClickCount());
    }

To the LogicBlock class I am able to both click the block and see the texture changes as well as relog into the world and see the correct textures(and by proxy the correct state)

Posted
2 hours ago, V0idWa1k3r said:

After adding this


@Override
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        return super.getActualState(state, worldIn, pos).withProperty(BLOCK_STATE, ((LogicTileEntity)worldIn.getTileEntity(pos)).getClickCount());
    }

 

Somehow this fixed the issue. I don't know how the other solution didn't work.

 

Thanks a lot for the help!

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.