Jump to content

Detect left click on block 1.16.x


NullDev

Recommended Posts

I want to detect when a player left clicks on a block, but onBlockClicked does nothing...

Here's my current code:

package com.nulldev.extremeskyblock.blocks;

import com.nulldev.extremeskyblock.util.RegistryHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;

public class CompactStoneBlock extends Block {
    public CompactStoneBlock(Material material, Float hardness, Float resistance, SoundType soundType, int harvestLevel, ToolType toolType) {
        super(Properties.create(material)
                .hardnessAndResistance(hardness, resistance)
                .sound(soundType)
                .harvestLevel(harvestLevel)
                .harvestTool(toolType));
    }

    @Override
    public void onBlockClicked(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
        ItemEntity stonePebble = new ItemEntity(worldIn, pos.getX(), pos.getY() + 2, pos.getZ(), new ItemStack(RegistryHandler.STONE_PEBBLE.get(), 1));
    }
}

But placing the block and clicking on it does nothing, and Intellij says that its deprecated but I cannot find anywhere what to use instead.

Link to comment
Share on other sites

1 hour ago, NullDev said:

Intellij says that its deprecated

You can override it.

1 hour ago, NullDev said:

But placing the block and clicking on it does nothing

You are creating the ItemEntity but aren't spawning it.

Edited by Danebi
  • Thanks 1
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.

Announcements



×
×
  • Create New...

Important Information

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