Skip to content

Commit

Permalink
Merge EntityUtils.getCityBlock and EntityUtils.getSurroundBlock utils…
Browse files Browse the repository at this point in the history
… and correct error message for AutoCity (#3084)
  • Loading branch information
machiecodes authored Dec 21, 2022
1 parent f2652a6 commit d31695d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void onActivate() {

targetPos = EntityUtils.getCityBlock(target);
if (targetPos == null || PlayerUtils.distanceTo(targetPos) > breakRange.get()) {
if (chatInfo.get()) error("Couldn't find a target, disabling.");
if (chatInfo.get()) error("Couldn't find a good block, disabling.");
toggle();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.ChunkSectionPos;
Expand All @@ -38,14 +39,15 @@
import net.minecraft.world.entity.SimpleEntityLookup;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;

import static meteordevelopment.meteorclient.MeteorClient.mc;

public class EntityUtils {
private static BlockPos.Mutable testPos = new BlockPos.Mutable();

public static boolean isAttackable(EntityType<?> type) {
return type != EntityType.AREA_EFFECT_CLOUD && type != EntityType.ARROW && type != EntityType.FALLING_BLOCK && type != EntityType.FIREWORK_ROCKET && type != EntityType.ITEM && type != EntityType.LLAMA_SPIT && type != EntityType.SPECTRAL_ARROW && type != EntityType.ENDER_PEARL && type != EntityType.EXPERIENCE_BOTTLE && type != EntityType.POTION && type != EntityType.TRIDENT && type != EntityType.LIGHTNING_BOLT && type != EntityType.FISHING_BOBBER && type != EntityType.EXPERIENCE_ORB && type != EntityType.EGG;
}
Expand Down Expand Up @@ -111,55 +113,28 @@ public static boolean isInRenderDistance(double posX, double posZ) {
return x < d && z < d;
}

public static List<BlockPos> getSurroundBlocks(PlayerEntity player) {
public static BlockPos getCityBlock(PlayerEntity player) {
if (player == null) return null;
BlockPos.Mutable testPos = new BlockPos.Mutable();

List<BlockPos> positions = new ArrayList<>();
double bestDistance = 6;
Direction bestDirection = null;

for (Direction direction : Direction.HORIZONTAL) {
testPos.set(player.getBlockPos()).offset(direction);

if (mc.world.getBlockState(testPos).getBlock() == Blocks.OBSIDIAN) {
positions.add(testPos);
}
}

return positions;
}

@Nullable
public static BlockPos getCityBlock(PlayerEntity player) {
BlockPos bestPos = null;
int bestScore = 0;
BlockPos.Mutable testPos = new BlockPos.Mutable();

for (BlockPos pos : getSurroundBlocks(player)) {
int score = 1;

for (Direction direction : Direction.values()) {
testPos.set(pos).offset(direction);
Block block = mc.world.getBlockState(testPos).getBlock();

if (direction == Direction.DOWN && block == Blocks.OBSIDIAN || block == Blocks.BEDROCK) {
score+= 2;
continue;
}

if (direction != Direction.DOWN && block instanceof AirBlock) {
score++;
}
}
testPos.set(player.getBlockPos().offset(direction));

score -= PlayerUtils.distanceTo(pos);
Block block = mc.world.getBlockState(testPos).getBlock();
if (block != Blocks.OBSIDIAN && block != Blocks.NETHERITE_BLOCK && block != Blocks.CRYING_OBSIDIAN
&& block != Blocks.RESPAWN_ANCHOR && block != Blocks.ANCIENT_DEBRIS) continue;

if (score >= bestScore) {
bestPos = pos;
bestScore = score;
double testDistance = PlayerUtils.distanceTo(testPos);
if (testDistance < bestDistance) {
bestDistance = testDistance;
bestDirection = direction;
}
}

return bestPos;
if (bestDirection == null) return null;
return player.getBlockPos().offset(bestDirection);
}

public static String getName(Entity entity) {
Expand Down

0 comments on commit d31695d

Please sign in to comment.