Advertisement
Creepinson

movingblockentity

Jun 18th, 2017
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. package me.creepinson.block;
  2.  
  3. import me.creepinson.entity.EntityMovingBlock;
  4. import me.creepinson.tileentity.TECreepinoSkull;
  5. import net.minecraft.block.BlockDirectional;
  6. import net.minecraft.block.ITileEntityProvider;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.block.properties.IProperty;
  9. import net.minecraft.block.properties.PropertyDirection;
  10. import net.minecraft.block.state.BlockStateContainer;
  11. import net.minecraft.block.state.IBlockState;
  12. import net.minecraft.creativetab.CreativeTabs;
  13. import net.minecraft.entity.EntityLivingBase;
  14. import net.minecraft.entity.player.EntityPlayer;
  15. import net.minecraft.init.Blocks;
  16. import net.minecraft.tileentity.TileEntity;
  17. import net.minecraft.util.EnumBlockRenderType;
  18. import net.minecraft.util.EnumFacing;
  19. import net.minecraft.util.EnumHand;
  20. import net.minecraft.util.Mirror;
  21. import net.minecraft.util.Rotation;
  22. import net.minecraft.util.math.AxisAlignedBB;
  23. import net.minecraft.util.math.BlockPos;
  24. import net.minecraft.world.World;
  25.  
  26. public class CreepinoSkull extends ModBlocks implements ITileEntityProvider {
  27. protected static final AxisAlignedBB DEFAULT_AABB = new AxisAlignedBB(0.25D, 0.0D, 0.25D, 0.75D, 0.5D, 0.75D);
  28. protected static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.25D, 0.25D, 0.5D, 0.75D, 0.75D, 1.0D);
  29. protected static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.25D, 0.25D, 0.0D, 0.75D, 0.75D, 0.5D);
  30. protected static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.5D, 0.25D, 0.25D, 1.0D, 0.75D, 0.75D);
  31. protected static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.25D, 0.25D, 0.5D, 0.75D, 0.75D);
  32. public static final PropertyDirection FACING = BlockDirectional.FACING;
  33.  
  34. public CreepinoSkull(Material mat, String name, CreativeTabs tab, float hardness, float resistance, int harvest,
  35. String tool) {
  36. super(mat, name, tab, hardness, resistance, harvest, tool);
  37. this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  38. }
  39.  
  40. @Override
  41. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand,
  42. EnumFacing facing, float hitX, float hitY, float hitZ) {
  43. if (!world.isRemote) {
  44. EntityMovingBlock entity = new EntityMovingBlock(world, pos.up(1));
  45. entity.setHealth(10.0F);
  46. entity.setNoAI(false);
  47. entity.setCustomNameTag("Moving Block");
  48. entity.setEntityInvulnerable(false);
  49. world.spawnEntity(entity);
  50. }
  51. return super.onBlockActivated(world, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
  52. }
  53.  
  54. @Override
  55. public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) {
  56.  
  57. worldIn.removeTileEntity(pos);
  58.  
  59. this.dropBlockAsItem(worldIn, pos, state, 0);
  60.  
  61. super.onBlockHarvested(worldIn, pos, state, player);
  62. }
  63.  
  64. public boolean isOpaqueCube(IBlockState state) {
  65. return false;
  66. }
  67.  
  68. public boolean isFullCube(IBlockState state) {
  69. return false;
  70. }
  71.  
  72. @Override
  73. public EnumBlockRenderType getRenderType(IBlockState state) {
  74. return EnumBlockRenderType.MODEL;
  75. }
  76.  
  77. public IBlockState getStateFromMeta(int meta) {
  78. return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7));
  79. }
  80.  
  81. public int getMetaFromState(IBlockState state) {
  82. int i = 0;
  83. i = i | ((EnumFacing) state.getValue(FACING)).getIndex();
  84.  
  85. return i;
  86. }
  87.  
  88. public IBlockState withRotation(IBlockState state, Rotation rot) {
  89. return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
  90. }
  91.  
  92. public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
  93. return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING)));
  94. }
  95.  
  96. protected BlockStateContainer createBlockState() {
  97. return new BlockStateContainer(this, new IProperty[] { FACING });
  98. }
  99.  
  100. @Override
  101. public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
  102. float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
  103.  
  104. return this.blockState.getBaseState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  105. }
  106.  
  107. @Override
  108. public TileEntity createNewTileEntity(World worldIn, int meta) {
  109.  
  110. return new TECreepinoSkull();
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement