Advertisement
Guest User

Untitled

a guest
Jan 16th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.28 KB | None | 0 0
  1. package waDelma.tinyblocks.block;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashSet;
  5. import java.util.List;
  6. import java.util.Random;
  7. import java.util.Set;
  8.  
  9. import net.minecraft.client.Minecraft;
  10. import net.minecraft.client.particle.EffectRenderer;
  11. import net.minecraft.client.particle.EntityDiggingFX;
  12. import net.minecraft.creativetab.CreativeTabs;
  13. import net.minecraft.block.Block;
  14. import net.minecraft.entity.Entity;
  15. import net.minecraft.entity.item.EntityItem;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.stats.StatList;
  18. import net.minecraft.tileentity.TileEntity;
  19. import net.minecraft.util.AxisAlignedBB;
  20. import net.minecraft.util.EnumMovingObjectType;
  21. import net.minecraft.util.MathHelper;
  22. import net.minecraft.util.MovingObjectPosition;
  23. import net.minecraft.util.Vec3;
  24. import net.minecraft.world.ChunkPosition;
  25. import net.minecraft.world.IBlockAccess;
  26. import net.minecraft.item.Item;
  27. import net.minecraft.item.ItemDye;
  28. import net.minecraft.item.ItemStack;
  29. import net.minecraft.world.World;
  30. import net.minecraftforge.common.ForgeDirection;
  31. import waDelma.tinyblocks.Bound;
  32. import waDelma.tinyblocks.TrayTracer;
  33. import waDelma.tinyblocks.mod_tinyblock;
  34. import waDelma.tinyblocks.handlers.WaterHandler;
  35. import waDelma.tinyblocks.helpers.HelperItem;
  36. import waDelma.tinyblocks.helpers.HelperWorld;
  37.  
  38. public class BlockTinyblock extends Block {
  39.  
  40. private WaterHandler waterhandler;
  41. private Bound bound;
  42. private Set<ChunkPosition> blocksNeedingUpdate;
  43. private boolean wiresProvidePower;
  44.  
  45. public BlockTinyblock(int i) {
  46. super(i, new MaterialTinyBlocks());
  47. setTickRandomly(true);
  48. setCreativeTab(CreativeTabs.tabBlock);
  49. setTextureFile(mod_tinyblock.instance().defaultTexturesPath);
  50. waterhandler = new WaterHandler();
  51. blocksNeedingUpdate = new HashSet<ChunkPosition>();
  52. isBlockContainer = true;
  53. // setLightOpacity(255);
  54. }
  55.  
  56. @Override
  57. public ItemStack getPickBlock(MovingObjectPosition target, World world,
  58. int x, int y, int z) {
  59. TileEntityTinyblock tile = HelperWorld.getTile(world, target.blockX,
  60. target.blockY, target.blockZ);
  61. if (tile != null) {
  62. int ID = HelperItem.swapID(tile.getIDs()[target.subHit]);
  63. int MD = tile.getMDs()[target.subHit];
  64. return new ItemStack(blockID, 1, HelperItem.merge(ID, MD));
  65. }
  66. return null;
  67. }
  68.  
  69. @Override
  70. public void harvestBlock(World world, EntityPlayer player, int x, int y,
  71. int z, int MD) {
  72. player.addStat(StatList.mineBlockStatArray[this.blockID], 1);
  73. player.addExhaustion(0.025F);
  74. }
  75.  
  76. @Override
  77. public boolean removeBlockByPlayer(World world, EntityPlayer player, int x,
  78. int y, int z) {
  79. MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world,
  80. player, false);
  81. if (mop != null && mop.typeOfHit == EnumMovingObjectType.TILE) {
  82. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  83. MovingObjectPosition tray = TrayTracer.traceTinyblock(world,
  84. mop.blockX, mop.blockY, mop.blockZ, player, 1.0F);
  85. if (tray != null) {
  86. if (!player.capabilities.isCreativeMode) {
  87. int damage = HelperItem.merge(tile.getIDs()[tray.subHit],
  88. tile.getMDs()[tray.subHit]);
  89. ItemStack stack = new ItemStack(
  90. mod_tinyblock.instance().tinyblock, 1, damage);
  91. dropBlockAsItem_do(world, x, y, z, stack);
  92. }
  93. if (world.isRemote) {
  94. destructionEffect(world, x, y, z, tray.subHit);
  95. }
  96. tile.removeBlock(tray.subHit);
  97. // removeRedstone(world, player, x, y, z, tile, tray, ii, jj,
  98. // kk);
  99. if (tile.isEmpty()) {
  100. world.removeBlockTileEntity(x, y, z);
  101. return world.setBlockWithNotify(x, y, z, 0);
  102. }
  103. HelperWorld.notifyBlockChange(world, x, y, z, blockID);
  104. tile.dirtyfy();
  105. return false;
  106. }
  107. }
  108. return false;
  109. }
  110.  
  111. @Override
  112. public void onBlockDestroyedByPlayer(World world, int x, int y, int z,
  113. int MD) {
  114. }
  115.  
  116. @Override
  117. public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
  118. }
  119.  
  120. @Override
  121. public ArrayList<ItemStack> getBlockDropped(World world, int x, int y,
  122. int z, int metadata, int fortune) {
  123. ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
  124. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  125. if (tile != null) {
  126. for (int n = 0; n < tile.getIDs().length; n++) {
  127. int damage = HelperItem.merge(tile.getIDs()[n],
  128. tile.getMDs()[n]);
  129. ret.add(new ItemStack(blockID, 1, damage));
  130. }
  131. }
  132. return ret;
  133. }
  134.  
  135. @Override
  136. public boolean addBlockHitEffects(World world, MovingObjectPosition target,
  137. EffectRenderer effect) {
  138. int x = target.blockX;
  139. int y = target.blockY;
  140. int z = target.blockZ;
  141. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  142. int sub = target.subHit;
  143. int ID = tile.getIDs()[sub]; // world.getBlockId(x, y, z);
  144.  
  145. if (ID != 0) {
  146. Block block = Block.blocksList[ID];
  147. double border = 0.1;
  148.  
  149. Random rand = new Random();
  150. double xx = x + rand.nextDouble()
  151. * (0.5 - (border * 2.0F)) + border;
  152. double yy = y + rand.nextDouble()
  153. * (0.5 - (border * 2.0F)) + border;
  154. double zz = z + rand.nextDouble()
  155. * (0.5 - (border * 2.0F)) + border;
  156.  
  157. double amount = (target.sideHit % 2 == 0 ? -border : border + 0.5);
  158. switch (target.sideHit) {
  159. case 0:
  160. case 1:
  161. yy = y + amount;
  162. break;
  163. case 2:
  164. case 3:
  165. zz = z + amount;
  166. break;
  167. case 4:
  168. case 5:
  169. xx = x + amount;
  170. break;
  171. }
  172. if (HelperWorld.isTinyblockInDirection(sub, ForgeDirection.UP)) {
  173. yy += 0.5;
  174. }
  175. if (HelperWorld.isTinyblockInDirection(sub, ForgeDirection.SOUTH)) {
  176. zz += 0.5;
  177. }
  178. if (HelperWorld.isTinyblockInDirection(sub, ForgeDirection.EAST)) {
  179. xx += 0.5;
  180. }
  181.  
  182. effect.addEffect(
  183. (new EntityDiggingFX(world, xx, yy, zz, 0.0D, 0.0D, 0.0D,
  184. block, target.sideHit, world.getBlockMetadata(x, y,
  185. z))).func_70596_a(x, y, z)
  186. .multiplyVelocity(0.2F)
  187. .multipleParticleScaleBy(0.6F), block);
  188. }
  189. return true;
  190. }
  191.  
  192. @Override
  193. public boolean addBlockDestroyEffects(World world, int x, int y, int z,
  194. int meta, EffectRenderer effectRenderer) {
  195. return true;
  196. }
  197.  
  198. public void destructionEffect(World world, int x, int y, int z, int n) {
  199. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  200. int ID = tile.getIDs()[n];
  201. int MD = tile.getMDs()[n];
  202. Minecraft minecraft = mod_tinyblock.instance().client;
  203. Block block = Block.blocksList[ID];
  204. Random rand = new Random();
  205. if (block != null) {
  206. double x1 = x;
  207. double y1 = y;
  208. double z1 = z;
  209. byte size = 4;
  210. if (HelperWorld.isTinyblockInDirection(n, ForgeDirection.UP)) {
  211. y1 += 0.5;
  212. }
  213. if (HelperWorld.isTinyblockInDirection(n, ForgeDirection.EAST)) {
  214. x1 += 0.5;
  215. }
  216. if (HelperWorld.isTinyblockInDirection(n, ForgeDirection.SOUTH)) {
  217. z1 += 0.5;
  218. }
  219.  
  220. for (int i = 0; i < size; ++i) {
  221. for (int j = 0; j < size; ++j) {
  222. for (int k = 0; k < size; ++k) {
  223. double xx = x1 + (i / 2D + 0.5D) / size;
  224. double yy = y1 + (j / 2D + 0.5D) / size;
  225. double zz = z1 + (k / 2D + 0.5D) / size;
  226. int direction = rand.nextInt(6);
  227. minecraft.effectRenderer.addEffect(
  228. (new EntityDiggingFX(world, xx, yy, zz, xx - x1
  229. - 0.5D, yy - y1 - 0.5D, zz - z1 - 0.5D,
  230. block, direction, MD)).func_70596_a(x,
  231. y, z).multipleParticleScaleBy(0.8F),
  232. block);
  233. }
  234. }
  235. }
  236. }
  237. }
  238.  
  239. // public boolean isProvidingWeakPower(IBlockAccess par1IBlockAccess, int
  240. // par2, int par3, int par4, int par5)
  241. // {
  242. // return false;
  243. // }
  244.  
  245. // public boolean isProvidingStrongPower(IBlockAccess par1IBlockAccess, int
  246. // par2, int par3, int par4, int par5)
  247. // {
  248. // return false;
  249. // }
  250.  
  251. // public void onBlockEventReceived(World par1World, int par2, int par3, int
  252. // par4, int par5, int par6) {}
  253.  
  254. @Override
  255. public void getSubBlocks(int ID, CreativeTabs tabs, List list) {
  256. for (Block block : Block.blocksList) {
  257. if (block != null && block.blockID != 0
  258. && block.getClass() != this.getClass()
  259. && !block.blockMaterial.isLiquid()) {
  260. List<ItemStack> subBlocks = new ArrayList<ItemStack>();
  261. block.getSubBlocks(block.blockID, tabs, subBlocks);
  262. for (ItemStack stack : subBlocks) {
  263. list.add(new ItemStack(ID, 1, HelperItem.merge(
  264. stack.itemID, stack.getItemDamage())));
  265. }
  266. }
  267. }
  268. list.add(new ItemStack(ID, 1, HelperItem.merge(
  269. Block.redstoneWire.blockID, 0)));
  270. }
  271.  
  272. @Override
  273. public String getBlockName() {
  274. return mod_tinyblock.instance().TinyblockTag;
  275. }
  276.  
  277. @Override
  278. public boolean onBlockActivated(World world, int x, int y, int z,
  279. EntityPlayer player, int n, float xx, float yy, float zz) {
  280. // if (world.isRemote)
  281. // return false;
  282. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  283. boolean sneaking = player.isSneaking();
  284. MovingObjectPosition tray = TrayTracer.traceTinyblock(world, x, y, z,
  285. player, 1.0F);
  286. if (tray == null) {
  287. return false;
  288. }
  289. // MovingObjectPosition mop = player.rayTrace(par1, par3);
  290. ItemStack stack = player.getCurrentEquippedItem();
  291. if (stack != null) {
  292. int id = stack.itemID;
  293. if (id == Item.dyePowder.itemID) {
  294. tile.getCOLOR()[tray.subHit] = ItemDye.dyeColors[stack
  295. .getItemDamage()];
  296. HelperWorld.notifyBlockChange(world, x, y, z, blockID);
  297. return true;
  298. } else {
  299. mod_tinyblock.instance();
  300. if (id == mod_tinyblock.opticTransformer.itemID) {
  301. if (sneaking) {
  302.  
  303. } else if (tile.getTINY()[tray.subHit]) {
  304. tile.getTINY()[tray.subHit] = false;
  305. } else {
  306. tile.getTINY()[tray.subHit] = true;
  307. }
  308. if (!player.capabilities.isCreativeMode) {
  309. stack.damageItem(1, player);
  310. }
  311. HelperWorld.notifyBlockChange(world, x, y, z, blockID);
  312. return true;
  313. } else if (id == Item.redstone.itemID) {// TODO: Redstone
  314. // behaviour
  315. // setRedstone(tray, tile);
  316. // mod_tinyblock.instance().notifyBlockChange(world, i, j,
  317. // k,
  318. // Block.redstoneWire.blockID);
  319. // tile.setBlock(tray.subHit, Block.redstoneWire.blockID,
  320. // 0);
  321. // System.out.println("Redstone wire");
  322. }
  323. }
  324. }
  325. return false;
  326. }
  327.  
  328. public boolean setAll(TileEntityTinyblock tile, int n, int ID, int MD,
  329. boolean tiny) {
  330. if (tile.getIDs()[n] == 0) {
  331. tile.setAll(n, ID, MD, mod_tinyblock.instance().defaultColor, tiny);
  332. return true;
  333. }
  334. return false;
  335. }
  336.  
  337. @Override
  338. public float getPlayerRelativeBlockHardness(EntityPlayer player,
  339. World world, int x, int y, int z) {
  340. // System.out.println("blockStrength");
  341. MovingObjectPosition mop = HelperWorld
  342. .getMOP(mod_tinyblock.instance().client);
  343. if (mop == null) {
  344. return 1.0f;
  345. }
  346. if (mop.typeOfHit == EnumMovingObjectType.TILE) {
  347. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  348. MovingObjectPosition tray = TrayTracer.traceTinyblock(world,
  349. mop.blockX, mop.blockY, mop.blockZ, player, 1.0F);
  350. if (tray != null) {
  351. Block block = Block.blocksList[tile.getIDs()[tray.subHit]];
  352. if (block != null) {
  353. stepSound = block.stepSound;
  354. return player.getCurrentPlayerStrVsBlock(block, 0)
  355. / block.getBlockHardness(world, x, y, z) / 30F * 4F;
  356. }
  357. }
  358. }
  359. return 1.0F;
  360. }
  361.  
  362. @Override
  363. public boolean canCollideCheck(int i, boolean flag) {
  364. return true;
  365. }
  366.  
  367. @Override
  368. public MovingObjectPosition collisionRayTrace(World world, int x, int y,
  369. int z, Vec3 vec3d, Vec3 vec3d1) {
  370. if (world.getBlockMetadata(x, y, z) == 1)
  371. return super.collisionRayTrace(world, x, y, z, vec3d, vec3d1);
  372. EntityPlayer entityplayer = mod_tinyblock.instance().client.thePlayer;
  373. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  374. MovingObjectPosition temp;
  375. double shortestDistance = Float.MAX_VALUE;
  376. MovingObjectPosition result = null;
  377. for (int n = 0; n < tile.getIDs().length; n++)
  378. if (tile.getIDs()[n] != 0) {
  379. Block block = Block.blocksList[tile.getIDs()[n]];
  380. if (block != null && !block.blockMaterial.isLiquid()) {
  381. bound = TrayTracer.setBounds(tile, n);
  382. temp = TrayTracer.rayTrace(world, x, y, z, vec3d, vec3d1,
  383. bound);
  384. if (temp != null) {
  385. temp.subHit = n;
  386. if (temp.hitVec.distanceTo(entityplayer
  387. .getPosition(1.0F)) < shortestDistance) {
  388. result = temp;
  389. shortestDistance = temp.hitVec
  390. .distanceTo(entityplayer.getPosition(1.0F));
  391. }
  392. }
  393. }
  394. }
  395. return result;
  396. }
  397.  
  398. @Override
  399. public TileEntity createTileEntity(World world, int metadata) {
  400. return new TileEntityTinyblock();
  401. }
  402.  
  403. @Override
  404. public void addCollidingBlockToList(World world, int x, int y, int z,
  405. AxisAlignedBB axis, List list, Entity entity) {
  406. if (world.getBlockMetadata(x, y, z) != 1) {
  407. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  408. if (tile.getIDs() == null)
  409. return;
  410. for (int n = 0; n < tile.getIDs().length; n++)
  411. if (tile.getIDs()[n] != 0
  412. && !Block.blocksList[tile.getIDs()[n]].blockMaterial
  413. .isLiquid()
  414. && tile.getIDs()[n] != Block.redstoneWire.blockID) {
  415. bound = TrayTracer.setBounds(tile, n);
  416. AxisAlignedBB ax = AxisAlignedBB.getAABBPool()
  417. .addOrModifyAABBInPool(x + bound.minX,
  418. y + bound.minY, z + bound.minZ,
  419. x + bound.maxX, y + bound.maxY,
  420. z + bound.maxZ);
  421. if (ax != null && axis.intersectsWith(ax)) {
  422. list.add(ax);
  423. }
  424. }
  425. return;
  426. }
  427. super.addCollidingBlockToList(world, x, y, z, axis, list, entity);
  428. }
  429.  
  430. @Override
  431. public int getLightValue(IBlockAccess access, int x, int y, int z) {
  432. TileEntityTinyblock tile = HelperWorld.getTile(access, x, y, z);
  433. if (tile == null || access.getBlockMetadata(x, y, z) == 1)
  434. return 0;
  435. float light = 0;
  436. int finallight = 0;
  437. int numberblocks = 1;
  438. for (int ID : tile.getIDs())
  439. if (ID != 0) {
  440. light += Block.lightValue[ID];
  441. numberblocks++;
  442. }
  443. finallight = (int) (light / numberblocks) * 2;
  444. return finallight;
  445. }
  446.  
  447. @Override
  448. public int getBlockTexture(IBlockAccess blockAccess, int x, int y, int z,
  449. int side) {
  450. net.minecraft.client.Minecraft minecraft = mod_tinyblock.instance().client;
  451. MovingObjectPosition mop = HelperWorld.getMOP(minecraft);
  452. EntityPlayer player = minecraft.thePlayer;
  453. World world = player.worldObj;
  454.  
  455. MovingObjectPosition tray = TrayTracer.traceTinyblock(world, x, y, z,
  456. player, 1.0F);
  457. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  458. if (tile != null)
  459. if (tray != null) {
  460. Block block = Block.blocksList[tile.getIDs()[tray.subHit]];
  461. if (block != null)
  462. return block.getBlockTextureFromSideAndMetadata(side,
  463. tile.getMDs()[tray.subHit]);
  464. }
  465. return super.getBlockTexture(blockAccess, x, y, z, side);
  466. }
  467.  
  468. @Override
  469. public int colorMultiplier(IBlockAccess access, int x, int y, int z) {
  470. EntityPlayer player = mod_tinyblock.instance().client.thePlayer;
  471. MovingObjectPosition tray = TrayTracer.traceTinyblock(access, x, y, z,
  472. player, 1.0F);
  473. TileEntityTinyblock tile = HelperWorld.getTile(access, x, y, z);
  474.  
  475. if (tray != null) {
  476. int color = tile.getCOLOR()[tray.subHit];
  477. boolean liquid = false;
  478. if (blockMaterial != null)
  479. liquid = blockMaterial.isLiquid();
  480. if (color == mod_tinyblock.instance().defaultColor) {
  481. color = Block.blocksList[tile.getIDs()[tray.subHit]]
  482. .colorMultiplier(access, x, y, z);
  483. } else if (liquid)
  484. color = mod_tinyblock.instance().defaultColor;
  485. return color;
  486. }
  487. return super.colorMultiplier(access, x, y, z);
  488. }
  489.  
  490. @Override
  491. public int getRenderType() {
  492. return mod_tinyblock.instance().tinyBlockRenderID;
  493. }
  494.  
  495. // @Override
  496. // public boolean isBlockReplaceable(World world, int x, int y, int z) {
  497. // // System.out.println("replace");
  498. // return true;//world.getBlockId(x, y, z) == blockID;
  499. // }
  500.  
  501. @Override
  502. public boolean canPlaceBlockAt(World world, int x, int y, int z) {
  503. int ID = world.getBlockId(x, y, z);
  504. return ID == 0 || blocksList[ID].blockMaterial.isReplaceable()
  505. || ID == blockID;
  506. }
  507.  
  508. @Override
  509. public boolean isBlockSolidOnSide(World world, int x, int y, int z,
  510. ForgeDirection side) {
  511. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  512. switch (side) {
  513. case DOWN:
  514. return sideIsFull(tile, 0, 1, 2, 3);
  515. case UP:
  516. return sideIsFull(tile, 4, 5, 6, 7);
  517. case NORTH:
  518. return sideIsFull(tile, 0, 1, 4, 5);
  519. case SOUTH:
  520. return sideIsFull(tile, 2, 3, 6, 7);
  521. case WEST:
  522. return sideIsFull(tile, 0, 2, 4, 6);
  523. case EAST:
  524. return sideIsFull(tile, 1, 3, 5, 7);
  525. }
  526. return false;
  527. }
  528.  
  529. private boolean sideIsFull(TileEntityTinyblock tile, int a, int b, int c,
  530. int d) {
  531. return tile.isFullBlock(a) && tile.isFullBlock(b)
  532. && tile.isFullBlock(c) && tile.isFullBlock(d);
  533. }
  534.  
  535. @Override
  536. public boolean isOpaqueCube() {
  537. return false;
  538. }
  539.  
  540. @Override
  541. public void onBlockAdded(World world, int x, int y, int z) {
  542. super.onBlockAdded(world, x, y, z);
  543. if (world.getBlockId(x, y, z) == blockID)
  544. world.scheduleBlockUpdate(x, y, z, blockID, tickRate());
  545. // System.out.println("added at: i: " + i + " j: " + j + " k: " + k);
  546. }
  547.  
  548. @Override
  549. public int getLightOpacity(World world, int x, int y, int z) {
  550. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  551. return lightOpacity[blockID];
  552. }
  553.  
  554. @Override
  555. public void onEntityWalking(World world, int x, int y, int z, Entity entity) {
  556. boolean diffX = entity.posX - x < 0.5F;
  557. boolean diffY = entity.posY - y - entity.height < 0.5F;
  558. boolean diffZ = entity.posZ - z < 0.5F;
  559. // System.out.println(diffX + " " + diffY + " " + diffZ);
  560. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  561. Block block;
  562. int ID;
  563. if (diffX) {
  564. if (diffY) {
  565. if (diffZ) {
  566. ID = tile.getIDs()[0];
  567. } else {
  568. ID = tile.getIDs()[2];
  569. }
  570. } else {
  571. if (diffZ) {
  572. ID = tile.getIDs()[4];
  573. } else {
  574. ID = tile.getIDs()[6];
  575. }
  576. }
  577. } else {
  578. if (diffY) {
  579. if (diffZ) {
  580. ID = tile.getIDs()[1];
  581. } else {
  582. ID = tile.getIDs()[3];
  583. }
  584. } else {
  585. if (diffZ) {
  586. ID = tile.getIDs()[5];
  587. } else {
  588. ID = tile.getIDs()[7];
  589. }
  590. }
  591. }
  592.  
  593. block = Block.blocksList[ID];
  594. if (block != null)
  595. stepSound = block.stepSound;
  596. }
  597.  
  598. public MovingObjectPosition getMovingObjectPositionFromPlayer(World world,
  599. EntityPlayer player, boolean flag) {
  600. float var4 = 1.0F;
  601. float pitch = player.prevRotationPitch
  602. + (player.rotationPitch - player.prevRotationPitch) * var4;
  603. float yaw = player.prevRotationYaw
  604. + (player.rotationYaw - player.prevRotationYaw) * var4;
  605. double posX = player.prevPosX + (player.posX - player.prevPosX) * var4;
  606. double posY = player.prevPosY + (player.posY - player.prevPosY) * var4
  607. + 1.62D - player.yOffset;
  608. double posZ = player.prevPosZ + (player.posZ - player.prevPosZ) * var4;
  609. Vec3 posVec = world.getWorldVec3Pool().getVecFromPool(posX, posY, posZ);
  610. float var14 = MathHelper.cos(-yaw * 0.017453292F - (float) Math.PI);
  611. float var15 = MathHelper.sin(-yaw * 0.017453292F - (float) Math.PI);
  612. float var16 = -MathHelper.cos(-pitch * 0.017453292F);
  613. float var17 = MathHelper.sin(-pitch * 0.017453292F);
  614. float var18 = var15 * var16;
  615. float var20 = var14 * var16;
  616. double var21 = 5.0D;
  617. // if (player instanceof EntityPlayerMP) {
  618. // var21 = ((EntityPlayerMP) player).theItemInWorldManager
  619. // .getBlockReachDistance();
  620. // }
  621. Vec3 var23 = posVec.addVector(var18 * var21, var17 * var21, var20
  622. * var21);
  623. return world.rayTraceBlocks_do_do(posVec, var23, flag, !flag);
  624. }
  625.  
  626. public void removeRedstone(World world, EntityPlayer player, int x, int y,
  627. int z, TileEntityTinyblock tile, MovingObjectPosition tray,
  628. double ii, double jj, double kk) {
  629. ItemStack redStack = new ItemStack(mod_tinyblock.instance().tinyblock,
  630. 1, HelperItem.merge(Block.redstoneWire.blockID, 0));
  631. if (tray.subHit < 4) {
  632. int n = tray.subHit + 4;
  633. if (tile.getIDs()[n] == Block.redstoneWire.blockID) {
  634. tile.removeBlock(n);
  635. if (!player.capabilities.isCreativeMode) {
  636. EntityItem entityitem = new EntityItem(world, x + ii, y
  637. + jj, z + kk, redStack);
  638. entityitem.delayBeforeCanPickup = 10;
  639. world.spawnEntityInWorld(entityitem);
  640. }
  641. }
  642. } else {
  643. TileEntityTinyblock tileUp = HelperWorld
  644. .getTile(world, x, y + 1, z);
  645. if (tileUp != null) {
  646. int n = tray.subHit - 4;
  647. if (tileUp.getIDs()[n] == Block.redstoneWire.blockID) {
  648. tileUp.removeBlock(n);
  649. if (!player.capabilities.isCreativeMode) {
  650. EntityItem entityitem = new EntityItem(world, x + ii, y
  651. + jj, z + kk, redStack);
  652. entityitem.delayBeforeCanPickup = 10;
  653. world.spawnEntityInWorld(entityitem);
  654. }
  655. }
  656. }
  657. }
  658. }
  659.  
  660. @Override
  661. public boolean renderAsNormalBlock() {
  662. return false;
  663. }
  664.  
  665. @Override
  666. public void setBlockBoundsBasedOnState(IBlockAccess access, int x, int y,
  667. int z) {
  668. if (access.getBlockMetadata(x, y, z) == 1)
  669. setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  670. }
  671.  
  672. @Override
  673. public int tickRate() {
  674. return 5;
  675. }
  676.  
  677. @Override
  678. public void randomDisplayTick(World world, int x, int y, int z,
  679. Random random) {
  680. waterhandler.tick(world, x, y, z, random);
  681.  
  682. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  683. for (int n = 0; n < tile.getIDs().length; n++)
  684. if (tile.getIDs()[n] == Block.redstoneWire.blockID) {
  685. int meta = tile.getMDs()[n];
  686. if (meta > 0) {
  687. double ii = x + 0.5D / 2 + (random.nextFloat() - 0.5D)
  688. * 0.2D;
  689. double jj = (y + 0.0625F / 2);
  690. double kk = z + 0.5D / 2 + (random.nextFloat() - 0.5D)
  691. * 0.2D;
  692. switch (n) {
  693. case 0:
  694.  
  695. break;
  696. case 1:
  697. ii += 0.5;
  698. break;
  699. case 2:
  700. kk += 0.5;
  701. break;
  702. case 3:
  703. ii += 0.5;
  704. kk += 0.5;
  705. break;
  706. case 4:
  707. jj += 0.5;
  708. break;
  709. case 5:
  710. ii += 0.5;
  711. jj += 0.5;
  712. break;
  713. case 6:
  714. kk += 0.5;
  715. jj += 0.5;
  716. break;
  717. case 7:
  718. ii += 0.5;
  719. kk += 0.5;
  720. jj += 0.5;
  721. break;
  722. }
  723. float partialMeta = meta / 15.0F;
  724. float multipliedMeta = partialMeta * 0.6F + 0.4F;
  725.  
  726. if (meta == 0)
  727. multipliedMeta = 0.0F;
  728.  
  729. float var15 = partialMeta * partialMeta * 0.7F - 0.5F;
  730. float var16 = partialMeta * partialMeta * 0.6F - 0.7F;
  731.  
  732. if (var15 < 0.0F)
  733. var15 = 0.0F;
  734. if (var16 < 0.0F)
  735. var16 = 0.0F;
  736.  
  737. world.spawnParticle("reddust", ii, jj, kk, multipliedMeta,
  738. var15, var16);
  739. }
  740. }
  741. }
  742.  
  743. @Override
  744. public void updateTick(World world, int x, int y, int z, Random random) {
  745. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  746. if (tile != null) {
  747. // EntityPlayer player = ModLoader.getMinecraftInstance().thePlayer;
  748. boolean flag = false;
  749. for (int n = 0; n < 4; n++) {
  750. if (tile.getIDs()[n] == Block.redstoneWire.blockID)
  751. if (world.getBlockId(x, y - 1, z) == 0) {
  752. tile.removeBlock(n);
  753. // if(!player.capabilities.isCreativeMode){
  754. float f = 0.7F;
  755. double xx = (world.rand.nextFloat() * f) + (1.0F - f)
  756. * 0.5D;
  757. double yy = (world.rand.nextFloat() * f) + (1.0F - f)
  758. * 0.5D;
  759. double zz = (world.rand.nextFloat() * f) + (1.0F - f)
  760. * 0.5D;
  761. ItemStack redStack = new ItemStack(
  762. mod_tinyblock.instance().tinyblock, 1,
  763. HelperItem.merge(Block.redstoneWire.blockID, 0));
  764. EntityItem entityitem = new EntityItem(world, x + xx, y
  765. + yy, z + zz, redStack);
  766. entityitem.delayBeforeCanPickup = 10;
  767. world.spawnEntityInWorld(entityitem);
  768. flag = true;
  769. // }
  770. }
  771. }
  772. if (flag)
  773. world.notifyBlockChange(x, y, z, Block.redstoneWire.blockID);
  774. }
  775. // Turns whole block to whole
  776. /*
  777. * TileEntityTinyblock tile =
  778. * (TileEntityTinyblock)world.getBlockTileEntity(x, y, z); int ID =
  779. * tile.IDs[0]; int MD = tile.MDs[0]; boolean flag = true; for(int n =
  780. * 1; n < tile.IDs.length; n++){ if(tile.IDs[n] == ID && tile.MDs[n] ==
  781. * MD){ continue; }else{ flag = false; break; } } if(flag)
  782. * world.setBlockAndMetadataWithNotify(x, y, z, ID, MD);
  783. */
  784. }
  785.  
  786. @Override
  787. public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z,
  788. int dir) {
  789. // TODO: Make it connect redstone correctly
  790. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  791. if (tile != null)
  792. for (int n = 0; n < tile.getIDs().length; n++)
  793. if (tile.getIDs()[n] == Block.redstoneWire.blockID) {
  794. // @off
  795. switch (dir) {
  796. case 0:
  797. switch (n) {
  798. case 0:
  799. case 1:
  800. case 4:
  801. case 5:
  802. return true;
  803. }
  804. break;
  805. case 1:
  806. switch (n) {
  807. case 1:
  808. case 3:
  809. case 5:
  810. case 7:
  811. return true;
  812. }
  813. break;
  814. case 2:
  815. switch (n) {
  816. case 3:
  817. case 2:
  818. case 7:
  819. case 6:
  820. return true;
  821. }
  822. break;
  823. case 3:
  824. switch (n) {
  825. case 2:
  826. case 0:
  827. case 6:
  828. case 4:
  829. return true;
  830. }
  831. break;
  832. }
  833. // @on
  834. }
  835. return false;
  836. }
  837.  
  838. @Override
  839. public void onNeighborBlockChange(World world, int x, int y, int z, int ID) {
  840. if (!world.isRemote) {
  841. updateAndPropagateCurrentStrength(world, x, y, z);
  842. super.onNeighborBlockChange(world, x, y, z, ID);
  843. }
  844. }
  845.  
  846. private void updateAndPropagateCurrentStrength(World world, int x, int y,
  847. int z) {
  848. TileEntityTinyblock tile = HelperWorld.getTile(world, x, y, z);
  849. for (int n = 0; n < tile.getIDs().length; n++)
  850. if (tile.getIDs()[n] == Block.redstoneWire.blockID)
  851. calculateCurrentChanges(world, x, y, z, x, y, z, tile, n);
  852. List<ChunkPosition> blocksForUpdate = new ArrayList<ChunkPosition>(
  853. blocksNeedingUpdate);
  854. blocksNeedingUpdate.clear();
  855.  
  856. for (int n = 0; n < blocksForUpdate.size(); ++n) {
  857. ChunkPosition chunk = blocksForUpdate.get(n);
  858. world.notifyBlocksOfNeighborChange(chunk.x, chunk.y, chunk.z,
  859. blockID);
  860. }
  861. }
  862.  
  863. // TODO: Multiply metadata same way as water and make it work with
  864. // tinyblocks
  865. private void calculateCurrentChanges(World world, int x, int y, int z,
  866. int i2, int j2, int k2, TileEntityTinyblock tile, int n) {
  867. int metadata = tile.getMDs()[n];
  868. int strength = 0;
  869. wiresProvidePower = false;
  870. boolean indirectPower = world.isBlockIndirectlyGettingPowered(x, y, z);
  871. wiresProvidePower = true;
  872. int m;
  873. int xx;
  874. int zz;
  875.  
  876. if (indirectPower) {
  877. strength = 15;
  878. } else {
  879. for (m = 0; m < 4; ++m) {
  880. xx = x;
  881. zz = z;
  882. // @off
  883. switch (m) {
  884. case 0:
  885. xx--;
  886. break;
  887. case 1:
  888. xx++;
  889. break;
  890. case 2:
  891. zz--;
  892. break;
  893. case 3:
  894. zz++;
  895. break;
  896. }
  897. // @on
  898.  
  899. if (xx != i2 || y != j2 || zz != k2)
  900. strength = getMaxCurrentStrength(world, xx, y, zz, strength);
  901.  
  902. if (world.isBlockNormalCube(xx, y, zz)
  903. && !world.isBlockNormalCube(x, y + 1, z)) {
  904. if (xx != i2 || y + 1 != j2 || zz != k2)
  905. strength = getMaxCurrentStrength(world, xx, y + 1, zz,
  906. strength);
  907. } else if (!world.isBlockNormalCube(xx, y, zz)
  908. && (xx != i2 || y - 1 != j2 || zz != k2)) {
  909. strength = getMaxCurrentStrength(world, xx, y - 1, zz,
  910. strength);
  911. }
  912. }
  913.  
  914. if (strength > 0) {
  915. strength--;
  916. } else {
  917. strength = 0;
  918. }
  919. }
  920.  
  921. if (metadata != strength) {
  922. world.editingBlocks = true;
  923. tile.getMDs()[n] = strength;// world.setBlockMetadataWithNotify(i,
  924. // j, k,
  925. // strength);
  926. // world.markBlocksDirty(i, j, k, i, j, k);
  927. world.editingBlocks = false;
  928.  
  929. for (m = 0; m < 4; ++m) {
  930. xx = x;
  931. zz = z;
  932. int yy = y - 1;
  933. // @off
  934. switch (m) {
  935. case 0:
  936. xx--;
  937. break;
  938. case 1:
  939. xx++;
  940. break;
  941. case 2:
  942. zz--;
  943. break;
  944. case 3:
  945. zz++;
  946. break;
  947. }
  948. // @on
  949.  
  950. if (world.isBlockNormalCube(xx, y, zz))
  951. yy += 2;
  952.  
  953. boolean var15 = false;
  954. int comparedStrength = getMaxCurrentStrength(world, xx, y, zz,
  955. -1);
  956. strength = tile.getMDs()[n];// world.getBlockMetadata(i, j, k);
  957.  
  958. if (strength > 0)
  959. --strength;
  960.  
  961. if (comparedStrength >= 0 && comparedStrength != strength)
  962. calculateCurrentChanges(world, xx, y, zz, x, y, z, tile, n);
  963.  
  964. comparedStrength = getMaxCurrentStrength(world, xx, yy, zz, -1);
  965. strength = tile.getMDs()[n];// world.getBlockMetadata(i, j, k);
  966.  
  967. if (strength > 0)
  968. --strength;
  969.  
  970. if (comparedStrength >= 0 && comparedStrength != strength)
  971. calculateCurrentChanges(world, xx, yy, zz, x, y, z, tile, n);
  972. }
  973.  
  974. if (metadata < strength || strength == 0) {
  975. blocksNeedingUpdate.add(new ChunkPosition(x , y , z));
  976. blocksNeedingUpdate.add(new ChunkPosition(x - 1, y , z));
  977. blocksNeedingUpdate.add(new ChunkPosition(x + 1, y , z));
  978. blocksNeedingUpdate.add(new ChunkPosition(x , y - y, z));
  979. blocksNeedingUpdate.add(new ChunkPosition(x , y + y, z));
  980. blocksNeedingUpdate.add(new ChunkPosition(x , y , z - 1));
  981. blocksNeedingUpdate.add(new ChunkPosition(x , y , z + 1));
  982. }
  983. }
  984. }
  985.  
  986. private int getMaxCurrentStrength(World world, int x, int y, int z, int old) {
  987. if (world.getBlockId(x, y, z) != Block.redstoneWire.blockID) {
  988. return old;
  989. } else {
  990. int meta = world.getBlockMetadata(x, y, z);
  991. return meta > old ? meta : old;
  992. }
  993. }
  994. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement