Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hostileworlds.ai.jobs;
- import net.minecraft.pathfinding.PathEntity;
- import net.minecraft.util.ChunkCoordinates;
- import net.minecraft.util.MovingObjectPosition;
- import CoroAI.PFQueue;
- import CoroAI.componentAI.jobSystem.JobBase;
- import CoroAI.componentAI.jobSystem.JobManager;
- import CoroAI.entity.EnumActState;
- import CoroAI.entity.EnumJobState;
- public class JobPathDigger extends JobGroupHorde {
- //Threading and pathfind simulation variables
- public int pfReturnTimeout = 0;
- public boolean waitingForPath = false;
- public boolean waitingForThreadPath = false;
- public PathEntity pathReturned = null;
- public boolean tryPathToTarget = true;
- public boolean hasPathToTarget = false;
- //Dig state variables
- public int simuDigCount;
- public ChunkCoordinates lastMinedCoord = null;
- public EnumJobState digState = EnumJobState.IDLE;
- public ChunkCoordinates bestDigCoord = null;
- public JobPathDigger(JobManager jm) {
- super(jm);
- }
- @Override
- public boolean shouldExecute() {
- return true;
- }
- @Override
- public boolean shouldContinue() {
- return false;
- }
- @Override
- public void onIdleTick() {
- }
- @Override
- public void tick() {
- //super.tick();
- //w1 = waiting on good angle, skipped for above target digs
- //w2 =
- if (pfReturnTimeout > 0) {
- pfReturnTimeout--;
- } else {
- if (waitingForPath) {
- waitingForPath = false;
- }
- }
- if (((JobGroupHorde)jm.getPrimaryJob()).attackCoord == null) return;
- ChunkCoordinates attackCoord = ((JobGroupHorde)jm.getPrimaryJob()).attackCoord;
- if (this.state == EnumJobState.IDLE) {
- if (!hasPathToTarget) {
- if (!waitingForPath) {
- if (tryPathToTarget) {
- if (ent.onGround) {
- waitingForPath = true;
- pathReturned = null;
- pfReturnTimeout = 40;
- waitingForThreadPath = true;
- PFQueue.tryPath(ent, attackCoord.posX, attackCoord.posY, attackCoord.posZ, entInt.getAIAgent().maxPFRange, 0);
- }
- }
- } else {
- if (!waitingForThreadPath) {
- if (pathReturned != null) {
- float dist = (float) Math.sqrt(attackCoord.getDistanceSquared(pathReturned.getFinalPathPoint().xCoord, pathReturned.getFinalPathPoint().yCoord, pathReturned.getFinalPathPoint().zCoord));
- System.out.println(dist);
- System.out.println(pathReturned.getCurrentPathLength());
- if (dist < 4F) {
- hasPathToTarget = true;
- } else {
- hasPathToTarget = false;
- }
- tryPathToTarget = false; //now that we know we must dig, logic later on must set this to true to reset the loop
- } else {
- System.out.println("no path");
- hasPathToTarget = false;
- waitingForPath = false;
- }
- }
- }
- }
- if (!tryPathToTarget) {
- if (hasPathToTarget) {
- super.tick();
- return;
- } else {
- this.setJobState(EnumJobState.W1);
- }
- }
- } else if (this.state == EnumJobState.W1) {
- if (this.entInt.getAIAgent().currentAction == EnumActState.IDLE) {
- if (isDiggableAngle()) {
- this.setJobState(EnumJobState.W2);
- } else {
- this.entInt.getAIAgent().updateWanderPath();
- }
- }
- } else if (this.state == EnumJobState.W2) {
- //simu dig #1
- if (simuDigCount == 0) {
- //strait dig test
- if (true) { //skipping a huge sensing step here
- //temp since W2 should set this
- bestDigCoord = ((JobGroupHorde)jm.getPrimaryJob()).attackCoord;
- this.setJobState(EnumJobState.W3);
- }
- } else if (simuDigCount < 5) {
- }
- } else if (this.state == EnumJobState.W3) {
- //DIG!
- entInt.getAIAgent().setState(EnumActState.WALKING);
- this.walkingTimeout = 600;
- if (bestDigCoord != null && ent.getDistance(bestDigCoord.posX, bestDigCoord.posY, bestDigCoord.posZ) >= 1F) {
- int offset = 0;
- if (digState == EnumJobState.W1) offset = -1;
- MovingObjectPosition aim = entInt.getAIAgent().rayTrace(1F, 1 + offset);
- if (aim != null) {
- int id = ent.worldObj.getBlockId(aim.blockX, aim.blockY, aim.blockZ);
- if (id != 0) {
- System.out.println(ent.rotationYaw);
- if (ent.worldObj.getBlockTileEntity(aim.blockX, aim.blockY, aim.blockZ) == null) {
- ent.worldObj.setBlock(aim.blockX, aim.blockY, aim.blockZ, 0);
- lastMinedCoord = new ChunkCoordinates(aim.blockX, aim.blockY, aim.blockZ);
- if (digState == EnumJobState.IDLE) {
- digState = EnumJobState.W1;
- } else {
- digState = EnumJobState.IDLE;
- }
- ent.swingItem();
- }
- }
- } else {
- if (ent.onGround && ent.isCollidedHorizontally && ent.boundingBox.minY < bestDigCoord.posY) {
- //ent.jump();
- }
- }
- if (lastMinedCoord != null) {
- entInt.getAIAgent().faceCoord(lastMinedCoord, 180, 180);
- } else {
- entInt.getAIAgent().faceCoord(bestDigCoord, 180, 180);
- }
- ent.moveFlying((ent.worldObj.rand.nextFloat() * 0.2F) - 0.1F, 0.5F, 0.2F);
- //System.out.println(aim);
- entInt.getAIAgent().entityToAttack = null;
- }
- } else if (this.state == EnumJobState.W4) {
- }
- System.out.println(state);
- //if below
- }
- public boolean isDiggableAngle() {
- if (ent.posY > ((JobGroupHorde)jm.getPrimaryJob()).attackCoord.posY) {
- return true;
- } else if (getVerticalAngle() > 50) {
- return true;
- }
- return false;
- }
- public float getVerticalAngle() {
- return 60F; //fake a safe angle for now
- }
- public void setPathToEntity(PathEntity pathentity)
- {
- if (waitingForThreadPath) {
- pathReturned = pathentity;
- waitingForThreadPath = false;
- } else {
- entInt.getAIAgent().setPathToEntityForce(pathentity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement