BlockInfoCommand.cpp 4.9 KB

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