Advertisement
shane020482

full red

Jun 18th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.06 KB | None | 0 0
  1. package shane.mod.objects.blocks.blockscustommodels;
  2.  
  3. import java.util.EnumSet;
  4. import java.util.List;
  5. import java.util.Random;
  6. import java.util.Set;
  7.  
  8. import javax.annotation.Nullable;
  9.  
  10. import com.google.common.collect.Lists;
  11. import com.google.common.collect.Sets;
  12.  
  13. import net.minecraft.block.Block;
  14. import net.minecraft.block.BlockObserver;
  15. import net.minecraft.block.BlockRedstoneDiode;
  16. import net.minecraft.block.BlockRedstoneRepeater;
  17. import net.minecraft.block.BlockRedstoneWire;
  18. import net.minecraft.block.SoundType;
  19. import net.minecraft.block.material.Material;
  20. import net.minecraft.block.properties.IProperty;
  21. import net.minecraft.block.properties.PropertyEnum;
  22. import net.minecraft.block.properties.PropertyInteger;
  23. import net.minecraft.block.state.BlockFaceShape;
  24. import net.minecraft.block.state.BlockStateContainer;
  25. import net.minecraft.block.state.IBlockState;
  26. import net.minecraft.creativetab.CreativeTabs;
  27. import net.minecraft.init.Blocks;
  28. import net.minecraft.init.Items;
  29. import net.minecraft.item.Item;
  30. import net.minecraft.item.ItemBlock;
  31. import net.minecraft.item.ItemStack;
  32. import net.minecraft.util.BlockRenderLayer;
  33. import net.minecraft.util.EnumFacing;
  34. import net.minecraft.util.EnumParticleTypes;
  35. import net.minecraft.util.IStringSerializable;
  36. import net.minecraft.util.Mirror;
  37. import net.minecraft.util.Rotation;
  38. import net.minecraft.util.math.AxisAlignedBB;
  39. import net.minecraft.util.math.BlockPos;
  40. import net.minecraft.util.math.MathHelper;
  41. import net.minecraft.world.IBlockAccess;
  42. import net.minecraft.world.World;
  43. import net.minecraftforge.fml.relauncher.Side;
  44. import net.minecraftforge.fml.relauncher.SideOnly;
  45. import shane.mod.CustomBlocks;
  46. import shane.mod.init.BlocksCustModelInit;
  47. import shane.mod.init.ItemInit;
  48. import shane.mod.library.IHasModel;
  49.  
  50. public class BlockRedstoneConduit extends Block implements IHasModel
  51. {
  52. public static final PropertyEnum<BlockRedstoneConduit.EnumAttachPosition> NORTH = PropertyEnum.<BlockRedstoneConduit.EnumAttachPosition>create("north", BlockRedstoneConduit.EnumAttachPosition.class);
  53. public static final PropertyEnum<BlockRedstoneConduit.EnumAttachPosition> EAST = PropertyEnum.<BlockRedstoneConduit.EnumAttachPosition>create("east", BlockRedstoneConduit.EnumAttachPosition.class);
  54. public static final PropertyEnum<BlockRedstoneConduit.EnumAttachPosition> SOUTH = PropertyEnum.<BlockRedstoneConduit.EnumAttachPosition>create("south", BlockRedstoneConduit.EnumAttachPosition.class);
  55. public static final PropertyEnum<BlockRedstoneConduit.EnumAttachPosition> WEST = PropertyEnum.<BlockRedstoneConduit.EnumAttachPosition>create("west", BlockRedstoneConduit.EnumAttachPosition.class);
  56. public static final PropertyInteger POWER = PropertyInteger.create("power", 0, 15);
  57. protected static final AxisAlignedBB[] REDSTONE_WIRE_AABB = new AxisAlignedBB[]
  58. {
  59. new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 0.8125D),
  60. new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 1.0D),
  61. new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 0.8125D),
  62. new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 1.0D),
  63. new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 0.8125D, 0.0625D, 0.8125D),
  64. new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 0.8125D, 0.0625D, 1.0D),
  65. new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.8125D, 0.0625D, 0.8125D),
  66. new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.8125D, 0.0625D, 1.0D),
  67. new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 1.0D, 0.0625D, 0.8125D),
  68. new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 1.0D, 0.0625D, 1.0D),
  69. new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 1.0D, 0.0625D, 0.8125D),
  70. new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 1.0D, 0.0625D, 1.0D),
  71. new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 1.0D, 0.0625D, 0.8125D),
  72. new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D),
  73. new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 0.8125D),
  74. new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D)
  75. };
  76.  
  77.  
  78. private boolean canProvidePower = true;
  79. /** List of blocks to update with redstone. */
  80. private final Set<BlockPos> blocksNeedingUpdate = Sets.<BlockPos>newHashSet();
  81.  
  82. public BlockRedstoneConduit(String name)
  83. {
  84. super(Material.CIRCUITS);
  85. this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, BlockRedstoneConduit.EnumAttachPosition.NONE)
  86. .withProperty(EAST, BlockRedstoneConduit.EnumAttachPosition.NONE)
  87. .withProperty(SOUTH, BlockRedstoneConduit.EnumAttachPosition.NONE)
  88. .withProperty(WEST, BlockRedstoneConduit.EnumAttachPosition.NONE)
  89. .withProperty(POWER, Integer.valueOf(0)));
  90. setUnlocalizedName(name);
  91. setRegistryName(name);
  92. setHardness(0.5f);
  93. setResistance(30f);
  94. setHarvestLevel("pickaxe", 1);
  95. setCreativeTab(CreativeTabs.DECORATIONS);
  96. setSoundType(SoundType.STONE);
  97.  
  98. BlocksCustModelInit.BLOCKS.add(this);
  99. ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
  100.  
  101. }
  102.  
  103. @Override
  104. public void registerModels()
  105. {
  106. CustomBlocks.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
  107.  
  108. }
  109.  
  110.  
  111. public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
  112. {
  113. return REDSTONE_WIRE_AABB[getAABBIndex(state.getActualState(source, pos))];
  114. }
  115.  
  116. private static int getAABBIndex(IBlockState state)
  117. {
  118. int i = 0;
  119. boolean flag = state.getValue(NORTH) != BlockRedstoneConduit.EnumAttachPosition.NONE;
  120. boolean flag1 = state.getValue(EAST) != BlockRedstoneConduit.EnumAttachPosition.NONE;
  121. boolean flag2 = state.getValue(SOUTH) != BlockRedstoneConduit.EnumAttachPosition.NONE;
  122. boolean flag3 = state.getValue(WEST) != BlockRedstoneConduit.EnumAttachPosition.NONE;
  123.  
  124. if (flag || flag2 && !flag && !flag1 && !flag3)
  125. {
  126. i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
  127. }
  128.  
  129. if (flag1 || flag3 && !flag && !flag1 && !flag2)
  130. {
  131. i |= 1 << EnumFacing.EAST.getHorizontalIndex();
  132. }
  133.  
  134. if (flag2 || flag && !flag1 && !flag2 && !flag3)
  135. {
  136. i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
  137. }
  138.  
  139. if (flag3 || flag1 && !flag && !flag2 && !flag3)
  140. {
  141. i |= 1 << EnumFacing.WEST.getHorizontalIndex();
  142. }
  143.  
  144. return i;
  145. }
  146.  
  147. /**
  148. * Get the actual Block state of this Block at the given position. This applies properties not visible in the
  149. * metadata, such as fence connections.
  150. */
  151. public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
  152. {
  153. state = state.withProperty(WEST, this.getAttachPosition(worldIn, pos, EnumFacing.WEST));
  154. state = state.withProperty(EAST, this.getAttachPosition(worldIn, pos, EnumFacing.EAST));
  155. state = state.withProperty(NORTH, this.getAttachPosition(worldIn, pos, EnumFacing.NORTH));
  156. state = state.withProperty(SOUTH, this.getAttachPosition(worldIn, pos, EnumFacing.SOUTH));
  157. return state;
  158. }
  159.  
  160. private BlockRedstoneConduit.EnumAttachPosition getAttachPosition(IBlockAccess worldIn, BlockPos pos, EnumFacing direction)
  161. {
  162. BlockPos blockpos = pos.offset(direction);
  163. IBlockState iblockstate = worldIn.getBlockState(pos.offset(direction));
  164.  
  165. if (!canConnectTo(worldIn.getBlockState(blockpos), direction, worldIn, blockpos) && (iblockstate.isNormalCube() || !canConnectUpwardsTo(worldIn, blockpos.down())))
  166. {
  167. IBlockState iblockstate1 = worldIn.getBlockState(pos.up());
  168.  
  169. if (!iblockstate1.isNormalCube())
  170. {
  171. boolean flag = worldIn.getBlockState(blockpos).isSideSolid(worldIn, blockpos, EnumFacing.UP) || worldIn.getBlockState(blockpos).getBlock() == Blocks.GLOWSTONE;
  172.  
  173. if (flag && canConnectUpwardsTo(worldIn, blockpos.up()))
  174. {
  175. if (iblockstate.isBlockNormalCube())
  176. {
  177. return BlockRedstoneConduit.EnumAttachPosition.UP;
  178. }
  179.  
  180. return BlockRedstoneConduit.EnumAttachPosition.SIDE;
  181. }
  182. }
  183.  
  184. return BlockRedstoneConduit.EnumAttachPosition.NONE;
  185. }
  186. else
  187. {
  188. return BlockRedstoneConduit.EnumAttachPosition.SIDE;
  189. }
  190. }
  191.  
  192. @Nullable
  193. public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
  194. {
  195. return NULL_AABB;
  196. }
  197.  
  198. /**
  199. * Used to determine ambient occlusion and culling when rebuilding chunks for render
  200. */
  201. public boolean isOpaqueCube(IBlockState state)
  202. {
  203. return false;
  204. }
  205.  
  206. public boolean isFullCube(IBlockState state)
  207. {
  208. return false;
  209. }
  210.  
  211. /**
  212. * Checks if this block can be placed exactly at the given position.
  213. */
  214. public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
  215. {
  216. return worldIn.getBlockState(pos.down()).isTopSolid() || worldIn.getBlockState(pos.down()).getBlock() == Blocks.GLOWSTONE;
  217. }
  218.  
  219. private IBlockState updateSurroundingRedstone(World worldIn, BlockPos pos, IBlockState state)
  220. {
  221. state = this.calculateCurrentChanges(worldIn, pos, pos, state);
  222. List<BlockPos> list = Lists.newArrayList(this.blocksNeedingUpdate);
  223. this.blocksNeedingUpdate.clear();
  224.  
  225. for (BlockPos blockpos : list)
  226. {
  227. worldIn.notifyNeighborsOfStateChange(blockpos, this, false);
  228. }
  229.  
  230. return state;
  231. }
  232.  
  233. private IBlockState calculateCurrentChanges(World worldIn, BlockPos pos1, BlockPos pos2, IBlockState state)
  234. {
  235. IBlockState iblockstate = state;
  236. int i = ((Integer)state.getValue(POWER)).intValue();
  237. int j = 0;
  238. j = this.getMaxCurrentStrength(worldIn, pos2, j);
  239. this.canProvidePower = false;
  240. int k = worldIn.isBlockIndirectlyGettingPowered(pos1);
  241. this.canProvidePower = true;
  242.  
  243. if (k > 0 && k > j - 1)
  244. {
  245. j = k;
  246. }
  247.  
  248. int l = 0;
  249.  
  250. for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  251. {
  252. BlockPos blockpos = pos1.offset(enumfacing);
  253. boolean flag = blockpos.getX() != pos2.getX() || blockpos.getZ() != pos2.getZ();
  254.  
  255. if (flag)
  256. {
  257. l = this.getMaxCurrentStrength(worldIn, blockpos, l);
  258. }
  259.  
  260. if (worldIn.getBlockState(blockpos).isNormalCube() && !worldIn.getBlockState(pos1.up()).isNormalCube())
  261. {
  262. if (flag && pos1.getY() >= pos2.getY())
  263. {
  264. l = this.getMaxCurrentStrength(worldIn, blockpos.up(), l);
  265. }
  266. }
  267. else if (!worldIn.getBlockState(blockpos).isNormalCube() && flag && pos1.getY() <= pos2.getY())
  268. {
  269. l = this.getMaxCurrentStrength(worldIn, blockpos.down(), l);
  270. }
  271. }
  272.  
  273. if (l > j)
  274. {
  275. j = l - 1;
  276. }
  277. else if (j > 0)
  278. {
  279. --j;
  280. }
  281. else
  282. {
  283. j = 0;
  284. }
  285.  
  286. if (k > j - 1)
  287. {
  288. j = k;
  289. }
  290.  
  291. if (i != j)
  292. {
  293. state = state.withProperty(POWER, Integer.valueOf(j));
  294.  
  295. if (worldIn.getBlockState(pos1) == iblockstate)
  296. {
  297. worldIn.setBlockState(pos1, state, 2);
  298. }
  299.  
  300. this.blocksNeedingUpdate.add(pos1);
  301.  
  302. for (EnumFacing enumfacing1 : EnumFacing.values())
  303. {
  304. this.blocksNeedingUpdate.add(pos1.offset(enumfacing1));
  305. }
  306. }
  307.  
  308. return state;
  309. }
  310.  
  311. /**
  312. * Calls World.notifyNeighborsOfStateChange() for all neighboring blocks, but only if the given block is a redstone
  313. * wire.
  314. */
  315. private void notifyWireNeighborsOfStateChange(World worldIn, BlockPos pos)
  316. {
  317. if (worldIn.getBlockState(pos).getBlock() == this)
  318. {
  319. worldIn.notifyNeighborsOfStateChange(pos, this, false);
  320.  
  321. for (EnumFacing enumfacing : EnumFacing.values())
  322. {
  323. worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this, false);
  324. }
  325. }
  326. }
  327.  
  328. /**
  329. * Called after the block is set in the Chunk data, but before the Tile Entity is set
  330. */
  331. public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
  332. {
  333. if (!worldIn.isRemote)
  334. {
  335. this.updateSurroundingRedstone(worldIn, pos, state);
  336.  
  337. for (EnumFacing enumfacing : EnumFacing.Plane.VERTICAL)
  338. {
  339. worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this, false);
  340. }
  341.  
  342. for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
  343. {
  344. this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
  345. }
  346.  
  347. for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
  348. {
  349. BlockPos blockpos = pos.offset(enumfacing2);
  350.  
  351. if (worldIn.getBlockState(blockpos).isNormalCube())
  352. {
  353. this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
  354. }
  355. else
  356. {
  357. this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
  358. }
  359. }
  360. }
  361. }
  362.  
  363. /**
  364. * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
  365. */
  366. public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
  367. {
  368. super.breakBlock(worldIn, pos, state);
  369.  
  370. if (!worldIn.isRemote)
  371. {
  372. for (EnumFacing enumfacing : EnumFacing.values())
  373. {
  374. worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this, false);
  375. }
  376.  
  377. this.updateSurroundingRedstone(worldIn, pos, state);
  378.  
  379. for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
  380. {
  381. this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
  382. }
  383.  
  384. for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
  385. {
  386. BlockPos blockpos = pos.offset(enumfacing2);
  387.  
  388. if (worldIn.getBlockState(blockpos).isNormalCube())
  389. {
  390. this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
  391. }
  392. else
  393. {
  394. this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
  395. }
  396. }
  397. }
  398. }
  399.  
  400. private int getMaxCurrentStrength(World worldIn, BlockPos pos, int strength)
  401. {
  402. if (worldIn.getBlockState(pos).getBlock() != this)
  403. {
  404. return strength;
  405. }
  406. else
  407. {
  408. int i = ((Integer)worldIn.getBlockState(pos).getValue(POWER)).intValue();
  409. return i > strength ? i : strength;
  410. }
  411. }
  412.  
  413. /**
  414. * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
  415. * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
  416. * block, etc.
  417. */
  418. public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
  419. {
  420. if (!worldIn.isRemote)
  421. {
  422. if (this.canPlaceBlockAt(worldIn, pos))
  423. {
  424. this.updateSurroundingRedstone(worldIn, pos, state);
  425. }
  426. else
  427. {
  428. this.dropBlockAsItem(worldIn, pos, state, 0);
  429. worldIn.setBlockToAir(pos);
  430. }
  431. }
  432. }
  433.  
  434. // /**
  435. // * Get the Item that this Block should drop when harvested.
  436. // */
  437. // public Item getItemDropped(IBlockState state, Random rand, int fortune)
  438. // {
  439. // return Items.REDSTONE;
  440. // }
  441.  
  442. public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
  443. {
  444. return !this.canProvidePower ? 0 : blockState.getWeakPower(blockAccess, pos, side);
  445. }
  446.  
  447. public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
  448. {
  449. if (!this.canProvidePower)
  450. {
  451. return 0;
  452. }
  453. else
  454. {
  455. int i = ((Integer)blockState.getValue(POWER)).intValue();
  456.  
  457. if (i == 0)
  458. {
  459. return 0;
  460. }
  461. else if (side == EnumFacing.UP)
  462. {
  463. return i;
  464. }
  465. else
  466. {
  467. EnumSet<EnumFacing> enumset = EnumSet.<EnumFacing>noneOf(EnumFacing.class);
  468.  
  469. for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  470. {
  471. if (this.isPowerSourceAt(blockAccess, pos, enumfacing))
  472. {
  473. enumset.add(enumfacing);
  474. }
  475. }
  476.  
  477. if (side.getAxis().isHorizontal() && enumset.isEmpty())
  478. {
  479. return i;
  480. }
  481. else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY()))
  482. {
  483. return i;
  484. }
  485. else
  486. {
  487. return 0;
  488. }
  489. }
  490. }
  491. }
  492.  
  493. private boolean isPowerSourceAt(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
  494. {
  495. BlockPos blockpos = pos.offset(side);
  496. IBlockState iblockstate = worldIn.getBlockState(blockpos);
  497. boolean flag = iblockstate.isNormalCube();
  498. boolean flag1 = worldIn.getBlockState(pos.up()).isNormalCube();
  499.  
  500. if (!flag1 && flag && canConnectUpwardsTo(worldIn, blockpos.up()))
  501. {
  502. return true;
  503. }
  504. else if (canConnectTo(iblockstate, side, worldIn, pos))
  505. {
  506. return true;
  507. }
  508. else if (iblockstate.getBlock() == Blocks.POWERED_REPEATER && iblockstate.getValue(BlockRedstoneDiode.FACING) == side)
  509. {
  510. return true;
  511. }
  512. else
  513. {
  514. return !flag && canConnectUpwardsTo(worldIn, blockpos.down());
  515. }
  516. }
  517.  
  518. protected static boolean canConnectUpwardsTo(IBlockAccess worldIn, BlockPos pos)
  519. {
  520. return canConnectTo(worldIn.getBlockState(pos), null, worldIn, pos);
  521. }
  522.  
  523. protected static boolean canConnectTo(IBlockState blockState, @Nullable EnumFacing side, IBlockAccess world, BlockPos pos)
  524. {
  525. Block block = blockState.getBlock();
  526.  
  527. if (block == Blocks.REDSTONE_WIRE)
  528. {
  529. return true;
  530. }
  531. // else if (block == BlocksCustModelInit.block_redstone_conduit)
  532. // {
  533. // return true;
  534. // }
  535. else if (Blocks.UNPOWERED_REPEATER.isSameDiode(blockState))
  536. {
  537. EnumFacing enumfacing = (EnumFacing)blockState.getValue(BlockRedstoneRepeater.FACING);
  538. return enumfacing == side || enumfacing.getOpposite() == side;
  539. }
  540. else if (Blocks.OBSERVER == blockState.getBlock())
  541. {
  542. return side == blockState.getValue(BlockObserver.FACING);
  543. }
  544. else
  545. {
  546. return blockState.getBlock().canConnectRedstone(blockState, world, pos, side);
  547. }
  548. }
  549.  
  550. /**
  551. * Can this block provide power. Only wire currently seems to have this change based on its state.
  552. */
  553. public boolean canProvidePower(IBlockState state)
  554. {
  555. return this.canProvidePower;
  556. }
  557.  
  558. @SideOnly(Side.CLIENT)
  559. public static int colorMultiplier(int p_176337_0_)
  560. {
  561. float f = (float)p_176337_0_ / 15.0F;
  562. float f1 = f * 0.6F + 0.4F;
  563.  
  564. if (p_176337_0_ == 0)
  565. {
  566. f1 = 0.3F;
  567. }
  568.  
  569. float f2 = f * f * 0.7F - 0.5F;
  570. float f3 = f * f * 0.6F - 0.7F;
  571.  
  572. if (f2 < 0.0F)
  573. {
  574. f2 = 0.0F;
  575. }
  576.  
  577. if (f3 < 0.0F)
  578. {
  579. f3 = 0.0F;
  580. }
  581.  
  582. int i = MathHelper.clamp((int)(f1 * 255.0F), 0, 255);
  583. int j = MathHelper.clamp((int)(f2 * 255.0F), 0, 255);
  584. int k = MathHelper.clamp((int)(f3 * 255.0F), 0, 255);
  585. return -16777216 | i << 16 | j << 8 | k;
  586. }
  587.  
  588. @SideOnly(Side.CLIENT)
  589. public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
  590. {
  591. int i = ((Integer)stateIn.getValue(POWER)).intValue();
  592.  
  593. if (i != 0)
  594. {
  595. double d0 = (double)pos.getX() + 0.5D + ((double)rand.nextFloat() - 0.5D) * 0.2D;
  596. double d1 = (double)((float)pos.getY() + 0.0625F);
  597. double d2 = (double)pos.getZ() + 0.5D + ((double)rand.nextFloat() - 0.5D) * 0.2D;
  598. float f = (float)i / 15.0F;
  599. float f1 = f * 0.6F + 0.4F;
  600. float f2 = Math.max(0.0F, f * f * 0.7F - 0.5F);
  601. float f3 = Math.max(0.0F, f * f * 0.6F - 0.7F);
  602. worldIn.spawnParticle(EnumParticleTypes.REDSTONE, d0, d1, d2, (double)f1, (double)f2, (double)f3);
  603. }
  604. }
  605.  
  606. public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
  607. {
  608. return new ItemStack(Items.REDSTONE);
  609. }
  610.  
  611. /**
  612. * Convert the given metadata into a BlockState for this Block
  613. */
  614. public IBlockState getStateFromMeta(int meta)
  615. {
  616. return this.getDefaultState().withProperty(POWER, Integer.valueOf(meta));
  617. }
  618.  
  619. @SideOnly(Side.CLIENT)
  620. public BlockRenderLayer getBlockLayer()
  621. {
  622. return BlockRenderLayer.CUTOUT;
  623. }
  624.  
  625. /**
  626. * Convert the BlockState into the correct metadata value
  627. */
  628. public int getMetaFromState(IBlockState state)
  629. {
  630. return ((Integer)state.getValue(POWER)).intValue();
  631. }
  632.  
  633. /**
  634. * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
  635. * blockstate.
  636. */
  637. public IBlockState withRotation(IBlockState state, Rotation rot)
  638. {
  639. switch (rot)
  640. {
  641. case CLOCKWISE_180:
  642. return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(EAST, state.getValue(WEST)).withProperty(SOUTH, state.getValue(NORTH)).withProperty(WEST, state.getValue(EAST));
  643. case COUNTERCLOCKWISE_90:
  644. return state.withProperty(NORTH, state.getValue(EAST)).withProperty(EAST, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(WEST)).withProperty(WEST, state.getValue(NORTH));
  645. case CLOCKWISE_90:
  646. return state.withProperty(NORTH, state.getValue(WEST)).withProperty(EAST, state.getValue(NORTH)).withProperty(SOUTH, state.getValue(EAST)).withProperty(WEST, state.getValue(SOUTH));
  647. default:
  648. return state;
  649. }
  650. }
  651.  
  652. /**
  653. * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
  654. * blockstate.
  655. */
  656. public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  657. {
  658. switch (mirrorIn)
  659. {
  660. case LEFT_RIGHT:
  661. return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH));
  662. case FRONT_BACK:
  663. return state.withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST));
  664. default:
  665. return super.withMirror(state, mirrorIn);
  666. }
  667. }
  668.  
  669. protected BlockStateContainer createBlockState()
  670. {
  671. return new BlockStateContainer(this, new IProperty[] {NORTH, EAST, SOUTH, WEST, POWER});
  672. }
  673.  
  674. /**
  675. * Get the geometry of the queried face at the given position and state. This is used to decide whether things like
  676. * buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
  677. * <p>
  678. * Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
  679. * does not fit the other descriptions and will generally cause other things not to connect to the face.
  680. *
  681. * @return an approximation of the form of the given face
  682. */
  683. public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
  684. {
  685. return BlockFaceShape.UNDEFINED;
  686. }
  687.  
  688. static enum EnumAttachPosition implements IStringSerializable
  689. {
  690. UP("up"),
  691. SIDE("side"),
  692. NONE("none");
  693.  
  694. private final String name;
  695.  
  696. private EnumAttachPosition(String name)
  697. {
  698. this.name = name;
  699. }
  700.  
  701. public String toString()
  702. {
  703. return this.getName();
  704. }
  705.  
  706. public String getName()
  707. {
  708. return this.name;
  709. }
  710. }
  711. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement