BlockInfoCommand.cpp 4.9 KB

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