BlockInfoCommand.cpp 5.0 KB

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