Redsword

Untitled

Mar 10th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. package redsword.mub.blocks;
  2.  
  3. import redsword.mub.Reference;
  4. import redsword.mub.handlers.MubSoundHandler;
  5. import redsword.mub.init.ModBlocks;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.BlockDoor;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.EnumFacing;
  13. import net.minecraft.util.EnumHand;
  14. import net.minecraft.util.ResourceLocation;
  15. import net.minecraft.util.SoundCategory;
  16. import net.minecraft.util.math.BlockPos;
  17. import net.minecraft.world.World;
  18.  
  19. public class BlockSandstoneDoor extends BlockDoor {
  20.  
  21. public BlockSandstoneDoor(String unlocalizedName) {
  22. super(Material.ROCK);
  23. this.setUnlocalizedName(unlocalizedName);
  24. this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName));
  25. this.setHardness(3);
  26. this.setResistance(20);
  27. }
  28.  
  29. @Override
  30. public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  31. if (this.blockMaterial == Material.IRON) {
  32. return false; //Allow items to interact with the door
  33. }
  34. else {
  35. BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
  36. IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);
  37.  
  38. if (iblockstate.getBlock() != this) {
  39. return false;
  40. }
  41. else {
  42. state = iblockstate.cycleProperty(OPEN);
  43. worldIn.setBlockState(blockpos, state, 10);
  44. worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
  45. worldIn.playSound(playerIn, blockpos, ((Boolean)state.getValue(OPEN)).booleanValue() ? MubSoundHandler.SANDSTONE_DOOR_OPEN : MubSoundHandler.SANDSTONE_DOOR_CLOSE, SoundCategory.BLOCKS, 1.0F, 1.0F);
  46. return true;
  47. }
  48. }
  49. }
  50.  
  51. @Override
  52. public void toggleDoor(World worldIn, BlockPos pos, boolean open) {
  53. IBlockState iblockstate = worldIn.getBlockState(pos);
  54.  
  55. if (iblockstate.getBlock() == this) {
  56. BlockPos blockpos = iblockstate.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
  57. IBlockState iblockstate1 = pos == blockpos ? iblockstate : worldIn.getBlockState(blockpos);
  58.  
  59. if (iblockstate1.getBlock() == this && ((Boolean)iblockstate1.getValue(OPEN)).booleanValue() != open) {
  60. worldIn.setBlockState(blockpos, iblockstate1.withProperty(OPEN, Boolean.valueOf(open)), 10);
  61. worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
  62. worldIn.playSound((EntityPlayer)null, blockpos, open ? MubSoundHandler.SANDSTONE_DOOR_OPEN : MubSoundHandler.SANDSTONE_DOOR_CLOSE, SoundCategory.BLOCKS, 1.0F, 1.0F);
  63. }
  64. }
  65. }
  66.  
  67. @Override
  68. public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
  69. if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) {
  70. BlockPos blockpos = pos.down();
  71. IBlockState iblockstate = worldIn.getBlockState(blockpos);
  72.  
  73. if (iblockstate.getBlock() != this) {
  74. worldIn.setBlockToAir(pos);
  75. }
  76. else if (blockIn != this) {
  77. iblockstate.neighborChanged(worldIn, blockpos, blockIn, fromPos);
  78. }
  79. }
  80. else {
  81. boolean flag1 = false;
  82. BlockPos blockpos1 = pos.up();
  83. IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
  84.  
  85. if (iblockstate1.getBlock() != this) {
  86. worldIn.setBlockToAir(pos);
  87. flag1 = true;
  88. }
  89.  
  90. if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP)) {
  91. worldIn.setBlockToAir(pos);
  92. flag1 = true;
  93.  
  94. if (iblockstate1.getBlock() == this) {
  95. worldIn.setBlockToAir(blockpos1);
  96. }
  97. }
  98.  
  99. if (flag1) {
  100. if (!worldIn.isRemote) {
  101. this.dropBlockAsItem(worldIn, pos, state, 0);
  102. }
  103. }
  104. else {
  105. boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);
  106.  
  107. if (blockIn != this && (flag || blockIn.getDefaultState().canProvidePower()) && flag != ((Boolean)iblockstate1.getValue(POWERED)).booleanValue()) {
  108. worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag)), 2);
  109.  
  110. if (flag != ((Boolean)state.getValue(OPEN)).booleanValue()){
  111. worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
  112. worldIn.markBlockRangeForRenderUpdate(pos, pos);
  113. worldIn.playSound((EntityPlayer)null, pos, flag ? MubSoundHandler.SANDSTONE_DOOR_OPEN : MubSoundHandler.SANDSTONE_DOOR_CLOSE, SoundCategory.BLOCKS, 1.0F, 1.0F);
  114. }
  115. }
  116. }
  117. }
  118. }
  119.  
  120. @Override
  121. public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
  122. return new ItemStack(ModBlocks.sandstoneDoor);
  123. }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment