loom.txt 3.4 KB

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