cobweb_test.txt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. event.load("block_break");
  2. cobweb_radius = 1;
  3. sword = item.getTag("km:sword");
  4. msg("dev", "§bCobwebs §rloaded.");
  5. @wait
  6. wait();
  7. if(cancel) {
  8. goto("wait");
  9. }
  10. if(block_type != "minecraft:cobweb"){
  11. goto("wait");
  12. }
  13. equip = living.getEquip(player, "hand");
  14. if(!item.hasTag(sword, equip)){
  15. goto("wait");
  16. }
  17. cobweb_X = loc.getX(block_loc);
  18. cobweb_Y = loc.getY(block_loc);
  19. cobweb_Z = loc.getZ(block_loc);
  20. unbreaking_level = enchantment.getLevel(enchantment.get("unbreaking"), equip);
  21. location = block_loc;
  22. for(a = -cobweb_radius; a < cobweb_radius+1; a++){
  23. loc.setX(location, cobweb_X + a);
  24. for(b = -cobweb_radius; b < cobweb_radius+1; b++){
  25. loc.setY(location, cobweb_Y + b);
  26. for(c = -cobweb_radius; c < cobweb_radius+1; c++){
  27. loc.setZ(location, cobweb_Z + c);
  28. if(math.abs(a)+math.abs(b)+math.abs(c)+math.random(0,2) < cobweb_radius+2){
  29. shear(location,block_type,player,unbreaking_level);
  30. }
  31. }
  32. }
  33. }
  34. goto("wait");
  35. function shear(block_loc,original_block_type,player,unbreaking_level){
  36. if(block.getType(block_loc) == original_block_type){
  37. block.break(block_loc, player);
  38. if(math.random(0,99) < 100/(unbreaking_level+1)){
  39. player.damageItem(player, 1);
  40. }
  41. }
  42. }