All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minecraft.server.PathfinderGoalMoveThroughVillage Maven / Gradle / Ivy

package net.minecraft.server;

import com.google.common.collect.Lists;

import java.util.Iterator;
import java.util.List;

public class PathfinderGoalMoveThroughVillage extends PathfinderGoal {
	
	private final EntityCreature a;
	private final double b;
	private PathEntity c;
	private VillageDoor d;
	private final boolean e;
	private final List f = Lists.newArrayList();
	
	public PathfinderGoalMoveThroughVillage(EntityCreature entitycreature, double d0, boolean flag) {
		this.a = entitycreature;
		this.b = d0;
		this.e = flag;
		this.setMutexBits(1);
		if (!(entitycreature.getNavigation() instanceof Navigation)) {
			throw new IllegalArgumentException("Unsupported mob for MoveThroughVillageGoal");
		}
	}
	
	public boolean a() {
		this.f();
		if (this.e && this.a.world.w()) {
			return false;
		} else {
			Village village = this.a.world.ae().getClosestVillage(new BlockPosition(this.a), 0);
			
			if (village == null) {
				return false;
			} else {
				this.d = this.a(village);
				if (this.d == null) {
					return false;
				} else {
					Navigation navigation = (Navigation) this.a.getNavigation();
					boolean flag = navigation.g();
					
					navigation.b(false);
					this.c = navigation.getPathToPos(this.d.d());
					navigation.b(flag);
					if (this.c != null) {
						return true;
					} else {
						Vec3D vec3d = RandomPositionGenerator.a(this.a, 10, 7, new Vec3D(this.d.d().getX(), this.d.d().getY(), this.d.d().getZ()));
						
						if (vec3d == null) {
							return false;
						} else {
							navigation.b(false);
							this.c = this.a.getNavigation().getPathToXYZ(vec3d.a, vec3d.b, vec3d.c);
							navigation.b(flag);
							return this.c != null;
						}
					}
				}
			}
		}
	}
	
	public boolean b() {
		if (this.a.getNavigation().noPath()) {
			return false;
		} else {
			float f = this.a.width + 4.0F;
			
			return this.a.getDistanceSquared(this.d.d()) > (double) (f * f);
		}
	}
	
	public void c() {
		this.a.getNavigation().setPath(this.c, this.b);
	}
	
	public void d() {
		if (this.a.getNavigation().noPath() || this.a.getDistanceSquared(this.d.d()) < 16.0D) {
			this.f.add(this.d);
		}
		
	}
	
	private VillageDoor a(Village village) {
		VillageDoor villagedoor = null;
		int i = Integer.MAX_VALUE;
		List list = village.f();
		
		for (VillageDoor villagedoor1 : list) {
			int j = villagedoor1.b(MathHelper.floor(this.a.locX), MathHelper.floor(this.a.locY), MathHelper.floor(this.a.locZ));
			
			if (j < i && !this.a(villagedoor1)) {
				villagedoor = villagedoor1;
				i = j;
			}
		}
		
		return villagedoor;
	}
	
	private boolean a(VillageDoor villagedoor) {
		Iterator iterator = this.f.iterator();
		
		VillageDoor villagedoor1;
		
		do {
			if (!iterator.hasNext()) {
				return false;
			}
			
			villagedoor1 = iterator.next();
		} while (!villagedoor.d().equals(villagedoor1.d()));
		
		return true;
	}
	
	private void f() {
		if (this.f.size() > 15) {
			this.f.remove(0);
		}
		
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy