Grass.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "Grass.h"
  2. #include "Game.h"
  3. #include "ItemEntity.h"
  4. GrassBlock::GrassBlock(int typeId, Framework::Vec3<int> pos, int dimensionId)
  5. : AdditionalItemSpawningBlock(typeId, pos, dimensionId)
  6. {
  7. transparent = 1;
  8. }
  9. bool GrassBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
  10. {
  11. // TODO: spread to neighbor blocks if light level is hight enought
  12. return 0;
  13. }
  14. void GrassBlock::onPostTick() {}
  15. void GrassBlock::filterPassingLight(unsigned char rgb[3]) const
  16. {
  17. rgb[0] = (unsigned char)(rgb[0] * 0.7);
  18. rgb[1] = (unsigned char)(rgb[1] * 0.9);
  19. rgb[2] = (unsigned char)(rgb[2] * 0.7);
  20. }
  21. TickSourceType GrassBlock::isTickSource() const
  22. {
  23. return TickSourceType::EACH_TICK;
  24. }
  25. GrassBlockType::GrassBlockType()
  26. : AdditionalItemSpawningBlockType()
  27. {}
  28. ItemType* GrassBlockType::createItemType() const
  29. {
  30. return 0;
  31. }
  32. void GrassBlockType::createSuperBlock(Block* zBlock, Item* zItem) const
  33. {
  34. AdditionalItemSpawningBlockType::createSuperBlock(zBlock, zItem);
  35. }
  36. void GrassBlockType::loadSuperBlock(
  37. Block* zBlock, Framework::StreamReader* zReader, int dimensionId) const
  38. {
  39. AdditionalItemSpawningBlockType::loadSuperBlock(
  40. zBlock, zReader, dimensionId);
  41. }
  42. void GrassBlockType::saveSuperBlock(
  43. Block* zBlock, Framework::StreamWriter* zWriter) const
  44. {
  45. AdditionalItemSpawningBlockType::saveSuperBlock(zBlock, zWriter);
  46. }
  47. Item* GrassBlockType::createItem() const
  48. {
  49. return 0;
  50. }
  51. Block* GrassBlockType::createBlock(
  52. Framework::Vec3<int> position, int dimensionId) const
  53. {
  54. return new GrassBlock(getId(), position, dimensionId);
  55. }
  56. GrassBlockTypeFactory::GrassBlockTypeFactory()
  57. : SubTypeFactory()
  58. {}
  59. GrassBlockType* GrassBlockTypeFactory::createValue(
  60. Framework::JSON::JSONObject* zJson) const
  61. {
  62. return new GrassBlockType();
  63. }
  64. void GrassBlockTypeFactory::fromJson(
  65. GrassBlockType* zResult, Framework::JSON::JSONObject* zJson) const
  66. {
  67. super.fromJson(zResult, zJson);
  68. }
  69. void GrassBlockTypeFactory::toJson(
  70. GrassBlockType* zObject, Framework::JSON::JSONObject* zResult) const
  71. {
  72. super.toJson(zObject, zResult);
  73. }
  74. JSONObjectValidationBuilder* GrassBlockTypeFactory::addToValidator(
  75. JSONObjectValidationBuilder* builder) const
  76. {
  77. return super.addToValidator(builder);
  78. }
  79. Framework::Text GrassBlockTypeFactory::getTypeToken() const
  80. {
  81. return "grass";
  82. }