From aec057c89cdf0b2debcebb815c2543689dcd8fd0 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 28 Apr 2021 07:12:30 +0000 Subject: [PATCH] Use our own hypot() for older Python support --- mosfet/commands.py | 1 - mosfet/game.py | 1 - mosfet/job.py | 1 - mosfet/jobs/cache_items.py | 2 +- mosfet/jobs/check_threats.py | 2 +- mosfet/jobs/clear_leaves.py | 2 +- mosfet/jobs/eat_food.py | 2 +- mosfet/jobs/fill_blocks.py | 6 +++--- mosfet/jobs/find_gapple.py | 2 +- mosfet/jobs/gather_crop.py | 2 +- mosfet/jobs/gather_sand.py | 2 +- mosfet/jobs/gather_wart.py | 2 +- mosfet/jobs/gather_wood.py | 2 +- mosfet/jobs/grab_sand.py | 2 +- mosfet/jobs/grab_sapling.py | 2 +- mosfet/jobs/grab_supplies.py | 2 +- mosfet/jobs/plant_tree.py | 2 +- mosfet/jobs/sell_to_villager.py | 2 +- mosfet/jobs/sleep_with_bed.py | 2 +- mosfet/path.py | 3 +-- mosfet/utils.py | 6 +++++- mosfet/vector.py | 3 ++- mosfet/world.py | 5 ++--- 23 files changed, 28 insertions(+), 28 deletions(-) diff --git a/mosfet/commands.py b/mosfet/commands.py index 72e8a23..86a5a15 100644 --- a/mosfet/commands.py +++ b/mosfet/commands.py @@ -1,7 +1,6 @@ import re import time import random -from math import hypot from itertools import count from munch import Munch diff --git a/mosfet/game.py b/mosfet/game.py index 05a9184..e051474 100644 --- a/mosfet/game.py +++ b/mosfet/game.py @@ -1,7 +1,6 @@ import re import time import random -from math import hypot from itertools import count from munch import Munch diff --git a/mosfet/job.py b/mosfet/job.py index 90cb323..cff6bf8 100644 --- a/mosfet/job.py +++ b/mosfet/job.py @@ -3,7 +3,6 @@ import time import importlib import random from itertools import count -from math import hypot, floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/cache_items.py b/mosfet/jobs/cache_items.py index 38d5aba..b0b8c8d 100644 --- a/mosfet/jobs/cache_items.py +++ b/mosfet/jobs/cache_items.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/check_threats.py b/mosfet/jobs/check_threats.py index f61eee7..b150632 100644 --- a/mosfet/jobs/check_threats.py +++ b/mosfet/jobs/check_threats.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/clear_leaves.py b/mosfet/jobs/clear_leaves.py index e3e9221..5505e4c 100644 --- a/mosfet/jobs/clear_leaves.py +++ b/mosfet/jobs/clear_leaves.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/eat_food.py b/mosfet/jobs/eat_food.py index 16bb758..bfae10e 100644 --- a/mosfet/jobs/eat_food.py +++ b/mosfet/jobs/eat_food.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/fill_blocks.py b/mosfet/jobs/fill_blocks.py index 31243f1..21b8bef 100644 --- a/mosfet/jobs/fill_blocks.py +++ b/mosfet/jobs/fill_blocks.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace @@ -40,7 +40,7 @@ class FillBlocksStates: b1, b2 = utils.pboundingbox(f.coord1, f.coord2) box = utils.psub(b2, b1) - xz_distance = hypot(box[0]+1, box[2]+1) + xz_distance = utils.hypot(box[0]+1, box[2]+1) y_start = f.coord1[1] y_end = f.coord2[1] @@ -84,7 +84,7 @@ class FillBlocksStates: b1, b2 = utils.pboundingbox(f.coord1, f.coord2) box = utils.psub(b2, b1) - xz_distance = hypot(box[0]+1, box[2]+1) + xz_distance = utils.hypot(box[0]+1, box[2]+1) y_start = f.coord1[1] y_end = f.coord2[1] diff --git a/mosfet/jobs/find_gapple.py b/mosfet/jobs/find_gapple.py index 6ac0f82..dd74544 100644 --- a/mosfet/jobs/find_gapple.py +++ b/mosfet/jobs/find_gapple.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/gather_crop.py b/mosfet/jobs/gather_crop.py index 7f7ff5d..f92cddd 100644 --- a/mosfet/jobs/gather_crop.py +++ b/mosfet/jobs/gather_crop.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/gather_sand.py b/mosfet/jobs/gather_sand.py index 10fe9f6..1d7d251 100644 --- a/mosfet/jobs/gather_sand.py +++ b/mosfet/jobs/gather_sand.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/gather_wart.py b/mosfet/jobs/gather_wart.py index 8f1a47e..3a3eb98 100644 --- a/mosfet/jobs/gather_wart.py +++ b/mosfet/jobs/gather_wart.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/gather_wood.py b/mosfet/jobs/gather_wood.py index 012eb3e..100969e 100644 --- a/mosfet/jobs/gather_wood.py +++ b/mosfet/jobs/gather_wood.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/grab_sand.py b/mosfet/jobs/grab_sand.py index bafb88a..db0a659 100644 --- a/mosfet/jobs/grab_sand.py +++ b/mosfet/jobs/grab_sand.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/grab_sapling.py b/mosfet/jobs/grab_sapling.py index d2f1012..197fee6 100644 --- a/mosfet/jobs/grab_sapling.py +++ b/mosfet/jobs/grab_sapling.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/grab_supplies.py b/mosfet/jobs/grab_supplies.py index 7ebbc7d..e17e080 100644 --- a/mosfet/jobs/grab_supplies.py +++ b/mosfet/jobs/grab_supplies.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/plant_tree.py b/mosfet/jobs/plant_tree.py index e2e264e..f55901a 100644 --- a/mosfet/jobs/plant_tree.py +++ b/mosfet/jobs/plant_tree.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/sell_to_villager.py b/mosfet/jobs/sell_to_villager.py index 5dd2d0d..1033f80 100644 --- a/mosfet/jobs/sell_to_villager.py +++ b/mosfet/jobs/sell_to_villager.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/jobs/sleep_with_bed.py b/mosfet/jobs/sleep_with_bed.py index 55de0f7..3674872 100644 --- a/mosfet/jobs/sleep_with_bed.py +++ b/mosfet/jobs/sleep_with_bed.py @@ -3,7 +3,7 @@ import time import importlib import random from itertools import count -from math import hypot, floor +from math import floor from minecraft.networking.types import BlockFace diff --git a/mosfet/path.py b/mosfet/path.py index f951af3..d48cb1a 100644 --- a/mosfet/path.py +++ b/mosfet/path.py @@ -1,7 +1,6 @@ import importlib import functools import time -from math import hypot, sqrt from astar import AStar @@ -306,7 +305,7 @@ class Pathfinder(AStar): def distance_between(self, n1, n2): (x1, y1, z1) = n1 (x2, y2, z2) = n2 - return hypot(x2-x1, y2-y1, z2-z1) + return utils.hypot(x2-x1, y2-y1, z2-z1) def heuristic_cost_estimate(self, n1, n2): (x1, y1, z1) = n1 diff --git a/mosfet/utils.py b/mosfet/utils.py index f8c69fe..ea5710f 100644 --- a/mosfet/utils.py +++ b/mosfet/utils.py @@ -1,12 +1,16 @@ import importlib import collections -from math import floor, ceil, sqrt, hypot +from math import floor, ceil, sqrt from mosfet.info import blocks from mosfet.info import mcdata TICK = 0.05 +def hypot(*coordinates): + # python's 3D hypot is too new, so we'll use our own + return sqrt(sum(x**2 for x in coordinates)) + def padd(p1, p2): return (p1[0] + p2[0], p1[1] + p2[1], p1[2] + p2[2]) diff --git a/mosfet/vector.py b/mosfet/vector.py index be83335..05ccf63 100644 --- a/mosfet/vector.py +++ b/mosfet/vector.py @@ -1,4 +1,5 @@ import math +from mosfet import utils class Vector3D: def __init__(self, vector): @@ -17,7 +18,7 @@ class Vector3D: return self.tuple()[key] def length(self): - return math.hypot(self.x, self.y, self.z) + return utils.hypot(self.x, self.y, self.z) def normalized(self): x = self.x / self.length() diff --git a/mosfet/world.py b/mosfet/world.py index cda9646..21e9529 100644 --- a/mosfet/world.py +++ b/mosfet/world.py @@ -2,7 +2,6 @@ import collections import re import time import random -from math import hypot from itertools import count from copy import copy @@ -35,7 +34,7 @@ class World: continue if y_limit and abs(cur[1]) > y_limit: continue - if distance and hypot(*cur) > distance: + if distance and utils.hypot(*cur) > distance: continue check = utils.padd(center, cur) @@ -76,7 +75,7 @@ class World: offset = utils.spiral(n) check = utils.padd(center, offset) if self.block_at(*check) in block_ids: - if hypot(*offset) < distance: + if utils.hypot(*offset) < distance: result.append(check) if limit and len(result) == limit: return result