BlockInfoCommand.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. void 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. if (Game::INSTANCE->zDimension(dimension))
  33. {
  34. auto block = Game::INSTANCE->zBlockAt(location, dimension);
  35. if (block.isB())
  36. {
  37. result += "No block instance was created yet.\n";
  38. result += " Block Type: ";
  39. if (block.getB() == 0)
  40. {
  41. result += "[not loaded]";
  42. }
  43. else
  44. {
  45. result += Game::INSTANCE->zBlockType(block.getB())->getName();
  46. }
  47. result += " (";
  48. result += block.getB();
  49. result += ")\n";
  50. }
  51. else
  52. {
  53. Block* zBlock = block.getA();
  54. result.append()
  55. << "Block instance found.\n"
  56. << " Block Type: " << zBlock->zBlockType()->getName() << " ("
  57. << zBlock->zBlockType()->getId() << ")\n"
  58. << " HP: " << zBlock->getHP() << " / " << zBlock->getMaxHP()
  59. << "\n"
  60. << " Transparent: " << zBlock->isTransparent() << "\n"
  61. << " Passable: " << zBlock->isPassable() << "\n"
  62. << " Hardness: " << zBlock->getHardness() << "\n"
  63. << " Tick source: " << zBlock->isTickSource() << "\n"
  64. << " Interactable by hand: " << zBlock->isInteractable(0)
  65. << "\n"
  66. << " Light emission: ("
  67. << (int)zBlock->getLightEmisionColor()[0] << ", "
  68. << (int)zBlock->getLightEmisionColor()[1] << ", "
  69. << (int)zBlock->getLightEmisionColor()[2] << ")\n";
  70. }
  71. result += " Light data: ";
  72. Chunk* zChunk = Game::INSTANCE->zDimension(dimension)->zChunk(
  73. Game::getChunkCenter(x, y));
  74. if (zChunk)
  75. {
  76. unsigned char* light
  77. = zChunk->getLightData(Dimension::chunkCoordinates(location));
  78. result.append()
  79. << "(" << (int)light[0] << ", " << (int)light[1] << ", "
  80. << (int)light[2] << ", " << (int)light[3] << ", "
  81. << (int)light[4] << ", " << (int)light[5] << ")";
  82. }
  83. else
  84. {
  85. result += "[not loaded]";
  86. }
  87. result += "\n";
  88. for (int i = 0; i < 6; i++)
  89. {
  90. Framework::Vec3<int> pos
  91. = location + getDirection(getDirectionFromIndex(i));
  92. if (pos.z >= 0 && pos.z < WORLD_HEIGHT)
  93. {
  94. switch (i)
  95. {
  96. case 0:
  97. result += " North: ";
  98. break;
  99. case 1:
  100. result += " East: ";
  101. break;
  102. case 2:
  103. result += " South: ";
  104. break;
  105. case 3:
  106. result += " West: ";
  107. break;
  108. case 4:
  109. result += " Top: ";
  110. break;
  111. case 5:
  112. result += " Bottom: ";
  113. break;
  114. }
  115. zChunk = Game::INSTANCE->zDimension(dimension)->zChunk(
  116. Game::getChunkCenter(x, y));
  117. if (zChunk)
  118. {
  119. unsigned char* light = zChunk->getLightData(
  120. Dimension::chunkCoordinates(pos));
  121. result.append()
  122. << "(" << (int)light[0] << ", " << (int)light[1] << ", "
  123. << (int)light[2] << ", " << (int)light[3] << ", "
  124. << (int)light[4] << ", " << (int)light[5] << ")";
  125. }
  126. else
  127. {
  128. result += "[not loaded]";
  129. }
  130. result += "\n";
  131. }
  132. }
  133. }
  134. else
  135. {
  136. result += "Given dimension is not loaded";
  137. }
  138. if (zActor)
  139. {
  140. Game::INSTANCE->zChat()->sendMessageTo(
  141. result, zActor, Chat::CHANNEL_INFO);
  142. }
  143. else
  144. {
  145. Framework::Logging::info() << result;
  146. }
  147. }