BlockInfoCommand.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "BlockInfoCommand.h"
  2. #include <Logging.h>
  3. #include "Block.h"
  4. #include "BlockType.h"
  5. #include "Chat.h"
  6. #include "Dimension.h"
  7. #include "Game.h"
  8. BlockInfoCommand::BlockInfoCommand()
  9. : ChatCommand("block_info", "Outputs information of a specified block", 1)
  10. {
  11. addParam(
  12. new IntegerParameter("x", "The x position of the block", false, 0));
  13. addParam(
  14. new IntegerParameter("y", "The y position of the block", false, 0));
  15. addParam(
  16. new IntegerParameter("z", "The z position of the block", false, 0));
  17. addParam(new IntegerParameter(
  18. "dimensionId", "The dimensionId of the block", true, [](Entity* e) {
  19. if (e) return e->getDimensionId();
  20. return 0;
  21. }));
  22. }
  23. bool BlockInfoCommand::execute(
  24. Framework::RCArray<Framework::Text>& params, Entity* zActor) const
  25. {
  26. int x = (int)*params.z(0);
  27. int y = (int)*params.z(1);
  28. int z = (int)*params.z(2);
  29. int dimension = (int)*params.z(3);
  30. Framework::Vec3<int> location = {x, y, z};
  31. Framework::Text result = "";
  32. bool ok = 1;
  33. if (Game::INSTANCE->zDimension(dimension))
  34. {
  35. auto block = Game::INSTANCE->zBlockAt(location, dimension, 0);
  36. if (block.isB())
  37. {
  38. result += "No block instance was created yet.\n";
  39. result += " Block Type: ";
  40. if (block.getB() == 0)
  41. {
  42. result += "[not loaded]";
  43. }
  44. else
  45. {
  46. result += Game::INSTANCE->zBlockType(block.getB())->getName();
  47. }
  48. result += " (";
  49. result += block.getB();
  50. result += ")\n";
  51. }
  52. else
  53. {
  54. Block* zBlock = block.getA();
  55. result.append()
  56. << "Block instance found.\n"
  57. << " Block Type: " << zBlock->zBlockType()->getName() << " ("
  58. << zBlock->zBlockType()->getId() << ")\n"
  59. << " HP: " << zBlock->getHP() << " / " << zBlock->getMaxHP()
  60. << "\n"
  61. << " Transparent: " << zBlock->isTransparent() << "\n"
  62. << " Passable: " << zBlock->isPassable() << "\n"
  63. << " Hardness: " << zBlock->getHardness() << "\n"
  64. << " Tick source: " << zBlock->isTickSource() << "\n"
  65. << " Interactable by hand: " << zBlock->isInteractable(0)
  66. << "\n"
  67. << " Light emission: ("
  68. << (int)zBlock->getLightEmisionColor()[0] << ", "
  69. << (int)zBlock->getLightEmisionColor()[1] << ", "
  70. << (int)zBlock->getLightEmisionColor()[2] << ")\n";
  71. }
  72. result += " Light data: ";
  73. Chunk* zChunk = Game::INSTANCE->zDimension(dimension)->zChunk(
  74. Game::getChunkCenter(x, y));
  75. if (zChunk)
  76. {
  77. unsigned char* light
  78. = zChunk->getLightData(Dimension::chunkCoordinates(location));
  79. result.append()
  80. << "(" << (int)light[0] << ", " << (int)light[1] << ", "
  81. << (int)light[2] << ", " << (int)light[3] << ", "
  82. << (int)light[4] << ", " << (int)light[5] << ")";
  83. }
  84. else
  85. {
  86. result += "[not loaded]";
  87. }
  88. result += "\n";
  89. for (int i = 0; i < 6; i++)
  90. {
  91. Framework::Vec3<int> pos
  92. = location + getDirection(getDirectionFromIndex(i));
  93. if (pos.z >= 0 && pos.z < WORLD_HEIGHT)
  94. {
  95. switch (i)
  96. {
  97. case 0:
  98. result += " North: ";
  99. break;
  100. case 1:
  101. result += " East: ";
  102. break;
  103. case 2:
  104. result += " South: ";
  105. break;
  106. case 3:
  107. result += " West: ";
  108. break;
  109. case 4:
  110. result += " Top: ";
  111. break;
  112. case 5:
  113. result += " Bottom: ";
  114. break;
  115. }
  116. zChunk = Game::INSTANCE->zDimension(dimension)->zChunk(
  117. Game::getChunkCenter(x, y));
  118. if (zChunk)
  119. {
  120. unsigned char* light = zChunk->getLightData(
  121. Dimension::chunkCoordinates(pos));
  122. result.append()
  123. << "(" << (int)light[0] << ", " << (int)light[1] << ", "
  124. << (int)light[2] << ", " << (int)light[3] << ", "
  125. << (int)light[4] << ", " << (int)light[5] << ")";
  126. }
  127. else
  128. {
  129. result += "[not loaded]";
  130. }
  131. result += "\n";
  132. }
  133. }
  134. }
  135. else
  136. {
  137. result += "Given dimension is not loaded";
  138. ok = 0;
  139. }
  140. if (zActor)
  141. {
  142. Game::INSTANCE->zChat()->sendMessageTo(
  143. result, zActor, Chat::CHANNEL_INFO);
  144. }
  145. else
  146. {
  147. Framework::Logging::info() << result;
  148. }
  149. return ok;
  150. }