| 1 | package net.minecraft.world.level.pathfinder;
|
| 2 |
|
| 3 | import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
| 4 | import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
| 5 | import net.minecraft.core.BlockPos;
|
| 6 | import net.minecraft.tags.BlockTags;
|
| 7 | import net.minecraft.util.Mth;
|
| 8 | import net.minecraft.world.entity.Mob;
|
| 9 | import net.minecraft.world.level.PathNavigationRegion;
|
| 10 | import net.minecraft.world.level.block.Blocks;
|
| 11 | import net.minecraft.world.level.block.CampfireBlock;
|
| 12 | import net.minecraft.world.level.block.state.BlockState;
|
| 13 |
|
| 14 | public abstract class NodeEvaluator {
|
| 15 | protected PathfindingContext currentContext;
|
| 16 | protected Mob mob;
|
| 17 | protected final Int2ObjectMap<Node> nodes = new Int2ObjectOpenHashMap<>();
|
| 18 | protected int entityWidth;
|
| 19 | protected int entityHeight;
|
| 20 | protected int entityDepth;
|
| 21 | protected boolean canPassDoors = true;
|
| 22 | protected boolean canOpenDoors;
|
| 23 | protected boolean canFloat;
|
| 24 | protected boolean canWalkOverFences;
|
| 25 |
|
| 26 | public void prepare(final PathNavigationRegion level, final Mob entity) {
|
| 27 | this.currentContext = new PathfindingContext(level, entity);
|
| 28 | this.mob = entity;
|
| 29 | this.nodes.clear();
|
| 30 | this.entityWidth = Mth.floor(entity.getBbWidth() + 1.0F);
|
| 31 | this.entityHeight = Mth.floor(entity.getBbHeight() + 1.0F);
|
| 32 | this.entityDepth = Mth.floor(entity.getBbWidth() + 1.0F);
|
| 33 | }
|
| 34 |
|
| 35 | public void done() {
|
| 36 | this.currentContext = null;
|
| 37 | this.mob = null;
|
| 38 | }
|
| 39 |
|
| 40 | protected Node getNode(final BlockPos pos) {
|
| 41 | return this.getNode(pos.getX(), pos.getY(), pos.getZ());
|
| 42 | }
|
| 43 |
|
| 44 | protected Node getNode(final int x, final int y, final int z) {
|
| 45 | return this.nodes.computeIfAbsent(Node.createHash(x, y, z), k -> new Node(x, y, z));
|
| 46 | }
|
| 47 |
|
| 48 | public abstract Node getStart();
|
| 49 |
|
| 50 | public abstract Target getTarget(double x, double y, double z);
|
| 51 |
|
| 52 | protected Target getTargetNodeAt(final double x, final double y, final double z) {
|
| 53 | return new Target(this.getNode(Mth.floor(x), Mth.floor(y), Mth.floor(z)));
|
| 54 | }
|
| 55 |
|
| 56 | public abstract int getNeighbors(Node[] neighbors, Node pos);
|
| 57 |
|
| 58 | public abstract PathType getPathTypeOfMob(PathfindingContext context, int x, int y, int z, Mob mob);
|
| 59 |
|
| 60 | public abstract PathType getPathType(PathfindingContext context, int x, int y, int z);
|
| 61 |
|
| 62 | public PathType getPathType(final Mob mob, final BlockPos pos) {
|
| 63 | return this.getPathType(new PathfindingContext(mob.level(), mob), pos.getX(), pos.getY(), pos.getZ());
|
| 64 | }
|
| 65 |
|
| 66 | public void setCanPassDoors(final boolean canPassDoors) {
|
| 67 | this.canPassDoors = canPassDoors;
|
| 68 | }
|
| 69 |
|
| 70 | public void setCanOpenDoors(final boolean canOpenDoors) {
|
| 71 | this.canOpenDoors = canOpenDoors;
|
| 72 | }
|
| 73 |
|
| 74 | public void setCanFloat(final boolean canFloat) {
|
| 75 | this.canFloat = canFloat;
|
| 76 | }
|
| 77 |
|
| 78 | public void setCanWalkOverFences(final boolean canWalkOverFences) {
|
| 79 | this.canWalkOverFences = canWalkOverFences;
|
| 80 | }
|
| 81 |
|
| 82 | public boolean canPassDoors() {
|
| 83 | return this.canPassDoors;
|
| 84 | }
|
| 85 |
|
| 86 | public boolean canOpenDoors() {
|
| 87 | return this.canOpenDoors;
|
| 88 | }
|
| 89 |
|
| 90 | public boolean canFloat() {
|
| 91 | return this.canFloat;
|
| 92 | }
|
| 93 |
|
| 94 | public boolean canWalkOverFences() {
|
| 95 | return this.canWalkOverFences;
|
| 96 | }
|
| 97 |
|
| 98 | public static boolean isBurningBlock(final BlockState blockState) {
|
| 99 | return blockState.is(BlockTags.FIRE)
|
| 100 | || blockState.is(Blocks.LAVA)
|
| 101 | || blockState.is(Blocks.MAGMA_BLOCK)
|
| 102 | || CampfireBlock.isLitCampfire(blockState)
|
| 103 | || blockState.is(Blocks.LAVA_CAULDRON);
|
| 104 | }
|
| 105 | }
|
| 106 |
|