Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. package fr.ethnyx.mod.blocks;
  2.  
  3. import static net.minecraftforge.common.util.ForgeDirection.EAST;
  4. import static net.minecraftforge.common.util.ForgeDirection.NORTH;
  5. import static net.minecraftforge.common.util.ForgeDirection.SOUTH;
  6. import static net.minecraftforge.common.util.ForgeDirection.WEST;
  7.  
  8. import java.util.Random;
  9.  
  10. import cpw.mods.fml.relauncher.Side;
  11. import cpw.mods.fml.relauncher.SideOnly;
  12. import net.minecraft.block.Block;
  13. import net.minecraft.block.material.Material;
  14. import net.minecraft.creativetab.CreativeTabs;
  15. import net.minecraft.entity.Entity;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.util.AxisAlignedBB;
  18. import net.minecraft.util.MathHelper;
  19. import net.minecraft.world.IBlockAccess;
  20. import net.minecraft.world.World;
  21.  
  22. public class IronLadderBlock extends Block {
  23.  
  24. public IronLadderBlock() {
  25. super(Material.circuits);
  26. this.setCreativeTab(CreativeTabs.tabDecorations);
  27. }
  28.  
  29.  
  30. public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
  31. this.setBlockBoundsBasedOnState(world, x, y, z);
  32. return super.getCollisionBoundingBoxFromPool(world, x, y, z);
  33. }
  34.  
  35. public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
  36. this.func_149797_b(world.getBlockMetadata(x, y, z));
  37. }
  38.  
  39. @SideOnly(Side.CLIENT)
  40. public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
  41. this.setBlockBoundsBasedOnState(world, x, y, z);
  42. return super.getSelectedBoundingBoxFromPool(world, x, y, z);
  43. }
  44.  
  45. public void func_149797_b(int p_149797_1_) {
  46. float f = 0.125F;
  47.  
  48. if (p_149797_1_ == 2) {
  49. this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
  50. }
  51.  
  52. if (p_149797_1_ == 3) {
  53. this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
  54. }
  55.  
  56. if (p_149797_1_ == 4) {
  57. this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  58. }
  59.  
  60. if (p_149797_1_ == 5) {
  61. this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
  62. }
  63. }
  64.  
  65. public boolean isOpaqueCube() {
  66. return false;
  67. }
  68.  
  69. public boolean renderAsNormalBlock() {
  70. return false;
  71. }
  72.  
  73. public int getRenderType() {
  74. return 8;
  75. }
  76.  
  77. public boolean canPlaceBlockAt(World world, int x, int y, int z) {
  78. return world.isSideSolid(x - 1, y, z, EAST ) ||
  79. world.isSideSolid(x + 1, y, z, WEST ) ||
  80. world.isSideSolid(x, y, z - 1, SOUTH) ||
  81. world.isSideSolid(x, y, z + 1, NORTH);
  82. }
  83.  
  84. public int onBlockPlaced(World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
  85. int j1 = metadata;
  86.  
  87. if ((metadata == 0 || side == 2) && world.isSideSolid(x, y, z + 1, NORTH)) {
  88. j1 = 2;
  89. }
  90.  
  91. if ((j1 == 0 || side == 3) && world.isSideSolid(x, y, z - 1, SOUTH)) {
  92. j1 = 3;
  93. }
  94.  
  95. if ((j1 == 0 || side == 4) && world.isSideSolid(x + 1, y, z, WEST)) {
  96. j1 = 4;
  97. }
  98.  
  99. if ((j1 == 0 || side == 5) && world.isSideSolid(x - 1, y, z, EAST)) {
  100. j1 = 5;
  101. }
  102.  
  103. return j1;
  104. }
  105.  
  106. public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
  107. int l = world.getBlockMetadata(x, y, z);
  108. boolean flag = false;
  109.  
  110. if (l == 2 && world.isSideSolid(x, y, z + 1, NORTH)) {
  111. flag = true;
  112. }
  113.  
  114. if (l == 3 && world.isSideSolid(x, y, z - 1, SOUTH)) {
  115. flag = true;
  116. }
  117.  
  118. if (l == 4 && world.isSideSolid(x + 1, y, z, WEST)) {
  119. flag = true;
  120. }
  121.  
  122. if (l == 5 && world.isSideSolid(x - 1, y, z, EAST)) {
  123. flag = true;
  124. }
  125.  
  126. if (!flag) {
  127. this.dropBlockAsItem(world, x, y, z, l, 0);
  128. world.setBlockToAir(x, y, z);
  129. }
  130.  
  131. super.onNeighborBlockChange(world, x, y, z, block);
  132. }
  133.  
  134. public int quantityDropped(Random random) {
  135. return 1;
  136. }
  137.  
  138. @Override
  139. public boolean isLadder(IBlockAccess world, int x, int y, int z, EntityLivingBase entity) {
  140. return true;
  141. }
  142.  
  143. @Override
  144.  
  145. public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
  146. if (entity.onGround || entity.isCollidedVertically) { return; }
  147. if (entity.motionY >= 0.1) {
  148. entity.setPosition(entity.posX, entity.posY + 0.05F, entity.posZ);
  149. } else if (entity.motionY <= -0.1) {
  150. Block blockUnder = world.getBlock(MathHelper.floor_double(entity.posX), MathHelper.floor_double(entity.posY) - 3, MathHelper.floor_double(entity.posZ));
  151. if (blockUnder == null || blockUnder == this) {
  152. entity.setPosition(entity.posX, entity.posY - 0.05F, entity.posZ);
  153. }
  154. }
  155. }
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement