loom.txt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. event.load("player_toss");
  2. wool_tag = item.getTag("minecraft:wool");
  3. par = particle.get("minecraft:witch");
  4. counter_map = map.new();
  5. loom_list = list.new();
  6. msg("dev", "§bLoom §rloaded.");
  7. @wait
  8. wait();
  9. if(event == "player_toss") {
  10. target_loc = player.getTarget(player, 5);
  11. block_type = block.getType(target_loc);
  12. if(block_type == "minecraft:loom") {
  13. if(!item.hasTag(wool_tag, item) && item.getType(item) != "km:coarse_cloth") {
  14. goto("wait");
  15. }
  16. cancel = true;
  17. spawn_loc = loc.mod(target_loc, 0.5, 1.5, 0.5);
  18. loom_loc = loc.mod(target_loc, 0.5, 1, 0.5);
  19. item_entity = item.entity.new(spawn_loc, item);
  20. item.entity.spawn(item_entity);
  21. loom_id = map.getOrDefault(counter_map, loom_loc, 0) + 1;
  22. map.add(counter_map, loom_loc, loom_id);
  23. a = array.new(3);
  24. a[0] = loom_id;
  25. a[1] = player.getUuid(player);
  26. a[2] = loom_loc;
  27. list.add(loom_list, a);
  28. sgoto(40, "loom");
  29. }
  30. }
  31. goto("wait");
  32. @loom
  33. a = list.getIndex(loom_list, 0);
  34. list.removeIndex(loom_list, 0);
  35. loom_id = a[0];
  36. player_uuid = a[1];
  37. loom_loc = a[2];
  38. player = player.get(player_uuid);
  39. if(player == null) {
  40. goto("wait");
  41. }
  42. loc_loom_id = map.get(counter_map, loom_loc);
  43. if(loc_loom_id != loom_id) {
  44. goto("wait");
  45. }
  46. wool_amount = 0;
  47. wool_item = null;
  48. wool_item_entity = null;
  49. coarse_amount = 0;
  50. coarse_item = null;
  51. coarse_item_entity = null;
  52. list = entity.near(loom_loc, 0.05);
  53. iter = iterator(list);
  54. while(hasNext(iter)) {
  55. item_entity = next(iter);
  56. item = item.entity.get(item_entity);
  57. type = item.getType(item);
  58. amount = item.getAmount(item);
  59. if(item.hasTag(wool_tag, item)) {
  60. wool_amount = amount;
  61. wool_item = item;
  62. wool_item_entity = item_entity;
  63. continue;
  64. }
  65. if(type == "km:coarse_cloth") {
  66. coarse_amount = amount;
  67. coarse_item = item;
  68. coarse_item_entity = item_entity;
  69. continue;
  70. }
  71. }
  72. if(wool_amount == 0) {
  73. goto("wait");
  74. }
  75. if(coarse_amount == 0) {
  76. //only wool to coarse
  77. amount = item.getAmount(wool_item);
  78. output_item = read.item("km:coarse_cloth");
  79. item.setAmount(output_item, amount);
  80. item.entity.set(wool_item_entity, output_item);
  81. entity.throw(wool_item_entity, 0, 0.3, 0);
  82. particle.spawn(loc.mod(loom_loc, 0.5, 1.4, 0.5), par, 20, 0, 0.25, 0.25, 0.25);
  83. loomEvent(player, loom_loc, wool_item_entity);
  84. goto("wait");
  85. }
  86. //wool and coarse to cloth
  87. if(coarse_amount > wool_amount) {
  88. amount = wool_amount;
  89. wool_amount = 0;
  90. coarse_amount -= amount;
  91. } else {
  92. amount = coarse_amount;
  93. coarse_amount = 0;
  94. wool_amount -= amount;
  95. }
  96. item.setAmount(coarse_item, coarse_amount);
  97. item.setAmount(wool_item, wool_amount);
  98. item.entity.set(coarse_item_entity, coarse_item);
  99. item.entity.set(wool_item_entity, wool_item);
  100. output_item = read.item("km:cloth");
  101. item.setAmount(output_item, amount);
  102. output_item_entity = item.entity.new(loom_loc, output_item);
  103. item.entity.spawn(output_item_entity);
  104. entity.throw(output_item_entity, 0, 0.2, 0);
  105. particle.spawn(loc.mod(loom_loc, 0.5, 1.4, 0.5), par, 20, 0, 0.25, 0.25, 0.25);
  106. loomEvent(player, loom_loc, output_item_entity);
  107. goto("wait");
  108. function loomEvent(player, loom_loc, entity) {
  109. setScriptVar("player", player);
  110. setScriptVar("loom_loc", loom_loc);
  111. setScriptVar("entity", entity);
  112. script.callEvent("player_loom_finish");
  113. }