Grass.cpp 2.3 KB

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