Pawel_Langer

Untitled

Aug 23rd, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. package mcjty.modtut.neons;
  2.  
  3. import java.util.Random;
  4.  
  5. import mcjty.modtut.Lanterns;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.block.properties.PropertyDirection;
  9. import net.minecraft.block.properties.PropertyInteger;
  10. import net.minecraft.block.state.BlockStateContainer;
  11. import net.minecraft.block.state.IBlockState;
  12. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  13. import net.minecraft.entity.EntityLivingBase;
  14. import net.minecraft.item.Item;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.util.EnumFacing;
  17. import net.minecraft.util.math.BlockPos;
  18. import net.minecraft.world.IBlockAccess;
  19. import net.minecraft.world.World;
  20. import net.minecraftforge.client.model.ModelLoader;
  21. import net.minecraftforge.fml.relauncher.Side;
  22. import net.minecraftforge.fml.relauncher.SideOnly;
  23.  
  24. public class NeonLetterENeon extends Block {
  25.  
  26. public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
  27.  
  28. public static final PropertyInteger STATE = PropertyInteger.create("state", 0, 1);
  29.  
  30.  
  31.  
  32.  
  33. public NeonLetterENeon() {
  34. super(Material.IRON);
  35.  
  36. this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.WEST));
  37. this.setCreativeTab(Lanterns.tabLetters);
  38. this.disableStats();
  39. this.setTickRandomly(true);
  40.  
  41.  
  42.  
  43.  
  44. }
  45.  
  46. @SideOnly(Side.CLIENT)
  47. public void initModel() {
  48. ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
  49. }
  50.  
  51. @SideOnly(Side.CLIENT)
  52. @Override
  53. public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
  54. return false;
  55. }
  56.  
  57. @Override
  58. public boolean isBlockNormalCube(IBlockState blockState) {
  59. return false;
  60. }
  61.  
  62. @Override
  63. public boolean isOpaqueCube(IBlockState blockState) {
  64. return false;
  65. }
  66.  
  67. @Override
  68. public BlockStateContainer createBlockState() {
  69. return new BlockStateContainer(this, FACING);
  70. }
  71.  
  72. @Override
  73. public int getMetaFromState(IBlockState state) {
  74. return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
  75. }
  76.  
  77. @Override
  78. public IBlockState getStateFromMeta(int meta) {
  79. return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
  80. }
  81.  
  82. @Override
  83. public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) {
  84. EnumFacing entityFacing = entity.getHorizontalFacing();
  85. if(!world.isRemote) {
  86. if(entityFacing == EnumFacing.NORTH) {
  87. entityFacing = EnumFacing.NORTH;
  88. } else if(entityFacing == EnumFacing.EAST) {
  89. entityFacing = EnumFacing.EAST;
  90. } else if(entityFacing == EnumFacing.SOUTH) {
  91. entityFacing = EnumFacing.SOUTH;
  92. } else if(entityFacing == EnumFacing.WEST) {
  93. entityFacing = EnumFacing.WEST;
  94. }
  95.  
  96. world.setBlockState(pos, state.withProperty(FACING, entityFacing), 2);
  97. }
  98. }
  99.  
  100. @Override
  101. public boolean isTopSolid(IBlockState state)
  102. {
  103. return false;
  104. }
  105.  
  106.  
  107. protected PropertyInteger getStateProperty()
  108. {
  109. return STATE;
  110. }
  111.  
  112. public int getMaxState()
  113. {
  114. return 7;
  115. }
  116.  
  117. protected int getState(IBlockState state)
  118. {
  119. return ((Integer)state.getValue(this.getStateProperty())).intValue();
  120. }
  121.  
  122. public IBlockState withState(int State)
  123. {
  124. return this.getDefaultState().withProperty(this.getStateProperty(), Integer.valueOf(State));
  125. }
  126.  
  127. public boolean isMaxState(IBlockState state)
  128. {
  129. return ((Integer)state.getValue(this.getStateProperty())).intValue() >= this.getMaxState();
  130. }
  131.  
  132. public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
  133. {
  134. super.updateTick(worldIn, pos, state, rand);
  135. if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
  136. {
  137. int isActive = this.getState(state);
  138.  
  139. if(isActive == this.getMaxState())
  140. {
  141. this.setLightLevel(1F);
  142. }else
  143. {
  144. this.setLightLevel(0F);
  145.  
  146. }
  147. }
  148. }
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. }
Add Comment
Please, Sign In to add comment