BlockTrap.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package me.km.blocks;
  2. import net.minecraft.block.Block;
  3. import net.minecraft.block.material.Material;
  4. import net.minecraft.block.state.IBlockState;
  5. import net.minecraft.util.BlockRenderLayer;
  6. import net.minecraft.util.math.AxisAlignedBB;
  7. import net.minecraft.util.math.BlockPos;
  8. import net.minecraft.world.IBlockAccess;
  9. import net.minecraft.world.World;
  10. import net.minecraftforge.fml.relauncher.Side;
  11. import net.minecraftforge.fml.relauncher.SideOnly;
  12. public class BlockTrap extends BlockBase
  13. {
  14. protected static final AxisAlignedBB BOX = new AxisAlignedBB(0, 0, 0, 1, 0.0625d, 1);
  15. public BlockTrap(Material material, String name, String local)
  16. {
  17. super(material, name, local);
  18. }
  19. @Override
  20. public void neighborChanged(IBlockState state, World w, BlockPos pos, Block b, BlockPos fromPos)
  21. {
  22. if(!w.getBlockState(pos.down()).getMaterial().isSolid())
  23. {
  24. this.dropBlockAsItem(w, pos, state, 0);
  25. w.setBlockToAir(pos);
  26. }
  27. super.neighborChanged(state, w, pos, b, fromPos);
  28. }
  29. @Override
  30. public boolean canPlaceBlockAt(World w, BlockPos pos)
  31. {
  32. return w.getBlockState(pos.down()).getMaterial().isSolid() && super.canPlaceBlockAt(w, pos);
  33. }
  34. @Override
  35. public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
  36. {
  37. return BOX;
  38. }
  39. @Override
  40. public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
  41. {
  42. return NULL_AABB;
  43. }
  44. @Override
  45. public boolean isOpaqueCube(IBlockState state)
  46. {
  47. return false;
  48. }
  49. @Override
  50. public boolean isFullCube(IBlockState state)
  51. {
  52. return false;
  53. }
  54. @Override
  55. public boolean canSpawnInBlock()
  56. {
  57. return false;
  58. }
  59. @SideOnly(Side.CLIENT)
  60. @Override
  61. public BlockRenderLayer getBlockLayer()
  62. {
  63. return BlockRenderLayer.CUTOUT;
  64. }
  65. @Override
  66. public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
  67. {
  68. return true;
  69. }
  70. }