Grass.cpp 2.3 KB

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