0

如果我有一个 3 x 3 块模型的图块实体,如何使块命中框与模型一样大?从 1.8 开始,该setSize功能似乎不起作用,setBlockBounds只是重新调整了选择框的大小,而不是点击框。

我的代码:

package tutorial.generic;

import net.minecraft.block.Block;
import net.minecraft.block.BlockRail;
import net.minecraft.block.BlockRailBase;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class railControlBlock extends BlockRail implements ITileEntityProvider {

public static final PropertyEnum SHAPE = PropertyEnum.create("shape", BlockRailBase.EnumRailDirection.class);
private static String name = "railControlBlock";

public railControlBlock() {

    super();
    GameRegistry.registerTileEntity(railControl.class, name);
    setDefaultState(this.blockState.getBaseState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH));
    GameRegistry.registerBlock(this, name);
    this.setCreativeTab(CreativeTabs.tabMisc);
    this.setUnlocalizedName(name);
    this.setBlockBounds(-1.0F, 0.0F, -1.0F, 2.0F, 0.125F, 2.0F);
    this.setHardness(2.0f);
    this.setResistance(6.0f);
    this.setHarvestLevel("pickaxe", 2);
    this.isBlockContainer = true;

}

@Override
public String toString() {
    return getName();
}



@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
    return new railControl();
}



public static String getName(){
    return name;
}



  @SideOnly(Side.CLIENT)
  public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
  {
    setBlockBoundsBasedOnState(worldIn, pos);
    return super.getSelectedBoundingBox(worldIn, pos);
  }

public IProperty getShapeProperty()
  {
    return SHAPE;
  }



  public IBlockState getStateFromMeta(int meta)
  {
    return getDefaultState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.byMetadata(meta));
  }

  @Override
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
    {

            this.setBlockBounds(-1.0F, 0.0F, -1.0F, 2.0F, 0.125F, 2.0F);

    }

  public int getMetaFromState(IBlockState state)
  {
    return ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).getMetadata();
  }

  protected BlockState createBlockState()
  {
    return new BlockState(this, new IProperty[] { SHAPE });
  }



  public boolean isOpaqueCube()
  {
  return false;
  }
  /**
  * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  */

  public boolean renderAsNormalBlock()
  {
  return false;
  }

  public int getRenderBlockPass()
  {
  return 1;
  }

  protected void onNeighborChangedInternal(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
  {
    //whenever the blocks around it change
  }


}
4

0 回答 0