harvest.txt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. event.load("block_break");
  2. event.load("block_drop");
  3. crops_tag = block.getTag("minecraft:crops");
  4. hoe_tag = item.getTag("km:hoe");
  5. auto_farm_set = set.new();
  6. set.add(auto_farm_set, "minecraft:wheat_seeds");
  7. set.add(auto_farm_set, "minecraft:carrot");
  8. set.add(auto_farm_set, "minecraft:potato");
  9. set.add(auto_farm_set, "minecraft:beetroot_seeds");
  10. auto_farm_set2 = set.new();
  11. set.add(auto_farm_set2, "minecraft:wheat");
  12. set.add(auto_farm_set2, "minecraft:carrots");
  13. set.add(auto_farm_set2, "minecraft:potatoes");
  14. set.add(auto_farm_set2, "minecraft:beetroots");
  15. msg("dev", "§bHarvest §rloaded.");
  16. @wait
  17. wait();
  18. if(event == "block_drop") {
  19. loc = location;
  20. } else {
  21. loc = entity.getLocation(player);
  22. }
  23. world_name = world.getName(loc.getWorld(loc));
  24. if(world.isSurvName(world_name)) {
  25. ignoreGoto(event);
  26. }
  27. goto("wait");
  28. @block_break
  29. if(!block.hasTag(crops_tag, block)) {
  30. goto("wait");
  31. }
  32. block_type = block.getType(block_loc);
  33. if(!set.contains(auto_farm_set2, block_type)) {
  34. goto("wait");
  35. }
  36. item = living.getEquip(player, "hand");
  37. if(!item.hasTag(hoe_tag, item)) {
  38. item = living.getEquip(player, "offhand");
  39. if(!item.hasTag(hoe_tag, item)) {
  40. goto("wait");
  41. }
  42. }
  43. cancel = false;
  44. goto("wait");
  45. @block_drop
  46. if(!isPlayer(entity)) {
  47. goto("wait");
  48. }
  49. player = entity;
  50. if(item == null) {
  51. goto("wait");
  52. }
  53. if(!block.hasTag(crops_tag, block)) {
  54. goto("wait");
  55. }
  56. if(!item.hasTag(hoe_tag, item)) {
  57. goto("wait");
  58. }
  59. for(i = 0; i < list.getSize(drops); i++) {
  60. drop_item = list.getIndex(drops, i);
  61. if(set.contains(auto_farm_set, item.getType(drop_item))) {
  62. amount = item.getAmount(drop_item);
  63. if(amount > 0) {
  64. item.setAmount(drop_item, amount - 1);
  65. }
  66. }
  67. }
  68. block.set(location, concat(block_type, "[age=0]"));
  69. player.damageItem(player, 1);
  70. goto("wait");