Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I got a Block with two models. When one of these Blocks is connected to an other one it should change the state to blocked, else unblocked. Sounds simple.

Here is the working code for changing the state when the Block is placed and the actual state handling:

@Override
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
        for(EnumFacing facing : EnumFacing.HORIZONTALS){
            if(world.getBlockState(pos.offset(facing)).getBlock() == this){
                //Block found -> block
                TEForgeDistributor distributor = (TEForgeDistributor)world.getTileEntity(pos);
                if(!distributor.isBlocked()) {
                    distributor.setState(true);
                    distributor.markDirty();
                    world.markBlockForUpdate(pos);
                    return;
                }
            }
        }                
        //no block found -> unblock
        TEForgeDistributor distributor = (TEForgeDistributor)world.getTileEntity(pos);
        if(distributor.isBlocked()) {
            distributor.setState(false);
            distributor.markDirty();
            world.markBlockForUpdate(pos);
        }
    }

    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
        if(world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof TEForgeDistributor){
            TEForgeDistributor distributor = (TEForgeDistributor)world.getTileEntity(pos);
            return state.withProperty(BlockStateProperties.BLOCKED, distributor.isBlocked());
        }
        return state;
    }

 

So far everything is working good and instant. But when I use the neighbor Block Change method, the state changes also instant, but the Client only updates the model when an other block in a close range produces a update.

Neighbor Block Change Method:

@Override
    public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighborBlock) {
        for(EnumFacing facing : EnumFacing.HORIZONTALS){
            if(world.getBlockState(pos.offset(facing)).getBlock() == this){
                TEForgeDistributor distributor = (TEForgeDistributor)world.getTileEntity(pos);
                distributor.setState(true);
                distributor.markDirty();
                world.markBlockForUpdate(pos);
                return;
            }
        }
        TEForgeDistributor distributor = (TEForgeDistributor)world.getTileEntity(pos);
        distributor.setState(false);
        distributor.markDirty();
        world.markBlockForUpdate(pos);
    }

 

I'm running out of Ideas, is something missing or is this a bug. When I Output the state on both sides it has the correct state. Only the model is not updating.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.