Jump to content

Recommended Posts

Posted (edited)

Hello,

I am trying to create a transparent block.

It looks like previous version of minecraft supported the following code:

    @Override
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT_MIPPED;
    }

    @Override
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

But 1.18 does not seem to have those classes.

This is my class:

public class ActivatedDisappearBlock extends Block {
    public static final BooleanProperty IS_ACTIVATED = BooleanProperty.create("is_activated");

    public ActivatedDisappearBlock(Properties properties) {
        super(properties);
        registerDefaultState(defaultBlockState().setValue(IS_ACTIVATED, Boolean.valueOf(false)));
    }

    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        super.createBlockStateDefinition(builder);
        builder.add(IS_ACTIVATED);
    }

    private boolean isVanished(BlockState state) {
        return state.hasProperty(IS_ACTIVATED) && state.getValue(IS_ACTIVATED);
    }

     // Compilation fails
    @Override
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT_MIPPED;
    }

     // Compilation fails
    @Override
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

    @Override
    public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext ctx) {
        return isVanished(state) ? Shapes.empty() : super.getShape(state, world, pos, ctx);
    }

    @Override
    public VoxelShape getCollisionShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext ctx) {
        return isVanished(state) ? Shapes.empty() : super.getCollisionShape(state, world, pos, ctx);
    }

    public void neighborChanged(BlockState blockState, Level level, BlockPos blockPos, Block blockIn, BlockPos fromPos, boolean isMoving) {
        if (!level.isClientSide) {
            System.out.println(blockState);
            if (blockIn instanceof ActivatorBlock){
                ActivatorBlock activator = (ActivatorBlock)blockIn;
                BlockState state = level.getBlockState(fromPos);
                var activating = state.getValue(IS_ACTIVATING);
                System.out.println(activating);
                blockState = blockState.setValue(IS_ACTIVATED, activating);
                level.setBlock(blockPos, blockState, 3);
                level.blockEntityChanged(blockPos);
                level.updateNeighbourForOutputSignal(blockPos, blockState.getBlock());
            }
        }
    }
}

 

Edited by Ideki
Cleanup
Posted
7 hours ago, Ideki said:

I am trying to create a transparent block.

You need to set the RenderLayer in FMLClientSetupEvent via ItemBlockRenderTypes#setRenderLayer 

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.