MineKhan icon indicating copy to clipboard operation
MineKhan copied to clipboard

Flora and Fauna

Open ghost opened this issue 3 years ago • 14 comments

Live animals and Live plants.

An ECO system in minekhan...

ghost avatar May 12 '21 08:05 ghost

hmm AI would be a huge thing to figure out first.

SnehasishCodez avatar May 12 '21 15:05 SnehasishCodez

hmm AI would be a huge thing to figure out first.

I'm unaware of whether Minecraft uses genuine A.I. or not, but it's no necessary, we just need a way to measure the shortest path from one block to another, and to make the mob follow it.

Mobs don't learn, they aren't smart.

ghost avatar May 12 '21 16:05 ghost

hmm AI would be a huge thing to figure out first.

I'm unaware of whether Minecraft uses genuine A.I. or not, but it's no necessary, we just need a way to measure the shortest path from one block to another, and to make the mob follow it.

Mobs don't learn, they aren't smart.

Let me rephrase my sentence how bout we need to just code a simple bot/AI for mobs that tell them not to fall off a cliff or not to go into a cave which would require tons more of work

Maybe There could be a different word instead of AI but 🤷

SnehasishCodez avatar May 12 '21 16:05 SnehasishCodez

Guys do you guys sometimes get the chills playing minekhan like you arent alone there is someone else playing in the emty world of minekhan ???

(It would be funny if willard added herbrine for fun after basic mobs get added lol).

SnehasishCodez avatar May 12 '21 16:05 SnehasishCodez

These will be Very Hard, near to impossible but only near, most likely will make the project incompable with Khan

Hacker1254 avatar May 12 '21 22:05 Hacker1254

hmm AI would be a huge thing to figure out first.

I'm unaware of whether Minecraft uses genuine A.I. or not, but it's no necessary, we just need a way to measure the shortest path from one block to another, and to make the mob follow it.

Mobs don't learn, they aren't smart. its possible for us to implement A* or some other form of naïve path finding.

InterestingBrainPoops avatar May 13 '21 03:05 InterestingBrainPoops

I just used:

 this.speed = 0.1
        if (this.x > p.x - (this.height / 2)) {

            this.x -= this.speed / 4
;
        }
        if (this.x < p.x - (this.height / 2)) {
            this.x += this.speed / 4;
        }
        if (this.z > p.z - (this.height / 2)) {

        
            this.z -= this.speed / 4; 
        }
        if (this.z < p.z - (this.height / 2)) {

            this.z += this.speed / 4;
        }
        if (this.y > p.y+0.1 - (this.height / 2)) {

            this.y += this.speed / 4; 
        }
        if (this.y < p.y+0.1 - (this.height / 2)) {

            this.y += this.speed / 4;
        }

and

        this.updateVelocity(now)

dumbest AI ever. If you want it to rotate towards you,

  function angleToPointDegrees(point1, point2) {
    return (angleToPointRadians(point1, point2) * 180 / Math.PI);
  }
  
  function getPos(canvas, evt) {
    var rect = canvas.getBoundingClientRect();
    return {
      x: evt.clientX - rect.left,
      y: evt.clientY - rect.top
    };
  }
    var playerPos = {x: p.x, z: p.z};
			let now = performance.now()
        let d = p.direction
        this.yaw = -angleToPointRadians(playerPos, this) + 110;

ghost avatar Jun 13 '21 14:06 ghost

Edit: this is in the modded ver. I dunno if it works on the real thing.

ghost avatar Jun 13 '21 14:06 ghost

	var path = [];				// Array of path branch checks
	var path_switch = false;	// Triggered when the generated path is switched to use
	var path_i = 0;				// Number of branch check iterations
	var path_count = 0;			// Number of path branches made
	var path_end = false;		// If the path has found its destination
	var path_loopcount = 0;		// Number of path entries to check
	var path_target_x = 0;		// Target X co-ordinate
	var path_target_y = 0;		// Target Y co-ordinate
	var path_start_x = 0;		// Starting X co-ordinate
	var path_start_y = 0;		// Starting Y co-ordinate
	var path_parent_x = 0;		// Stored parent X co-ordinate for building final path
	var path_parent_y = 0;		// Stored parent Y co-ordinate for building final path
	var path_done = [];			// Final path
	var path_done_count = 0;	// Final path count
	var path_coords = [];		// Recorded co-ordinates of each move for mapping best path when a proper one isn't possible
	var path_coords_count = 0;	// Number of recorded co-ordinates
	var path_store_x = 0;		// Closest possible co-ordinate if the path isn't possible
	var path_store_y = 0;		// Closest possible co-ordinate if the path isn't possible
	var path_store_n = 0;		// How close a set of co-ordinates is to the target
	var path_limit = 3000;		// Number of steps in the pathfinder
	
	function calcPath(x1,y1) {

		// Set target location
		path_target_x = Math.floor((Math.abs(screen_x)+x1-(bound_x*0.2))/gridsize);
		path_target_y = Math.floor((Math.abs(screen_y)+y1-(bound_y*0.2))/gridsize);
		
		// Set current location
		path_start_x = Math.floor(((spawn_x*gridsize)+xoffset)/gridsize);
		path_start_y = Math.floor(((spawn_y*gridsize)+yoffset)/gridsize);
		
		// Build array of landscape for pathbuilding
		path = [];
		for (y=0; y<ls.length; y++) {
			path[y] = [];
			for (x=0; x<ls[0].length; x++) {
				path[y][x] = '';
			}
		}
		
		// Set initial variables
		path_i = 0;
		path_end = false;
		path[path_start_y][path_start_x] = 'start';
		path[(path_start_y-1)][(path_start_x)] = 'up';
		path[(path_start_y+1)][(path_start_x)] = 'down';
		path[(path_start_y)][(path_start_x-1)] = 'left';
		path[(path_start_y)][(path_start_x+1)] = 'right';
		path_coords = [];
		path_coords_count = 0;
		
		cx = path_start_x;
		cy = path_start_y;
		p_dir = 'right';
		p_num = 1;
		p_count = 0;

		// Main checker
		while (path_i<path_limit&&!path_end) {

			//alert(p_num+' - '+p_count+' - '+p_dir)
			cancel = false;
		
			// Spiral outwards from starting position to check tiles
			if (p_dir=='right') {
				if (p_count<=p_num) {
					p_count++;
					cx += 1;
					if (p_count==p_num) {
						p_dir = 'down';
						p_count = 0;
					}
				}
			}
			else if (p_dir=='down') {
				if (p_count<=p_num) {
					p_count++;
					cy += 1;
					if (p_count==p_num) {
						p_dir = 'left';
						p_count = 0;
						p_num++;
					}
				}
			}
			else if (p_dir=='left') {
				if (p_count<=p_num) {
					p_count++;
					cx -= 1;
					if (p_count==p_num) {
						p_dir = 'up';
						p_count = 0;
					}
				}
			}
			else if (p_dir=='up') {
				if (p_count<=p_num) {
					p_count++;
					cy -= 1;
					if (p_count==p_num) {
						p_dir = 'right';
						p_count = 0;
						p_num++;
					}
				}
			}
			
			// Limit spiral to within the area
			if (cy<1) { cancel = true; }
			if (cx<1) { cancel = true; }
			if ((ls.length-2)<cy) { cancel = true; }
			if ((ls[0].length-2)<cx) { cancel = true; }
			
			// Check current tile
			if (!cancel&&path[cy][cx]!=''&&path[cy][cx]!='start') {
	
				// If down is free
				if (!calcPathTiles(cx,cy+1)&&path[(cy+1)][(cx)]=='') {
					path_coords[path_coords_count] = [cx,cy+1];
					path_coords_count++;
					path[(cy+1)][(cx)] = 'down';
				}
				// If right is free
				if (!calcPathTiles(cx+1,cy)&&path[(cy)][(cx+1)]=='') {
					path_coords[path_coords_count] = [cx+1,cy];
					path_coords_count++;
					path[(cy)][(cx+1)] = 'right';
				}
				// If up is free
				if (!calcPathTiles(cx,cy-1)&&path[(cy-1)][(cx)]=='') {
					path_coords[path_coords_count] = [cx,cy-1];
					path_coords_count++;
					path[(cy-1)][(cx)] = 'up';
				}
				// If left is free
				if (!calcPathTiles(cx-1,cy)&&path[(cy)][(cx-1)]=='') {
					path_coords[path_coords_count] = [cx-1,cy];
					path_coords_count++;
					path[(cy)][(cx-1)] = 'left';
				}
	
			}

			if (path[path_target_y][path_target_x]!='') {
				path_end = true;
			}
			path_i++;	// Count iterations
		}
		
		// If we didn't find the destination get the closest co-ordinate
		if (!path_end) {
		
			path_store_x = 0;		// Closest X co-ordinate
			path_store_y = 0;		// Closest Y co-ordinate
			path_store_n = 100000;	// Number value of how close it is
		
			// Loop through all recorded co-ordinates
			for (i=0; i<path_coords_count; i++) {
				nx = Math.abs(path_target_x-path_coords[i][0]);
				ny = Math.abs(path_target_y-path_coords[i][1]);
				
				// If current co-ordinate is closer to the target than the current closest
				if ((nx+ny)<path_store_n) {
					path_store_x = path_coords[i][0];	// Set current closest X co-ordinate
					path_store_y = path_coords[i][1];	// Set current closest Y co-ordinate
					path_store_n = nx+ny;				// Set current close value to check by
				}
			}
			px1 = path_store_x;	// Set the starting X co-ordinate to the closest co-ordinate
			py1 = path_store_y;	// Set the starting Y co-ordinate to the closest co-ordinate
			
		// If we did find the destination
		} else {
			px1 = path_target_x;	// Set the starting X co-ordinate to the destination
			py1 = path_target_y;	// Set the starting Y co-ordinate to the destination
		}
		

		// Reset the finished path map vars
		path_done = [];
		path_done_count = 0;
		path_mapped = false;
		path_mapped_i = 0;
		direction1 = '';
		direction2 = '';
		direction3 = '';
		px2 = 0;				// One step forward X
		py2 = 0;				// One step forward Y
		px3 = 0;				// Two steps forward X
		py3 = 0;				// Two steps forward Y
		diagonal = false;

		// Calculate the route from the spidered array
		while(!path_mapped&&(path_done_count<path_limit+20)) {
		
			// Move co-ordinates forward a step
			direction3 = direction2;
			px3 = px2;
			py3 = py2;				
			direction2 = direction1;
			px2 = px1;
			py2 = py1;

			// Head backwards from the direction to trace the route back
			direction1 = path[py1][px1];
			
			if (direction1=='up') {
				py1 = py2+1;
				px1 = px2; 
			}
			else if (direction1=='down') {
				py1 = py2-1;
				px1 = px2; 
			}
			else if (direction1=='left') {
				py1 = py2;
				px1 = px2+1; 
			}
			else if (direction1=='right') {
				py1 = py2;
				px1 = px2-1;
			}
			
			// Overwrite diagonal tiles
			var overwrite = false;
			
			if (direction1=='up') {
				if (direction2=='left') {
					overwrite = true;
					direction1 = 'upleft';
				}
				if (direction2=='right') {
					overwrite = true;
					direction1 = 'upright';
				}
			}
			if (direction1=='down') {
				if (direction2=='left') {
					overwrite = true;
					direction1 = 'downleft';
				}
				if (direction2=='right') {
					overwrite = true;
					direction1 = 'downright';
				}
			}
			if (direction1=='left') {
				if (direction2=='up') {
					overwrite = true;
					direction1 = 'upleft';
				}
				if (direction2=='down') {
					overwrite = true;
					direction1 = 'downleft';
				}
			}
			if (direction1=='right') {
				if (direction2=='up') {
					overwrite = true;
					direction1 = 'upright';
				}
				if (direction2=='down') {
					overwrite = true;
					direction1 = 'downright';
				}
			}
			if (overwrite) {
				if (diagonal) {
					diagonal = false;
				} else {
					path_done_count -= 1;
					diagonal = true;
				}
			} else {
				diagonal = false;
			}

			// Add to the route array the direction and co-ordinates
			path_done[path_done_count] = [direction1,px1,py1];

			// Count the backwards steps in the route
			path_done_count++;
			
			// If we have reached the start
			if (px1==path_start_x&&py1==path_start_y) {
				path_mapped = true;
			}
		}
		

	}

nailed it!

ghost avatar Jun 13 '21 16:06 ghost

Took longer than expected, but I now have a fully functioning AI!

ghost avatar Jun 13 '21 16:06 ghost

Actually.... I don't. errors... errors... more errors... I managed to do it in p5.js.... but not in js...

ghost avatar Jul 16 '21 18:07 ghost

hmm AI would be a huge thing to figure out first.

I'm unaware of whether Minecraft uses genuine A.I. or not, but it's no necessary, we just need a way to measure the shortest path from one block to another, and to make the mob follow it.

Mobs don't learn, they aren't smart.

it dosent its just path find and if else

harsha7addanki avatar Jun 29 '23 13:06 harsha7addanki

AI doesn't imply neural networks when referring to game entities, so learning has nothing to do with it. AI just refers to the logic used to control them. If you call entities pets, allies, enemies, mobs, or NPCs, you're attributing some level of intelligence to them, and that intelligence is artificial, making it AI. Even if it's stupid AI, it's still AI.

Willard21 avatar Jul 01 '23 23:07 Willard21

yeah i figured when he said genuine ai i thought he meant like ML/DL

harsha7addanki avatar Jul 03 '23 13:07 harsha7addanki