Solution for the next gen who stumble upon this thread. Solution provided by Simon_kungen:
public VoxelShape getShape(BlockState state, IBlockReader reader, BlockPos position, ISelectionContext context)
{
return Block.makeCuboidShape(xMin, yMin, zMin, xMax, yMax, zMax); //all decimals
}
The boundingbox of my block isn't what I set it. I'm a newby and after 2 days of trying I still couldn't find the problem. I would really appreciate if someone could halp me out a bit.
Here is the blocks class.
package com.gyugya55.mymod.blocks;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
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 Abacus extends Block
{
public Abacus()
{
super(Properties.create(Material.WOOD)
.sound(SoundType.WOOD)
.hardnessAndResistance(0.1f,0.5f)
.lightValue(0)
);
setRegistryName("abacus");
}
@Override
public BlockRenderLayer getRenderLayer()
{
return BlockRenderLayer.CUTOUT_MIPPED;
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
if (entity != null) {
world.setBlockState(pos, state.with(BlockStateProperties.FACING, getFacingFromEntity(pos, entity)), 2);
}
}
public static Direction getFacingFromEntity(BlockPos clickedBlock, LivingEntity entity) {
return Direction.getFacingFromVector((float) (entity.posX - clickedBlock.getX()), (float) (entity.posY - clickedBlock.getY()), (float) (entity.posZ - clickedBlock.getZ()));
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(BlockStateProperties.FACING);
}
@Override
public boolean isNormalCube(BlockState state, IBlockReader reader, BlockPos position)
{
return false;
}
public VoxelShape getCollisionShape(BlockState state, IBlockReader reader, BlockPos position, ISelectionContext context)
{
return Block.makeCuboidShape(
0D, //x
0D, //y down
7D, //z
16D, //x
10.5D, //y up
9D //z
);
}
public AxisAlignedBB getBoundingBox()
{
return new AxisAlignedBB( 0D, 0D, 7D, 16D, 10.5D, 9D );
}
}
So this is the current bounding box of my object.
And this is what im trying to achive.