Advertisement
MrCyberdragon

Untitled

Jan 26th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. package com.mrcyberdragon.lightthenight.blocks;
  2.  
  3. import com.mrcyberdragon.lightthenight.Main;
  4. import com.mrcyberdragon.lightthenight.init.ModBlocks;
  5. import com.mrcyberdragon.lightthenight.init.ModItems;
  6. import com.mrcyberdragon.lightthenight.util.IHasModel;
  7. import net.minecraft.block.*;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.block.properties.IProperty;
  10. import net.minecraft.block.state.BlockFaceShape;
  11. import net.minecraft.block.state.BlockStateContainer;
  12. import net.minecraft.block.state.IBlockState;
  13. import net.minecraft.entity.EntityLivingBase;
  14. import net.minecraft.init.Blocks;
  15. import net.minecraft.item.Item;
  16. import net.minecraft.item.ItemBlock;
  17. import net.minecraft.item.ItemStack;
  18. import net.minecraft.util.BlockRenderLayer;
  19. import net.minecraft.util.EnumFacing;
  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.IBlockAccess;
  25. import net.minecraft.world.World;
  26. import net.minecraftforge.fml.relauncher.Side;
  27. import net.minecraftforge.fml.relauncher.SideOnly;
  28.  
  29. import javax.annotation.Nullable;
  30. import java.util.Random;
  31.  
  32. public class BlockTreeGlowshrooms extends BlockHorizontal implements IHasModel {
  33.  
  34.  
  35. public BlockTreeGlowshrooms(String name, Material material){
  36. super(material);
  37. this.setUnlocalizedName(name);
  38. this.setRegistryName(name);
  39. this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  40. this.setLightLevel(0.3F);
  41. this.setCreativeTab(Main.ltntab);
  42. this.setSoundType(SoundType.PLANT);
  43. ModBlocks.BLOCKS.add(this);
  44. ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
  45. }
  46.  
  47. public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
  48. if (!this.canBlockStay(worldIn, pos, state)) {
  49. this.dropBlock(worldIn, pos, state);
  50. }
  51. }
  52.  
  53. public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
  54. {
  55. for (EnumFacing enumfacing : FACING.getAllowedValues())
  56. {
  57. if (this.canPlaceAt(worldIn, pos, enumfacing))
  58. {
  59. return true;
  60. }
  61. }
  62.  
  63. return false;
  64. }
  65.  
  66. private boolean canPlaceAt(World worldIn, BlockPos pos, EnumFacing facing)
  67. {
  68. BlockPos blockpos = pos.offset(facing.getOpposite());
  69. IBlockState iblockstate = worldIn.getBlockState(blockpos);
  70. Block block = iblockstate.getBlock();
  71. BlockFaceShape blockfaceshape = iblockstate.getBlockFaceShape(worldIn, blockpos, facing);
  72.  
  73. if (facing != EnumFacing.UP && facing != EnumFacing.DOWN)
  74. {
  75. return (block==Blocks.LOG||block==Blocks.LOG2||block==ModBlocks.INFECTED_WOOD)&& blockfaceshape == BlockFaceShape.SOLID;
  76. }
  77. else
  78. {
  79. return false;
  80. }
  81. }
  82.  
  83. public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
  84. {
  85. pos = pos.offset((EnumFacing)state.getValue(FACING));
  86. IBlockState iblockstate = worldIn.getBlockState(pos);
  87. return iblockstate.getBlock() == Blocks.LOG || iblockstate.getBlock()==Blocks.LOG2 || iblockstate.getBlock()==ModBlocks.INFECTED_WOOD;
  88. }
  89.  
  90. public IBlockState withRotation(IBlockState state, Rotation rot)
  91. {
  92. return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
  93. }
  94.  
  95. public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  96. {
  97. return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
  98. }
  99.  
  100. public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
  101. {
  102. EnumFacing enumfacing = EnumFacing.fromAngle((double)placer.rotationYaw);
  103. worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
  104. }
  105.  
  106. public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  107. {
  108. if (this.canPlaceAt(worldIn, pos, facing))
  109. {
  110. return this.getDefaultState().withProperty(FACING, facing);
  111. }
  112. else
  113. {
  114. for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  115. {
  116. if (this.canPlaceAt(worldIn, pos, enumfacing))
  117. {
  118. return this.getDefaultState().withProperty(FACING, enumfacing);
  119. }
  120. }
  121.  
  122. return this.getDefaultState();
  123. }
  124. }
  125.  
  126. public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
  127. {
  128. if (!this.canBlockStay(worldIn, pos, state))
  129. {
  130. this.dropBlock(worldIn, pos, state);
  131. }
  132. }
  133.  
  134. private void dropBlock(World worldIn, BlockPos pos, IBlockState state)
  135. {
  136. worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
  137. this.dropBlockAsItem(worldIn, pos, state, 0);
  138. }
  139.  
  140. public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
  141. {
  142. return BlockFaceShape.UNDEFINED;
  143. }
  144.  
  145. public IBlockState getStateFromMeta(int meta)
  146. {
  147. return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
  148. }
  149.  
  150. public int getMetaFromState(IBlockState state)
  151. {
  152. int i = 0;
  153. i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
  154. return i;
  155. }
  156.  
  157. protected BlockStateContainer createBlockState()
  158. {
  159. return new BlockStateContainer(this, new IProperty[] {FACING});
  160. }
  161.  
  162. /*@Override
  163. public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) {
  164. if(worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos)){
  165. }
  166. }*/
  167.  
  168. @Nullable
  169. public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
  170. {
  171. return NULL_AABB;
  172. }
  173.  
  174. @SideOnly(Side.CLIENT)
  175. public BlockRenderLayer getBlockLayer()
  176. {
  177. return BlockRenderLayer.TRANSLUCENT;
  178. }
  179.  
  180. @Override
  181. @SideOnly(Side.CLIENT)
  182. public int getPackedLightmapCoords(IBlockState state, IBlockAccess source, BlockPos pos)
  183. {
  184. return 15728880;
  185. }
  186.  
  187. public boolean isOpaqueCube(IBlockState state)
  188. {
  189. return false;
  190. }
  191.  
  192. public boolean isFullCube(IBlockState state)
  193. {
  194. return false;
  195. }
  196.  
  197. @Override
  198. public void registerModels() {
  199. Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
  200. }
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement