Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. package net.minecraft.block;
  2.  
  3. import net.minecraft.block.material.MapColor;
  4.  
  5. import net.minecraft.block.material.Material;
  6.  
  7. import net.minecraft.block.properties.IProperty;
  8.  
  9. import net.minecraft.block.properties.PropertyEnum;
  10.  
  11. import net.minecraft.block.state.BlockStateContainer;
  12.  
  13. import net.minecraft.block.state.IBlockState;
  14.  
  15. import net.minecraft.creativetab.CreativeTabs;
  16.  
  17. import net.minecraft.init.Blocks;
  18.  
  19. import net.minecraft.item.EnumDyeColor;
  20.  
  21. import net.minecraft.item.ItemStack;
  22.  
  23. import net.minecraft.util.EnumFacing;
  24.  
  25. import net.minecraft.util.NonNullList;
  26.  
  27. import net.minecraft.util.math.BlockPos;
  28.  
  29. import net.minecraft.world.IBlockAccess;
  30.  
  31. import net.minecraft.world.World;
  32.  
  33. public class BlockConcretePowder extends BlockFalling
  34.  
  35. {
  36.  
  37. public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);
  38.  
  39. public BlockConcretePowder()
  40.  
  41. {
  42.  
  43. super(Material.SAND);
  44.  
  45. this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumDyeColor.WHITE));
  46.  
  47. this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
  48.  
  49. }
  50.  
  51. public void onEndFalling(World worldIn, BlockPos pos, IBlockState p_176502_3_, IBlockState p_176502_4_)
  52.  
  53. {
  54.  
  55. if (p_176502_4_.getMaterial().isLiquid())
  56.  
  57. {
  58.  
  59. worldIn.setBlockState(pos, Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, p_176502_3_.getValue(COLOR)), 3);
  60.  
  61. }
  62.  
  63. }
  64.  
  65. protected boolean tryTouchWater(World worldIn, BlockPos pos, IBlockState state)
  66.  
  67. {
  68.  
  69. boolean flag = false;
  70.  
  71. for (EnumFacing enumfacing : EnumFacing.values())
  72.  
  73. {
  74.  
  75. if (enumfacing != EnumFacing.DOWN)
  76.  
  77. {
  78.  
  79. BlockPos blockpos = pos.offset(enumfacing);
  80.  
  81. if (worldIn.getBlockState(blockpos).getMaterial() == Material.WATER)
  82.  
  83. {
  84.  
  85. flag = true;
  86.  
  87. break;
  88.  
  89. }
  90.  
  91. }
  92.  
  93. }
  94.  
  95. if (flag)
  96.  
  97. {
  98.  
  99. worldIn.setBlockState(pos, Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, state.getValue(COLOR)), 3);
  100.  
  101. }
  102.  
  103. return flag;
  104.  
  105. }
  106.  
  107. /**
  108.  
  109. * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
  110.  
  111. * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
  112.  
  113. * block, etc.
  114.  
  115. */
  116.  
  117. public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
  118.  
  119. {
  120.  
  121. if (!this.tryTouchWater(worldIn, pos, state))
  122.  
  123. {
  124.  
  125. super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
  126.  
  127. }
  128.  
  129. }
  130.  
  131. /**
  132.  
  133. * Called after the block is set in the Chunk data, but before the Tile Entity is set
  134.  
  135. */
  136.  
  137. public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
  138.  
  139. {
  140.  
  141. if (!this.tryTouchWater(worldIn, pos, state))
  142.  
  143. {
  144.  
  145. super.onBlockAdded(worldIn, pos, state);
  146.  
  147. }
  148.  
  149. }
  150.  
  151. /**
  152.  
  153. * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
  154.  
  155. * returns the metadata of the dropped item based on the old metadata of the block.
  156.  
  157. */
  158.  
  159. public int damageDropped(IBlockState state)
  160.  
  161. {
  162.  
  163. return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
  164.  
  165. }
  166.  
  167. /**
  168.  
  169. * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
  170.  
  171. */
  172.  
  173. public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
  174.  
  175. {
  176.  
  177. for (EnumDyeColor enumdyecolor : EnumDyeColor.values())
  178.  
  179. {
  180.  
  181. items.add(new ItemStack(this, 1, enumdyecolor.getMetadata()));
  182.  
  183. }
  184.  
  185. }
  186.  
  187. /**
  188.  
  189. * Get the MapColor for this Block and the given BlockState
  190.  
  191. */
  192.  
  193. public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
  194.  
  195. {
  196.  
  197. return MapColor.getBlockColor((EnumDyeColor)state.getValue(COLOR));
  198.  
  199. }
  200.  
  201. /**
  202.  
  203. * Convert the given metadata into a BlockState for this Block
  204.  
  205. */
  206.  
  207. public IBlockState getStateFromMeta(int meta)
  208.  
  209. {
  210.  
  211. return this.getDefaultState().withProperty(COLOR, EnumDyeColor.byMetadata(meta));
  212.  
  213. }
  214.  
  215. /**
  216.  
  217. * Convert the BlockState into the correct metadata value
  218.  
  219. */
  220.  
  221. public int getMetaFromState(IBlockState state)
  222.  
  223. {
  224.  
  225. return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
  226.  
  227. }
  228.  
  229. protected BlockStateContainer createBlockState()
  230.  
  231. {
  232.  
  233. return new BlockStateContainer(this, new IProperty[] {COLOR});
  234.  
  235. }
  236.  
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement