Jump to content

Recommended Posts

Posted

I tried to make this block deal damage to the player when they walk on it and is not working I think because of the custom hit box.

here is my block class:

package com.ModdingMinecraft.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;

public class BlockBanana_Peel extends Block {

    private static final VoxelShape SHAPE = Block.makeCuboidShape(3.0d, 0.0d, 3.0d, 14.0d, 1.0d, 13.0d);

    public BlockBanana_Peel() {
        super(Block.Properties.create(Material.ORGANIC)
                .speedFactor(10)
                .notSolid()
                .lightValue(1)
                .slipperiness(10)
                .harvestLevel(0)
        );

    }
    @Override
    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        return SHAPE;
    }

    public void onEntityWalk(World worldIn, BlockPos pos, Entity entityIn) {
        if (!entityIn.isSneaking()) {
            entityIn.attackEntityFrom(DamageSource.FALLING_BLOCK, 10.0F);
        }

        super.onEntityWalk(worldIn, pos, entityIn);
    }
}

 

What am I doing wrong? 

Posted

Well it definitely doesn't help if you can just walk right through the block. How am I supposed to walk on a block that I can't even touch? You might want to check Block::onEntityCollision since you would be inside the VoxelShape of the block.

Posted
16 minutes ago, ChampionAsh5357 said:

Well it definitely doesn't help if you can just walk right through the block. How am I supposed to walk on a block that I can't even touch? You might want to check Block::onEntityCollision since you would be inside the VoxelShape of the block.

Thank you so much! It worked!

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.