123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- event.load("block_break");
- prop_persistent = block.getProperty("persistent");
- tag_log_burn = block.getTag("minecraft:logs_that_burn");
- axe_tag = item.getTag("km:axe");
- horizontal_dist_map = map.new();
- map.add(horizontal_dist_map, "minecraft:oak_log", 9);
- map.add(horizontal_dist_map, "minecraft:spruce_log", 8);
- map.add(horizontal_dist_map, "minecraft:birch_log", 2);
- map.add(horizontal_dist_map, "minecraft:jungle_log", 12);
- map.add(horizontal_dist_map, "minecraft:acacia_log", 9);
- map.add(horizontal_dist_map, "minecraft:dark_oak_log", 6);
- msg("dev", "§bTimber §rloaded.");
- @wait
- wait();
- if(event == "block_break") {
- if(cancel) {
- goto("wait");
- }
- duration = data.getTimer(player, "timber");
- if(duration < 0) {
- goto("wait");
- }
- if(!player.checkHandsForTag(player, axe_tag)) {
- goto("wait");
- }
- tree_type = block_type;
- horizontal_spec_dist = map.getOrDefault(horizontal_dist_map, tree_type, 2);
- origin_x = loc.getX(block_loc);
- origin_z = loc.getZ(block_loc);
- if(block.isTree(block_loc)) {
- block.removeTree(block_loc);
- }
- }
- goto("wait");
- function block.isTree(break_loc) {
- block = block.get(break_loc);
- if(!block.hasTag($tag_log_burn, block)) {
- return false;
- }
- //neighbours on same level found? return false
- mod_loc = loc.mod(break_loc, 1, 0, 0);
- if(block.getType(mod_loc) == $tree_type) {
- return false;
- }
- loc.add(mod_loc, -2, 0, 0);
- if(block.getType(mod_loc) == $tree_type) {
- return false;
- }
- loc.add(mod_loc, 1, 0, 1);
- if(block.getType(mod_loc) == $tree_type) {
- return false;
- }
- loc.add(mod_loc, 0, 0, -2);
- if(block.getType(mod_loc) == $tree_type) {
- return false;
- }
- loc.add(mod_loc, 0, 0, 1);
- //search top logs
- while(block.getType(mod_loc) == $tree_type) {
- loc.add(mod_loc, 0, 1, 0);
- }
- state = block.property.getValue(mod_loc, $prop_persistent);
- if(state == null || state) {
- if($tree_type == "minecraft:acacia_log") {
- for(i = 0; i < 5; i++) {
- state = block.property.getValue(mod_loc, $prop_persistent);
- if(state != null && !state) {
- return true;
- }
- mod_loc = loc.mod(mod_loc, 0, 1, 0);
- }
- }
- return false;
- }
- return true;
- }
- function block.removeTree(break_loc) {
- c = 0;
- $tree_list = list.new();
- $tree_set = set.new();
- list.add($tree_list, break_loc);
- while(list.getSize($tree_list) != 0) {
- index = list.getSize($tree_list) - 1;
- loc = list.getIndex($tree_list, index);
- list.removeIndex($tree_list, index);
- mod_loc = loc.mod(loc, 1, 0, 0);
- block.addIfTreePart(mod_loc);
- mod_loc = loc.mod(mod_loc, -2, 0, 0);
- block.addIfTreePart(mod_loc);
- mod_loc = loc.mod(mod_loc, 1, 0, 1);
- block.addIfTreePart(mod_loc);
- mod_loc = loc.mod(mod_loc, 0, 0, -2);
- block.addIfTreePart(mod_loc);
- mod_loc = loc.mod(mod_loc, 0, 1, 1);
- block.addIfTreePart(mod_loc);
- if($tree_type == "minecraft:acacia_log") {
- mod_loc = loc.mod(mod_loc, 1, 0, 0);
- block.addIfTreePart(mod_loc);
- mod_loc = loc.mod(mod_loc, -2, 0, 0);
- block.addIfTreePart(mod_loc);
- mod_loc = loc.mod(mod_loc, 1, 0, 1);
- block.addIfTreePart(mod_loc);
- mod_loc = loc.mod(mod_loc, 0, 0, -2);
- block.addIfTreePart(mod_loc);
- }
- if($tree_type == "minecraft:dark_oak_log") {
- mod_loc = loc.mod(mod_loc, 1, 0, 1);
- block.addIfLog(mod_loc);
- mod_loc = loc.mod(mod_loc, -2, 0, 0);
- block.addIfLog(mod_loc);
- mod_loc = loc.mod(mod_loc, 0, 0, -2);
- block.addIfLog(mod_loc);
- mod_loc = loc.mod(mod_loc, 2, 0, 0);
- block.addIfLog(mod_loc);
- }
- c++;
- if(c > 1000) {
- break;
- }
- }
- return;
- }
- function block.addIfLog(location) {
- if(block.isLog(location)) {
- block.addTreePart(location);
- }
- }
- function block.isLog(location) {
- horizontal_dist = math.abs($origin_x - loc.getX(location));
- if(horizontal_dist > $horizontal_spec_dist) {
- return false;
- }
- horizontal_dist = math.abs($origin_z - loc.getZ(location));
- if(horizontal_dist > $horizontal_spec_dist) {
- return false;
- }
- temp_type = block.getType(location);
- if(temp_type == $tree_type) {
- return true;
- }
- set.add($tree_set, location);
- return false;
- }
- function block.addIfTreePart(location) {
- if(block.isTreePart(location)) {
- block.addTreePart(location);
- }
- }
- function block.isTreePart(location) {
- horizontal_dist = math.abs($origin_x - loc.getX(location));
- if(horizontal_dist > $horizontal_spec_dist) {
- return false;
- }
- horizontal_dist = math.abs($origin_z - loc.getZ(location));
- if(horizontal_dist > $horizontal_spec_dist) {
- return false;
- }
- temp_type = block.getType(location);
- if(temp_type == $tree_type) {
- return true;
- }
- if(temp_type == "minecraft:vine") {
- return true;
- }
- state = block.property.getValue(location, $prop_persistent);
- if(state != null && !state) {
- return true;
- }
- set.add($tree_set, location);
- return false;
- }
- function block.addTreePart(location) {
- if(!set.contains($tree_set, location)) {
- list.add($tree_list, location);
- set.add($tree_set, location);
- block.break(location, player);
- }
- }
|