Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.67 KB | None | 0 0
  1. public class BlockModVine extends BlockMod implements IShearable {
  2.  
  3. public static final PropertyBool UP = PropertyBool.create("up");
  4. public static final PropertyBool NORTH = PropertyBool.create("north");
  5. public static final PropertyBool EAST = PropertyBool.create("east");
  6. public static final PropertyBool SOUTH = PropertyBool.create("south");
  7. public static final PropertyBool WEST = PropertyBool.create("west");
  8. public static final PropertyBool[] ALL_FACES = new PropertyBool[] {UP, NORTH, SOUTH, WEST, EAST};
  9. public static final int SOUTH_FLAG = getMetaFlag(EnumFacing.SOUTH);
  10. public static final int NORTH_FLAG = getMetaFlag(EnumFacing.NORTH);
  11. public static final int EAST_FLAG = getMetaFlag(EnumFacing.EAST);
  12. public static final int WEST_FLAG = getMetaFlag(EnumFacing.WEST);
  13.  
  14. public BlockModVine(String name, String finalName) {
  15. super(EnumMaterialTypes.VINES, name, finalName, 0.0F);
  16. this.setDefaultState(this.blockState.getBaseState().withProperty(UP, Boolean.valueOf(false)).withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)));
  17. this.setTickRandomly(true);
  18. this.setCreativeTab(JourneyTabs.decoraton);
  19. }
  20.  
  21. @Override
  22. public EnumWorldBlockLayer getBlockLayer() {
  23. return EnumWorldBlockLayer.TRANSLUCENT;
  24. }
  25.  
  26. public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
  27. {
  28. return state.withProperty(UP, Boolean.valueOf(worldIn.getBlockState(pos.up()).getBlock().isSolidFullCube()));
  29. }
  30.  
  31. public void setBlockBoundsForItemRender()
  32. {
  33. this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  34. }
  35.  
  36. public boolean isOpaqueCube()
  37. {
  38. return false;
  39. }
  40.  
  41. public boolean isFullCube()
  42. {
  43. return false;
  44. }
  45.  
  46. public boolean isReplaceable(World worldIn, BlockPos pos)
  47. {
  48. return true;
  49. }
  50.  
  51. public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
  52. {
  53. float f = 0.0625F;
  54. float f1 = 1.0F;
  55. float f2 = 1.0F;
  56. float f3 = 1.0F;
  57. float f4 = 0.0F;
  58. float f5 = 0.0F;
  59. float f6 = 0.0F;
  60. boolean flag = false;
  61.  
  62. if (((Boolean)worldIn.getBlockState(pos).getValue(WEST)).booleanValue())
  63. {
  64. f4 = Math.max(f4, 0.0625F);
  65. f1 = 0.0F;
  66. f2 = 0.0F;
  67. f5 = 1.0F;
  68. f3 = 0.0F;
  69. f6 = 1.0F;
  70. flag = true;
  71. }
  72.  
  73. if (((Boolean)worldIn.getBlockState(pos).getValue(EAST)).booleanValue())
  74. {
  75. f1 = Math.min(f1, 0.9375F);
  76. f4 = 1.0F;
  77. f2 = 0.0F;
  78. f5 = 1.0F;
  79. f3 = 0.0F;
  80. f6 = 1.0F;
  81. flag = true;
  82. }
  83.  
  84. if (((Boolean)worldIn.getBlockState(pos).getValue(NORTH)).booleanValue())
  85. {
  86. f6 = Math.max(f6, 0.0625F);
  87. f3 = 0.0F;
  88. f1 = 0.0F;
  89. f4 = 1.0F;
  90. f2 = 0.0F;
  91. f5 = 1.0F;
  92. flag = true;
  93. }
  94.  
  95. if (((Boolean)worldIn.getBlockState(pos).getValue(SOUTH)).booleanValue())
  96. {
  97. f3 = Math.min(f3, 0.9375F);
  98. f6 = 1.0F;
  99. f1 = 0.0F;
  100. f4 = 1.0F;
  101. f2 = 0.0F;
  102. f5 = 1.0F;
  103. flag = true;
  104. }
  105.  
  106. if (!flag && this.canPlaceOn(worldIn.getBlockState(pos.up()).getBlock()))
  107. {
  108. f2 = Math.min(f2, 0.9375F);
  109. f5 = 1.0F;
  110. f1 = 0.0F;
  111. f4 = 1.0F;
  112. f3 = 0.0F;
  113. f6 = 1.0F;
  114. }
  115.  
  116. this.setBlockBounds(f1, f2, f3, f4, f5, f6);
  117. }
  118.  
  119. public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
  120. {
  121. return null;
  122. }
  123.  
  124. public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
  125. {
  126. switch (BlockModVine.SwitchEnumFacing.FACING_LOOKUP[side.ordinal()])
  127. {
  128. case 1:
  129. return this.canPlaceOn(worldIn.getBlockState(pos.up()).getBlock());
  130. case 2:
  131. case 3:
  132. case 4:
  133. case 5:
  134. return this.canPlaceOn(worldIn.getBlockState(pos.offset(side.getOpposite())).getBlock());
  135. default:
  136. return false;
  137. }
  138. }
  139.  
  140. private boolean canPlaceOn(Block p_150093_1_)
  141. {
  142. return p_150093_1_.isFullCube() && p_150093_1_.getMaterial().blocksMovement();
  143. }
  144.  
  145. private boolean recheckGrownSides(World worldIn, BlockPos pos, IBlockState state)
  146. {
  147. IBlockState iblockstate1 = state;
  148. Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();
  149.  
  150. while (iterator.hasNext())
  151. {
  152. EnumFacing enumfacing = (EnumFacing)iterator.next();
  153. PropertyBool propertybool = getPropertyFor(enumfacing);
  154.  
  155. if (((Boolean)state.getValue(propertybool)).booleanValue() && !this.canPlaceOn(worldIn.getBlockState(pos.offset(enumfacing)).getBlock()))
  156. {
  157. IBlockState iblockstate2 = worldIn.getBlockState(pos.up());
  158.  
  159. if (iblockstate2.getBlock() != this || !((Boolean)iblockstate2.getValue(propertybool)).booleanValue())
  160. {
  161. state = state.withProperty(propertybool, Boolean.valueOf(false));
  162. }
  163. }
  164. }
  165.  
  166. if (getNumGrownFaces(state) == 0)
  167. {
  168. return false;
  169. }
  170. else
  171. {
  172. if (iblockstate1 != state)
  173. {
  174. worldIn.setBlockState(pos, state, 2);
  175. }
  176.  
  177. return true;
  178. }
  179. }
  180.  
  181. public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
  182. {
  183. if (!worldIn.isRemote && !this.recheckGrownSides(worldIn, pos, state))
  184. {
  185. this.dropBlockAsItem(worldIn, pos, state, 0);
  186. worldIn.setBlockToAir(pos);
  187. }
  188. }
  189.  
  190. public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
  191. {
  192. if (!worldIn.isRemote)
  193. {
  194. if (worldIn.rand.nextInt(4) == 0)
  195. {
  196. byte b0 = 4;
  197. int i = 5;
  198. boolean flag = false;
  199. label189:
  200.  
  201. for (int j = -b0; j <= b0; ++j)
  202. {
  203. for (int k = -b0; k <= b0; ++k)
  204. {
  205. for (int l = -1; l <= 1; ++l)
  206. {
  207. if (worldIn.getBlockState(pos.add(j, l, k)).getBlock() == this)
  208. {
  209. --i;
  210.  
  211. if (i <= 0)
  212. {
  213. flag = true;
  214. break label189;
  215. }
  216. }
  217. }
  218. }
  219. }
  220.  
  221. EnumFacing enumfacing1 = EnumFacing.random(rand);
  222. EnumFacing enumfacing2;
  223.  
  224. if (enumfacing1 == EnumFacing.UP && pos.getY() < 255 && worldIn.isAirBlock(pos.up()))
  225. {
  226. if (!flag)
  227. {
  228. IBlockState iblockstate2 = state;
  229. Iterator iterator1 = EnumFacing.Plane.HORIZONTAL.iterator();
  230.  
  231. while (iterator1.hasNext())
  232. {
  233. enumfacing2 = (EnumFacing)iterator1.next();
  234.  
  235. if (rand.nextBoolean() || !this.canPlaceOn(worldIn.getBlockState(pos.offset(enumfacing2).up()).getBlock()))
  236. {
  237. iblockstate2 = iblockstate2.withProperty(getPropertyFor(enumfacing2), Boolean.valueOf(false));
  238. }
  239. }
  240.  
  241. if (((Boolean)iblockstate2.getValue(NORTH)).booleanValue() || ((Boolean)iblockstate2.getValue(EAST)).booleanValue() || ((Boolean)iblockstate2.getValue(SOUTH)).booleanValue() || ((Boolean)iblockstate2.getValue(WEST)).booleanValue())
  242. {
  243. worldIn.setBlockState(pos.up(), iblockstate2, 2);
  244. }
  245. }
  246. }
  247. else
  248. {
  249. BlockPos blockpos2;
  250.  
  251. if (enumfacing1.getAxis().isHorizontal() && !((Boolean)state.getValue(getPropertyFor(enumfacing1))).booleanValue())
  252. {
  253. if (!flag)
  254. {
  255. blockpos2 = pos.offset(enumfacing1);
  256. Block block1 = worldIn.getBlockState(blockpos2).getBlock();
  257.  
  258. if (block1.getMaterial() == Material.air)
  259. {
  260. enumfacing2 = enumfacing1.rotateY();
  261. EnumFacing enumfacing3 = enumfacing1.rotateYCCW();
  262. boolean flag1 = ((Boolean)state.getValue(getPropertyFor(enumfacing2))).booleanValue();
  263. boolean flag2 = ((Boolean)state.getValue(getPropertyFor(enumfacing3))).booleanValue();
  264. BlockPos blockpos3 = blockpos2.offset(enumfacing2);
  265. BlockPos blockpos1 = blockpos2.offset(enumfacing3);
  266.  
  267. if (flag1 && this.canPlaceOn(worldIn.getBlockState(blockpos3).getBlock()))
  268. {
  269. worldIn.setBlockState(blockpos2, this.getDefaultState().withProperty(getPropertyFor(enumfacing2), Boolean.valueOf(true)), 2);
  270. }
  271. else if (flag2 && this.canPlaceOn(worldIn.getBlockState(blockpos1).getBlock()))
  272. {
  273. worldIn.setBlockState(blockpos2, this.getDefaultState().withProperty(getPropertyFor(enumfacing3), Boolean.valueOf(true)), 2);
  274. }
  275. else if (flag1 && worldIn.isAirBlock(blockpos3) && this.canPlaceOn(worldIn.getBlockState(pos.offset(enumfacing2)).getBlock()))
  276. {
  277. worldIn.setBlockState(blockpos3, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
  278. }
  279. else if (flag2 && worldIn.isAirBlock(blockpos1) && this.canPlaceOn(worldIn.getBlockState(pos.offset(enumfacing3)).getBlock()))
  280. {
  281. worldIn.setBlockState(blockpos1, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
  282. }
  283. else if (this.canPlaceOn(worldIn.getBlockState(blockpos2.up()).getBlock()))
  284. {
  285. worldIn.setBlockState(blockpos2, this.getDefaultState(), 2);
  286. }
  287. }
  288. else if (block1.getMaterial().isOpaque() && block1.isFullCube())
  289. {
  290. worldIn.setBlockState(pos, state.withProperty(getPropertyFor(enumfacing1), Boolean.valueOf(true)), 2);
  291. }
  292. }
  293. }
  294. else
  295. {
  296. if (pos.getY() > 1)
  297. {
  298. blockpos2 = pos.down();
  299. IBlockState iblockstate3 = worldIn.getBlockState(blockpos2);
  300. Block block = iblockstate3.getBlock();
  301. IBlockState iblockstate1;
  302. Iterator iterator;
  303. EnumFacing enumfacing;
  304.  
  305. if (block.getMaterial() == Material.air)
  306. {
  307. iblockstate1 = state;
  308. iterator = EnumFacing.Plane.HORIZONTAL.iterator();
  309.  
  310. while (iterator.hasNext())
  311. {
  312. enumfacing = (EnumFacing)iterator.next();
  313.  
  314. if (rand.nextBoolean())
  315. {
  316. iblockstate1 = iblockstate1.withProperty(getPropertyFor(enumfacing), Boolean.valueOf(false));
  317. }
  318. }
  319.  
  320. if (((Boolean)iblockstate1.getValue(NORTH)).booleanValue() || ((Boolean)iblockstate1.getValue(EAST)).booleanValue() || ((Boolean)iblockstate1.getValue(SOUTH)).booleanValue() || ((Boolean)iblockstate1.getValue(WEST)).booleanValue())
  321. {
  322. worldIn.setBlockState(blockpos2, iblockstate1, 2);
  323. }
  324. }
  325. else if (block == this)
  326. {
  327. iblockstate1 = iblockstate3;
  328. iterator = EnumFacing.Plane.HORIZONTAL.iterator();
  329.  
  330. while (iterator.hasNext())
  331. {
  332. enumfacing = (EnumFacing)iterator.next();
  333. PropertyBool propertybool = getPropertyFor(enumfacing);
  334.  
  335. if (rand.nextBoolean() || !((Boolean)state.getValue(propertybool)).booleanValue())
  336. {
  337. iblockstate1 = iblockstate1.withProperty(propertybool, Boolean.valueOf(false));
  338. }
  339. }
  340.  
  341. if (((Boolean)iblockstate1.getValue(NORTH)).booleanValue() || ((Boolean)iblockstate1.getValue(EAST)).booleanValue() || ((Boolean)iblockstate1.getValue(SOUTH)).booleanValue() || ((Boolean)iblockstate1.getValue(WEST)).booleanValue())
  342. {
  343. worldIn.setBlockState(blockpos2, iblockstate1, 2);
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352.  
  353. private static int getMetaFlag(EnumFacing face)
  354. {
  355. return 1 << face.getHorizontalIndex();
  356. }
  357.  
  358. public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  359. {
  360. IBlockState iblockstate = this.getDefaultState().withProperty(UP, Boolean.valueOf(false)).withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false));
  361. return facing.getAxis().isHorizontal() ? iblockstate.withProperty(getPropertyFor(facing.getOpposite()), Boolean.valueOf(true)) : iblockstate;
  362. }
  363.  
  364. public Item getItemDropped(IBlockState state, Random rand, int fortune)
  365. {
  366. return null;
  367. }
  368.  
  369. public int quantityDropped(Random random)
  370. {
  371. return 0;
  372. }
  373.  
  374. public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
  375. {
  376. {
  377. super.harvestBlock(worldIn, player, pos, state, te);
  378. }
  379. }
  380.  
  381. public IBlockState getStateFromMeta(int meta)
  382. {
  383. return this.getDefaultState().withProperty(NORTH, Boolean.valueOf((meta & NORTH_FLAG) > 0)).withProperty(EAST, Boolean.valueOf((meta & EAST_FLAG) > 0)).withProperty(SOUTH, Boolean.valueOf((meta & SOUTH_FLAG) > 0)).withProperty(WEST, Boolean.valueOf((meta & WEST_FLAG) > 0));
  384. }
  385.  
  386. public int getMetaFromState(IBlockState state)
  387. {
  388. int i = 0;
  389.  
  390. if (((Boolean)state.getValue(NORTH)).booleanValue())
  391. {
  392. i |= NORTH_FLAG;
  393. }
  394.  
  395. if (((Boolean)state.getValue(EAST)).booleanValue())
  396. {
  397. i |= EAST_FLAG;
  398. }
  399.  
  400. if (((Boolean)state.getValue(SOUTH)).booleanValue())
  401. {
  402. i |= SOUTH_FLAG;
  403. }
  404.  
  405. if (((Boolean)state.getValue(WEST)).booleanValue())
  406. {
  407. i |= WEST_FLAG;
  408. }
  409.  
  410. return i;
  411. }
  412.  
  413. protected BlockState createBlockState()
  414. {
  415. return new BlockState(this, new IProperty[] {UP, NORTH, EAST, SOUTH, WEST});
  416. }
  417.  
  418. public static PropertyBool getPropertyFor(EnumFacing side)
  419. {
  420. switch (BlockModVine.SwitchEnumFacing.FACING_LOOKUP[side.ordinal()])
  421. {
  422. case 1:
  423. return UP;
  424. case 2:
  425. return NORTH;
  426. case 3:
  427. return SOUTH;
  428. case 4:
  429. return EAST;
  430. case 5:
  431. return WEST;
  432. default:
  433. throw new IllegalArgumentException(side + " is an invalid choice");
  434. }
  435. }
  436.  
  437. public static int getNumGrownFaces(IBlockState state)
  438. {
  439. int i = 0;
  440. PropertyBool[] apropertybool = ALL_FACES;
  441. int j = apropertybool.length;
  442.  
  443. for (int k = 0; k < j; ++k)
  444. {
  445. PropertyBool propertybool = apropertybool[k];
  446.  
  447. if (((Boolean)state.getValue(propertybool)).booleanValue())
  448. {
  449. ++i;
  450. }
  451. }
  452.  
  453. return i;
  454. }
  455.  
  456. @Override
  457. public boolean isLadder(IBlockAccess world, BlockPos pos, EntityLivingBase entity){
  458. return true;
  459. }
  460.  
  461. @Override
  462. public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos){
  463. return true;
  464. }
  465.  
  466. @Override
  467. public java.util.List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune)
  468. {
  469. return java.util.Arrays.asList(new ItemStack(this, 1));
  470. }
  471.  
  472. static final class SwitchEnumFacing
  473. {
  474. static final int[] FACING_LOOKUP = new int[EnumFacing.values().length];
  475. private static final String __OBFID = "CL_00002049";
  476.  
  477. static
  478. {
  479. try
  480. {
  481. FACING_LOOKUP[EnumFacing.UP.ordinal()] = 1;
  482. }
  483. catch (NoSuchFieldError var5)
  484. {
  485. ;
  486. }
  487.  
  488. try
  489. {
  490. FACING_LOOKUP[EnumFacing.NORTH.ordinal()] = 2;
  491. }
  492. catch (NoSuchFieldError var4)
  493. {
  494. ;
  495. }
  496.  
  497. try
  498. {
  499. FACING_LOOKUP[EnumFacing.SOUTH.ordinal()] = 3;
  500. }
  501. catch (NoSuchFieldError var3)
  502. {
  503. ;
  504. }
  505.  
  506. try
  507. {
  508. FACING_LOOKUP[EnumFacing.EAST.ordinal()] = 4;
  509. }
  510. catch (NoSuchFieldError var2)
  511. {
  512. ;
  513. }
  514.  
  515. try
  516. {
  517. FACING_LOOKUP[EnumFacing.WEST.ordinal()] = 5;
  518. }
  519. catch (NoSuchFieldError var1)
  520. {
  521. ;
  522. }
  523. }
  524. }
  525. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement