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

Hello,

I am trying to create a block that will trigger a redstone power for 10~15 seconds after being right-clicked with a specific item.

I can render the block when if has no functions/property.

But when I try to add a 'is_activating' property, the game crash on load with the following exception:

Quote

[11:37:00] [Render thread/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: Cannot set property BooleanProperty{name=is_activating, clazz=class java.lang.Boolean, values=[true, false]} as it does not exist in Block{null}

This is my block code (I copied the functions from the Lever class):

public class ActivatorBlock extends HorizontalDirectionalBlock {
    public static final BooleanProperty IS_ACTIVATING = BooleanProperty.create("is_activating");

    public ActivatorBlock(Properties properties) {
        super(properties);
        registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH).setValue(IS_ACTIVATING, Boolean.valueOf(false)));
    }

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

    @Override
    public BlockState getStateForPlacement(BlockPlaceContext context) {
        return defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
    }

    @Override
    public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
        if (level.isClientSide) {
            BlockState blockstate1 = blockState.cycle(IS_ACTIVATING);

            return InteractionResult.SUCCESS;
        } else {
            BlockState blockstate = this.pull(blockState, level, blockPos);
            float f = blockstate.getValue(IS_ACTIVATING) ? 0.6F : 0.5F;
            level.playSound((Player)null, blockPos, SoundEvents.LEVER_CLICK, SoundSource.BLOCKS, 0.3F, f);
            level.gameEvent(player, blockstate.getValue(IS_ACTIVATING) ? GameEvent.BLOCK_SWITCH : GameEvent.BLOCK_UNSWITCH, blockPos);
            return InteractionResult.CONSUME;
        }
    }

    public BlockState pull(BlockState p_54677_, Level p_54678_, BlockPos p_54679_) {
        p_54677_ = p_54677_.cycle(IS_ACTIVATING);
        p_54678_.setBlock(p_54679_, p_54677_, 3);
        this.updateNeighbours(p_54677_, p_54678_, p_54679_);
        return p_54677_;
    }

    public int getSignal(BlockState p_54635_, BlockGetter p_54636_, BlockPos p_54637_, Direction p_54638_) {
        return p_54635_.getValue(IS_ACTIVATING) ? 15 : 0;
    }

    public int getDirectSignal(BlockState p_54670_, BlockGetter p_54671_, BlockPos p_54672_, Direction p_54673_) {
        return p_54670_.getValue(IS_ACTIVATING) ? 15 : 0;
    }

    public boolean isSignalSource(BlockState p_54675_) {
        return true;
    }

    private void updateNeighbours(BlockState p_54681_, Level p_54682_, BlockPos p_54683_) {
        p_54682_.updateNeighborsAt(p_54683_, this);
        //p_54682_.updateNeighborsAt(p_54683_.relative(getConnectedDirection(p_54681_).getOpposite()), this);
    }
}

The block is registered as:

    public static final BlockBehaviour.Properties TEST_BLOCK_PROPERTIES = BlockBehaviour.Properties
            .of(Material.GLASS, MaterialColor.TERRACOTTA_BLACK)
            .strength(-1.0F, 3600000.0F)
            .noDrops()
            .sound(SoundType.METAL);

    public static final RegistryObject<Block> ACTIVATOR_BLOCK = BLOCKS.register("activator_block", () -> new ActivatorBlock(TEST_BLOCK_PROPERTIES));

Edited by Ideki

  • Author

It is always the most obvious things that escape us the most.

Thanks a lot

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.