shears_test.txt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. event.load("block_break");
  2. //radius = 1;
  3. msg("dev", "§bShears §rloaded.");
  4. @wait
  5. wait();
  6. if(cancel) {
  7. goto("wait");
  8. }
  9. if(!text.contains(block_type, "leaves")){
  10. goto("wait");
  11. }
  12. if(item.getType(living.getEquip(player, "hand")) != "minecraft:shears"){
  13. goto("wait");
  14. }
  15. if(block.property.getValue(block_loc, block.getProperty("persistent"))){
  16. goto("wait");
  17. }
  18. shears_X = loc.getX(block_loc);
  19. shears_Y = loc.getY(block_loc);
  20. shears_Z = loc.getZ(block_loc);
  21. unbreaking_level = enchantment.getLevel(enchantment.get("unbreaking"), living.getEquip(player, "hand"));
  22. radius = enchantment.getLevel(enchantment.get("sharpness"), living.getEquip(player, "hand"));
  23. if(radius > 0){
  24. cancel = true;
  25. }
  26. location = block_loc;
  27. for(a = -radius; a < radius+1; a++){
  28. loc.setX(location, shears_X + a);
  29. for(b = -radius; b < radius+1; b++){
  30. loc.setY(location, shears_Y + b);
  31. for(c = -radius; c < radius+1; c++){
  32. loc.setZ(location, shears_Z + c);
  33. if(math.abs(a)+math.abs(b)+math.abs(c)+math.random(0,2) < radius+2){
  34. shear(location,block_type,player,unbreaking_level);
  35. }
  36. }
  37. }
  38. }
  39. goto("wait");
  40. function shear(block_loc,original_block_type,player,unbreaking_level){
  41. if(block.getType(block_loc) == original_block_type){
  42. if(!block.property.getValue(block_loc, block.getProperty("persistent"))){
  43. block.set(block_loc, "minecraft:air");
  44. item.drop(block_loc, read.item(original_block_type,1));
  45. if(player.isSurvival(player)){
  46. if(math.random(0,99) < 100/(unbreaking_level+1)){
  47. player.damageItem(player, 1);
  48. }
  49. }
  50. }
  51. }
  52. }