lectern.txt 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. event.load("player_toss");
  2. event.load("block_click");
  3. par = particle.get("minecraft:witch");
  4. prefix_money = "§2Money";
  5. prefix_commands = "§6Commands";
  6. max_ench_lvl = map.new();
  7. map.add(max_ench_lvl, enchantment.get("efficiency"), 10);
  8. map.add(max_ench_lvl, enchantment.get("smite"), 10);
  9. map.add(max_ench_lvl, enchantment.get("bane_of_arthropods"), 10);
  10. map.add(max_ench_lvl, enchantment.get("loyalty"), 5);
  11. map.add(max_ench_lvl, enchantment.get("piercing"), 5);
  12. map.add(max_ench_lvl, enchantment.get("lure"), 5);
  13. map.add(max_ench_lvl, enchantment.get("luck_of_the_sea"), 5);
  14. map.add(max_ench_lvl, enchantment.get("riptide"), 5);
  15. map.add(max_ench_lvl, enchantment.get("unbreaking"), 5);
  16. map.add(max_ench_lvl, enchantment.get("quick_charge"), 5);
  17. map.add(max_ench_lvl, enchantment.get("protection"), 5);
  18. map.add(max_ench_lvl, enchantment.get("fire_protection"), 5);
  19. map.add(max_ench_lvl, enchantment.get("blast_protection"), 5);
  20. map.add(max_ench_lvl, enchantment.get("projectile_protection"), 5);
  21. map.add(max_ench_lvl, enchantment.get("feather_falling"), 5);
  22. map.add(max_ench_lvl, enchantment.get("respiration"), 5);
  23. map.add(max_ench_lvl, enchantment.get("thorns"), 5);
  24. map.add(max_ench_lvl, enchantment.get("depth_strider"), 5);
  25. map.add(max_ench_lvl, enchantment.get("frost_walker"), 2);
  26. map.add(max_ench_lvl, enchantment.get("soul_speed"), 3);
  27. map.add(max_ench_lvl, enchantment.get("sharpness"), 10);
  28. map.add(max_ench_lvl, enchantment.get("knockback"), 5);
  29. map.add(max_ench_lvl, enchantment.get("fire_aspect"), 2);
  30. map.add(max_ench_lvl, enchantment.get("looting"), 5);
  31. map.add(max_ench_lvl, enchantment.get("sweeping"), 5);
  32. map.add(max_ench_lvl, enchantment.get("power"), 5);
  33. map.add(max_ench_lvl, enchantment.get("punch"), 5);
  34. map.add(max_ench_lvl, enchantment.get("impaling"), 5);
  35. map.add(max_ench_lvl, enchantment.get("fortune"), 5);
  36. msg("dev", "§bLectern §rloaded.");
  37. @wait
  38. wait();
  39. loc = entity.getLocation(player);
  40. world_name = world.getName(loc.getWorld(loc));
  41. ignoreGoto(event);
  42. goto("wait");
  43. @player_toss
  44. target_loc = player.getTarget(player, 5);
  45. block_type = block.getType(target_loc);
  46. if(block_type == "minecraft:lectern") {
  47. cancel = true;
  48. item.entity.spawn(item.entity.new(loc.mod(target_loc, 0.5, 1.5, 0.5), item));
  49. }
  50. goto("wait");
  51. @block_click
  52. if(hand == "OFF_HAND") {
  53. goto("wait");
  54. }
  55. if(action == "left") {
  56. goto("wait");
  57. }
  58. if(block_type != "minecraft:lectern") {
  59. goto("wait");
  60. }
  61. itementity = entity.get(loc.mod(block_loc, 0.5, 0.9, 0.5), 0.2, "net.minecraft.entity.item.ItemEntity");
  62. if(itementity == null) {
  63. goto("wait");
  64. }
  65. list = entity.near(itementity, 0.2);
  66. list.add(list, itementity);
  67. temp_list = list.new();
  68. for(i = 0; i < list.getSize(list); i++) {
  69. entity = list.getIndex(list, i);
  70. if(entity.getType(entity) != "item") {
  71. list.add(temp_list, entity);
  72. }
  73. }
  74. for(i = 0; i < list.getSize(temp_list); i++) {
  75. entity = list.getIndex(temp_list, i);
  76. list.remove(list, entity);
  77. }
  78. if(list.getSize(list) < 2) {
  79. msg.prefix(player, prefix_commands, "Too few items on lectern.");
  80. goto("wait");
  81. }
  82. a = array.new(2, 6); //0 = item, 1 = itementity, 2 = enchantments, 3 = enchanted, 4 = enchanted_book, 5 = book
  83. size = 0;
  84. for(i = 0; i < list.getSize(list); i++) {
  85. entity = list.getIndex(list, i);
  86. item = item.entity.get(entity);
  87. size += item.getAmount(item);
  88. if(size > 2) {
  89. msg.prefix(player, prefix_commands, "Too many items on lectern.");
  90. goto("wait");
  91. }
  92. map = enchantment.readFromItem(item);
  93. a[i, 0] = item;
  94. a[i, 1] = entity;
  95. a[i, 2] = map;
  96. a[i, 4] = false;
  97. a[i, 5] = false;
  98. if(map.getSize(map) > 0) {
  99. //Verzauberte Items
  100. a[i, 3] = true;
  101. if(item.getType(item) == "minecraft:enchanted_book") {
  102. a[i, 4] = true;
  103. }
  104. } else {
  105. //Nicht verzauberte Items
  106. a[i, 3] = false;
  107. if(item.getType(item) == "minecraft:book") {
  108. a[i, 5] = true;
  109. }
  110. }
  111. }
  112. lectern_action = null;
  113. if(a[0, 4] == true && a[1, 4] == true) {
  114. //Beide Items sind verzauberte Bücher
  115. lectern_action = 0;
  116. }
  117. elseif(a[0, 5] == true || a[1, 5] == true) {
  118. //Eines der beiden Items ist ein normales Buch
  119. if(a[0, 4] == true || a[1, 4] == true) {
  120. //Eines der beiden Items ist ein verzaubertes Buch
  121. lectern_action = 1;
  122. } elseif(a[0, 3] == true || a[1, 3] == true) {
  123. //Eines der beiden Items ist ein verzaubertes Item
  124. lectern_action = 2;
  125. }
  126. }
  127. elseif(a[0, 4] == true || a[1, 4] == true) {
  128. lectern_action = 3;
  129. }
  130. if(lectern_action == null) {
  131. goto("wait");
  132. }
  133. if(lectern_action == 0) {
  134. //Verzauberungsbücher mergen
  135. item1 = a[0, 0];
  136. item_entity1 = a[0, 1];
  137. item_entity2 = a[1, 1];
  138. map1 = a[0, 2];
  139. map2 = a[1, 2];
  140. map_size1 = map.getSize(map1);
  141. map_size2 = map.getSize(map2);
  142. iter = map.iterator(map2);
  143. betrag = 0;
  144. extra = 0;
  145. while(hasNext(iter)) {
  146. element = next(iter);
  147. key = map.getKey(element);
  148. level1 = map.getValue(element);
  149. level2 = map.getOrDefault(map1, key, 0);
  150. if(level1 == level2) {
  151. max_lvl = map.get(max_ench_lvl, key);
  152. //max_lvl = map.getOrDefault(max_ench_lvl, key, enchantment.getMaxLevel(key));
  153. if(max_lvl == null) {
  154. msg.prefix(player, prefix_commands, "Unknown enchantment.");
  155. goto("wait");
  156. }
  157. if(level1 >= max_lvl) {
  158. msg.prefix(player, prefix_commands, "Maximum level already reached.");
  159. goto("wait");
  160. }
  161. extra += 200;
  162. level1++;
  163. }
  164. if(level2 > level1) {
  165. level1 = level2;
  166. }
  167. map.add(map1, key, level1);
  168. }
  169. if(map_size1 > map_size2) {
  170. map = map1;
  171. } else {
  172. map = map2;
  173. }
  174. iter = map.iterator(map);
  175. while(hasNext(iter)) {
  176. element = next(iter);
  177. level = map.getValue(element);
  178. betrag += level * 100 + extra;
  179. }
  180. if(!world.isCreativeName(world_name)) {
  181. if(!hasEnoughMoney(player.getId(player), betrag)) {
  182. msg.prefix(player, prefix_money, concat("Not enough snuvis in inventory. This action costs ", text.number(betrag), " snuvis."));
  183. goto("wait");
  184. }
  185. subMoney(player, betrag);
  186. }
  187. enchantment.writeToItem(map1, item1);
  188. item.entity.set(item_entity1, item.clone(item1));
  189. entity.remove(item_entity2);
  190. } elseif(lectern_action == 1) {
  191. //Verzauberungsbuch kopieren
  192. if(a[0, 5]) {
  193. book_index = 0;
  194. other_index = 1;
  195. } else {
  196. book_index = 1;
  197. other_index = 0;
  198. }
  199. item1 = a[book_index, 0];
  200. item_entity1 = a[book_index, 1];
  201. item2 = a[other_index, 0];
  202. item_entity2 = a[other_index, 1];
  203. map2 = a[other_index, 2];
  204. map_size = map.getSize(map2);
  205. betrag = 100 * map_size;
  206. if(!world.isCreativeName(world_name)) {
  207. if(!hasEnoughMoney(player.getId(player), betrag)) {
  208. msg.prefix(player, prefix_money, concat("Not enough snuvis on your account. This action costs ", text.number(betrag), " snuvis."));
  209. goto("wait");
  210. }
  211. subMoney(player, betrag);
  212. }
  213. item1 = read.item("minecraft:enchanted_book");
  214. enchantment.writeToItem(map2, item1);
  215. item.entity.set(item_entity1, item1);
  216. item.entity.set(item_entity2, item.clone(item2));
  217. } elseif(lectern_action == 2) {
  218. //Einzelne Verzauberung herunterziehen
  219. if(a[0, 5]) {
  220. book_index = 0;
  221. other_index = 1;
  222. } else {
  223. book_index = 1;
  224. other_index = 0;
  225. }
  226. item_entity1 = a[book_index, 1];
  227. map1 = map.new();
  228. item2 = a[other_index, 0];
  229. item_entity2 = a[other_index, 1];
  230. map2 = a[other_index, 2];
  231. item1 = read.item("minecraft:enchanted_book");
  232. element = next(map.iterator(map2));
  233. key = map.getKey(element);
  234. value = map.getValue(element);
  235. map.add(map1, key, value);
  236. map.remove(map2, key);
  237. betrag = 100 * value;
  238. if(!world.isCreativeName(world_name)) {
  239. if(!hasEnoughMoney(player.getId(player), betrag)) {
  240. msg.prefix(player, prefix_money, concat("Not enough snuvis in your ccount. This action costs ", text.number(betrag), " snuvis."));
  241. goto("wait");
  242. }
  243. subMoney(player, betrag);
  244. }
  245. enchantment.writeToItem(map1, item1);
  246. enchantment.writeToItem(map2, item2);
  247. item.entity.set(item_entity1, item1);
  248. item.entity.set(item_entity2, item.clone(item2));
  249. } elseif(lectern_action == 3) {
  250. //Alle Verzauberungen vom Buch auf das Item übertragen
  251. betrag = 0;
  252. if(a[0, 4]) {
  253. ench_book_index = 0;
  254. other_index = 1;
  255. } else {
  256. ench_book_index = 1;
  257. other_index = 0;
  258. }
  259. item1 = a[ench_book_index, 0];
  260. item_entity1 = a[ench_book_index, 1];
  261. map1 = a[ench_book_index, 2];
  262. item2 = a[other_index, 0];
  263. item_entity2 = a[other_index, 1];
  264. map2 = a[other_index, 2];
  265. map_size1 = map.getSize(map1);
  266. map_size2 = map.getSize(map2);
  267. iter = map.iterator(map1);
  268. while(hasNext(iter)) {
  269. element = next(iter);
  270. key = map.getKey(element);
  271. value = map.getValue(element);
  272. value2 = map.getOrDefault(map2, key, 0);
  273. if(value2 > value) {
  274. value = value2;
  275. }
  276. map.add(map2, key, value);
  277. }
  278. if(map_size1 > map_size2) {
  279. map = map1;
  280. } else {
  281. map = map2;
  282. }
  283. iter = map.iterator(map);
  284. while(hasNext(iter)) {
  285. element = next(iter);
  286. level = map.getValue(element);
  287. betrag += level * 100;
  288. }
  289. if(!world.isCreativeName(world_name)) {
  290. if(!hasEnoughMoney(player.getId(player), betrag)) {
  291. msg.prefix(player, prefix_money, concat("Not enough snuvis on your account. This action costs ", text.number(betrag), " snuvis."));
  292. goto("wait");
  293. }
  294. subMoney(player, betrag);
  295. }
  296. enchantment.writeToItem(map2, item2);
  297. item.entity.set(item_entity2, item.clone(item2));
  298. entity.remove(item_entity1);
  299. }
  300. entity.throw(item_entity1, 0, 0.3, 0);
  301. entity.throw(item_entity2, 0, 0.3, 0);
  302. particle.spawn(loc.mod(block_loc, 0.5, 1.4, 0.5), par, 20, 0, 0.25, 0.25, 0.25);
  303. msg.prefix(player, prefix_money, concat("This cost " , text.number(betrag), " snuvis."));
  304. goto("wait");