visuals.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. -- Minimal test entities to test visuals
  2. core.register_entity("testentities:sprite", {
  3. initial_properties = {
  4. visual = "sprite",
  5. textures = { "testentities_sprite.png" },
  6. },
  7. })
  8. core.register_entity("testentities:upright_sprite", {
  9. initial_properties = {
  10. visual = "upright_sprite",
  11. textures = {
  12. "testentities_upright_sprite1.png",
  13. "testentities_upright_sprite2.png",
  14. },
  15. },
  16. })
  17. core.register_entity("testentities:cube", {
  18. initial_properties = {
  19. visual = "cube",
  20. textures = {
  21. "testentities_cube1.png",
  22. "testentities_cube2.png",
  23. "testentities_cube3.png",
  24. "testentities_cube4.png",
  25. "testentities_cube5.png",
  26. "testentities_cube6.png",
  27. },
  28. },
  29. })
  30. core.register_entity("testentities:item", {
  31. initial_properties = {
  32. visual = "item",
  33. wield_item = "testnodes:normal",
  34. },
  35. })
  36. core.register_entity("testentities:wielditem", {
  37. initial_properties = {
  38. visual = "wielditem",
  39. wield_item = "testnodes:normal",
  40. },
  41. })
  42. core.register_entity("testentities:mesh", {
  43. initial_properties = {
  44. visual = "mesh",
  45. mesh = "testnodes_pyramid.obj",
  46. textures = {
  47. "testnodes_mesh_stripes2.png"
  48. },
  49. },
  50. })
  51. core.register_entity("testentities:mesh_unshaded", {
  52. initial_properties = {
  53. visual = "mesh",
  54. mesh = "testnodes_pyramid.obj",
  55. textures = {
  56. "testnodes_mesh_stripes2.png"
  57. },
  58. shaded = false,
  59. },
  60. })
  61. core.register_entity("testentities:sam", {
  62. initial_properties = {
  63. visual = "mesh",
  64. mesh = "testentities_sam.b3d",
  65. textures = {
  66. "testentities_sam.png"
  67. },
  68. },
  69. on_activate = function(self)
  70. self.object:set_animation({x = 0, y = 219}, 30, 0, true)
  71. end,
  72. })
  73. -- Advanced visual tests
  74. -- An entity for testing animated and yaw-modulated sprites
  75. core.register_entity("testentities:yawsprite", {
  76. initial_properties = {
  77. selectionbox = {-0.3, -0.5, -0.3, 0.3, 0.3, 0.3},
  78. visual = "sprite",
  79. visual_size = {x=0.6666, y=1},
  80. textures = {"testentities_dungeon_master.png^[makealpha:128,0,0^[makealpha:128,128,0"},
  81. spritediv = {x=6, y=5},
  82. initial_sprite_basepos = {x=0, y=0},
  83. },
  84. on_activate = function(self, staticdata)
  85. self.object:set_sprite({x=0, y=0}, 3, 0.5, true)
  86. end,
  87. })
  88. -- An entity for testing animated upright sprites
  89. core.register_entity("testentities:upright_animated", {
  90. initial_properties = {
  91. visual = "upright_sprite",
  92. textures = {"testnodes_anim.png"},
  93. spritediv = {x = 1, y = 4},
  94. },
  95. on_activate = function(self)
  96. self.object:set_sprite({x=0, y=0}, 4, 1.0, false)
  97. end,
  98. })
  99. core.register_entity("testentities:nametag", {
  100. initial_properties = {
  101. visual = "sprite",
  102. textures = { "testentities_sprite.png" },
  103. },
  104. on_activate = function(self, staticdata)
  105. if staticdata ~= "" then
  106. local data = core.deserialize(staticdata)
  107. self.color = data.color
  108. self.bgcolor = data.bgcolor
  109. else
  110. self.color = {
  111. r = math.random(0, 255),
  112. g = math.random(0, 255),
  113. b = math.random(0, 255),
  114. }
  115. if math.random(0, 10) > 5 then
  116. self.bgcolor = {
  117. r = math.random(0, 255),
  118. g = math.random(0, 255),
  119. b = math.random(0, 255),
  120. a = math.random(0, 255),
  121. }
  122. end
  123. end
  124. assert(self.color)
  125. self.object:set_properties({
  126. nametag = tostring(math.random(1000, 10000)),
  127. nametag_color = self.color,
  128. nametag_bgcolor = self.bgcolor,
  129. })
  130. end,
  131. get_staticdata = function(self)
  132. return core.serialize({ color = self.color, bgcolor = self.bgcolor })
  133. end,
  134. })