Guest User

Untitled

a guest
Sep 6th, 2014
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. private static final int SPREAD_TIME = 5;
  2. private static final int SPREAD_LEVELS = 30;
  3.  
  4. private int timer;
  5. private int level;
  6.  
  7. public TileEntityBomb()
  8. {
  9. timer = SPREAD_TIME;
  10. level = 0;
  11. }
  12.  
  13. public boolean isIdle()
  14. {
  15. return timer < 0;
  16. }
  17.  
  18. @Override
  19. public void updateEntity()
  20. {
  21. if (!this.worldObj.isRemote) {
  22. if (timer == 0 && level < SPREAD_LEVELS) {
  23. spread(this.xCoord + 1, this.yCoord, this.zCoord);
  24. spread(this.xCoord - 1, this.yCoord, this.zCoord);
  25. spread(this.xCoord, this.yCoord, this.zCoord + 1);
  26. spread(this.xCoord, this.yCoord, this.zCoord - 1);
  27. this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, 1, 3);
  28. }else if (timer == SPREAD_TIME * (level - SPREAD_LEVELS))
  29. {
  30. this.worldObj.createExplosion(null, this.xCoord + .5, this.yCoord + .5, this.zCoord + .5, 4, true);
  31. }
  32.  
  33. timer--;
  34. }
  35. }
  36.  
  37. private void spread(int x, int y, int z)
  38. {
  39. if (this.worldObj.isAirBlock(x, y, z)) {
  40. this.worldObj.setBlock(x, y, z, ModBlocks.weird_bomb);
  41.  
  42. TileEntity tile = this.worldObj.getTileEntity(x, y, z);
  43.  
  44. if (tile != null && tile instanceof TileEntityBomb) {
  45. TileEntityBomb bomb = (TileEntityBomb) this.worldObj.getTileEntity(x, y, z);
  46. bomb.level = level + 1;
  47. }
  48. }
  49. }
  50.  
  51. @Override
  52. public void writeToNBT(NBTTagCompound compound)
  53. {
  54. super.writeToNBT(compound);
  55.  
  56. compound.setShort("Timer", (short)timer);
  57. compound.setByte("Level", (byte)level);
  58. }
  59.  
  60. @Override
  61. public void readFromNBT(NBTTagCompound compound)
  62. {
  63. super.readFromNBT(compound);
  64.  
  65. timer = compound.getShort("Timer");
  66. level = compound.getByte("Level");
  67. }
  68.  
  69. @Override
  70. public Packet getDescriptionPacket()
  71. {
  72. NBTTagCompound nbt = new NBTTagCompound();
  73. this.writeToNBT(nbt);
  74. return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbt);
  75. }
  76.  
  77. @Override
  78. public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
  79. {
  80. readFromNBT(packet.func_148857_g());
  81. }
Advertisement
Add Comment
Please, Sign In to add comment