- 22
- 0
И так, смог понять как примерно работает колизия, но все же где-то ошибся и блок можно разместить внутри модели, а хитбокс всплывает только при наведении на блок-исходник. Код и скриншоты я размещу ниже.
Sideboard:
package com.ct.dpack.stuff.blocks;
import com.ct.dpack.DPackCore;
import com.ct.dpack.init.BlockInit;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.util.List;
public class Sideboard extends Block {
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public Sideboard(String name) {
super(Material.IRON);
this.setRegistryName(name);
this.setUnlocalizedName(name);
this.setCreativeTab(DPackCore.tabCTBase);
setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
}
@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
@Override
public boolean isFullCube(IBlockState state)
{
return false;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] { FACING });
}
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
public int getMetaFromState(IBlockState state)
{
int i = 0;
i |= ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
return i;
}
public IBlockState getStateFromMeta(int meta)
{
return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}
@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
super.onBlockClicked(worldIn, pos, playerIn);
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
double x1 = 0;
double x2 = 1;
double y1 = 0;
double y2 = 2;
double z1 = 0;
double z2 = 2;
return new AxisAlignedBB(x1, y1, z1, x2, y2, z2);
}
@Nullable
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
double x1 = 0;
double x2 = 1;
double y1 = 0;
double y2 = 2;
double z1 = 0;
double z2 = 2;
return new AxisAlignedBB(x1, y1, z1, x2, y2, z2);
}
}