Guest User

BlockAnalyser

a guest
Mar 13th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. package destinyspork.appliedautomation.blocks;
  2.  
  3. import destinyspork.appliedautomation.AppliedAutomation;
  4. import net.minecraft.block.Block;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.block.properties.IProperty;
  7. import net.minecraft.block.properties.PropertyDirection;
  8. import net.minecraft.block.state.BlockState;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.util.BlockPos;
  13. import net.minecraft.util.EnumFacing;
  14. import net.minecraft.util.MathHelper;
  15. import net.minecraft.world.IBlockAccess;
  16. import net.minecraft.world.World;
  17. import net.minecraftforge.client.model.b3d.B3DLoader;
  18. import net.minecraftforge.common.property.ExtendedBlockState;
  19. import net.minecraftforge.common.property.IExtendedBlockState;
  20. import net.minecraftforge.common.property.IUnlistedProperty;
  21. import net.minecraftforge.fml.relauncher.Side;
  22. import net.minecraftforge.fml.relauncher.SideOnly;
  23.  
  24. public class BlockAnalyser extends Block{
  25.  
  26. public static final PropertyDirection FACING = PropertyDirection.create("facing");
  27. public static final BlockAnalyser instance = new BlockAnalyser();
  28. public static final String name = "CustomModelBlock";
  29. private int counter = 1;
  30. public ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[]{FACING}, new IUnlistedProperty[]{B3DLoader.B3DFrameProperty.instance});
  31.  
  32. public BlockAnalyser(){
  33. super(Material.iron);
  34. this.setUnlocalizedName("block_analyzer");
  35. this.setCreativeTab(AppliedAutomation.AppliedTab);
  36. this.setHardness(3.0F);
  37. this.setResistance(2.0F);
  38. this.setHarvestLevel("pickaxe", 1);
  39.  
  40. this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  41.  
  42. }
  43.  
  44. @Override
  45. public boolean isOpaqueCube() { return false; }
  46.  
  47. @Override
  48. public boolean isFullCube() { return false; }
  49.  
  50. @Override
  51. public boolean isVisuallyOpaque() { return false; }
  52.  
  53. @Override
  54. public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  55. {
  56. return this.getDefaultState().withProperty(FACING, 1); //This needs to use the Player's rotation value.
  57. }
  58.  
  59. @Override
  60. public IBlockState getStateFromMeta(int meta)
  61. {
  62. return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
  63. }
  64.  
  65. @Override
  66. public int getMetaFromState(IBlockState state)
  67. {
  68. return ((EnumFacing) state.getValue(FACING)).getIndex();
  69. }
  70.  
  71. @Override
  72. public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
  73. {
  74. //Only return an IExtendedBlockState from this method and createState(), otherwise block placement might break!
  75. B3DLoader.B3DState newState = new B3DLoader.B3DState(null, counter);
  76. return ((IExtendedBlockState) state).withProperty(B3DLoader.B3DFrameProperty.instance, newState);
  77. }
  78.  
  79. @Override
  80. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
  81. {
  82. if(world.isRemote)
  83. {
  84. System.out.println("click " + counter);
  85. if(player.isSneaking()) counter--;
  86. else counter++;
  87. //if(counter >= model.getNode().getKeys().size()) counter = 0;
  88. world.markBlockRangeForRenderUpdate(pos, pos);
  89. }
  90. return false;
  91. }
  92.  
  93.  
  94.  
  95.  
  96. @Override
  97. public BlockState createBlockState()
  98. {
  99. return new ExtendedBlockState(this, new IProperty[]{FACING}, new IUnlistedProperty[]{B3DLoader.B3DFrameProperty.instance});
  100. }
  101.  
  102. public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
  103. {
  104. if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
  105. {
  106. double d0 = entityIn.posY + (double)entityIn.getEyeHeight();
  107.  
  108. if (d0 - (double)clickedBlock.getY() > 2.0D)
  109. {
  110. return EnumFacing.UP;
  111. }
  112.  
  113. if ((double)clickedBlock.getY() - d0 > 0.0D)
  114. {
  115. return EnumFacing.DOWN;
  116. }
  117. }
  118.  
  119. return entityIn.getHorizontalFacing().getOpposite();
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment