2019-08-10 08:44:35 +02:00
|
|
|
package fr.themode.minestom.entity.demo;
|
|
|
|
|
2019-08-30 01:17:46 +02:00
|
|
|
import fr.themode.minestom.entity.Entity;
|
2019-08-10 08:44:35 +02:00
|
|
|
import fr.themode.minestom.entity.EntityCreature;
|
2019-08-27 20:49:11 +02:00
|
|
|
import fr.themode.minestom.entity.EntityType;
|
2019-08-29 02:15:52 +02:00
|
|
|
import fr.themode.minestom.entity.Player;
|
|
|
|
import fr.themode.minestom.utils.Position;
|
2019-08-30 01:17:46 +02:00
|
|
|
import fr.themode.minestom.utils.Vector;
|
|
|
|
import net.tofweb.starlite.CellSpace;
|
|
|
|
import net.tofweb.starlite.CostBlockManager;
|
|
|
|
import net.tofweb.starlite.Path;
|
|
|
|
import net.tofweb.starlite.Pathfinder;
|
2019-08-10 08:44:35 +02:00
|
|
|
|
2019-09-07 11:42:33 +02:00
|
|
|
import java.util.Random;
|
|
|
|
|
2019-08-10 08:44:35 +02:00
|
|
|
public class ChickenCreature extends EntityCreature {
|
|
|
|
|
2019-08-29 02:15:52 +02:00
|
|
|
private Path path;
|
|
|
|
private int counter;
|
|
|
|
private Position target;
|
|
|
|
private long lastTeleport;
|
|
|
|
private long wait = 500;
|
|
|
|
|
2019-09-07 11:42:33 +02:00
|
|
|
private float randomX = new Random().nextFloat();
|
|
|
|
private float randomZ = new Random().nextFloat();
|
|
|
|
|
2019-08-10 08:44:35 +02:00
|
|
|
public ChickenCreature() {
|
2019-08-27 20:49:11 +02:00
|
|
|
super(EntityType.CHICKEN);
|
2019-08-30 01:17:46 +02:00
|
|
|
setBoundingBox(0.4f, 0.7f, 0.4f);
|
2019-08-10 08:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
2019-08-24 20:34:01 +02:00
|
|
|
super.update();
|
2019-09-07 11:42:33 +02:00
|
|
|
float speed = 0.025f;
|
2019-08-10 08:44:35 +02:00
|
|
|
|
2019-08-30 01:17:46 +02:00
|
|
|
if (hasPassenger()) {
|
2019-08-20 17:41:07 +02:00
|
|
|
Entity passenger = getPassengers().iterator().next();
|
|
|
|
if (passenger instanceof Player) {
|
|
|
|
Player player = (Player) passenger;
|
|
|
|
float sideways = player.getVehicleSideways();
|
|
|
|
float forward = player.getVehicleForward();
|
2019-08-30 01:17:46 +02:00
|
|
|
|
|
|
|
boolean jump = player.isVehicleJump();
|
|
|
|
boolean unmount = player.isVehicleUnmount();
|
|
|
|
|
|
|
|
if (jump && isOnGround()) {
|
|
|
|
setVelocity(new Vector(0, 6, 0), 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean updateView = forward > 0;
|
2019-08-20 17:41:07 +02:00
|
|
|
if (sideways == 0f && forward == 0f)
|
|
|
|
return;
|
2019-08-11 13:57:23 +02:00
|
|
|
|
2019-08-30 01:17:46 +02:00
|
|
|
float yaw = player.getPosition().getYaw();
|
2019-08-20 17:41:07 +02:00
|
|
|
yaw %= 360;
|
2019-08-30 01:17:46 +02:00
|
|
|
|
|
|
|
sideways = yaw + (updateView ? -sideways * 90 : sideways * 90);
|
|
|
|
|
2019-08-20 17:41:07 +02:00
|
|
|
if (forward > 0) {
|
|
|
|
forward = yaw * forward;
|
|
|
|
} else {
|
2019-08-30 01:17:46 +02:00
|
|
|
forward = yaw + forward * 360;
|
2019-08-20 17:41:07 +02:00
|
|
|
}
|
|
|
|
yaw = (forward + sideways) / 2 % 360;
|
|
|
|
double radian = Math.toRadians(yaw + 90);
|
|
|
|
double cos = Math.cos(radian);
|
|
|
|
double sin = Math.sin(radian);
|
2019-08-30 01:17:46 +02:00
|
|
|
float x = (float) cos * speed;
|
|
|
|
float z = (float) sin * speed;
|
|
|
|
|
|
|
|
/*BlockPosition blockPosition = getPosition().toBlockPosition();
|
|
|
|
BlockPosition belowPosition = blockPosition.clone().add(0, -1, 0);
|
|
|
|
BlockPosition upPosition = blockPosition.clone().add(0, 1, 0);
|
|
|
|
boolean airCurrent = getInstance().getBlockId(blockPosition) == 0;
|
|
|
|
boolean airBelow = getInstance().getBlockId(belowPosition) == 0;
|
|
|
|
boolean airUp = getInstance().getBlockId(upPosition) == 0;
|
|
|
|
boolean shouldJump = false;
|
|
|
|
int boundingBoxY = (int) Math.ceil(getBoundingBox().getY());
|
|
|
|
for (int i = 0; i < boundingBoxY; i++) {
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
//System.out.println("test: "+player.isVehicleJump());
|
|
|
|
//System.out.println(getInstance().getBlockId(getPosition().toBlockPosition()));
|
|
|
|
|
|
|
|
move(x, 0, z, updateView);
|
2019-08-20 17:41:07 +02:00
|
|
|
}
|
2019-09-07 11:42:33 +02:00
|
|
|
} else {
|
|
|
|
move(randomX * speed, 0, randomZ * speed, true);
|
2019-08-30 01:17:46 +02:00
|
|
|
}
|
2019-08-29 02:15:52 +02:00
|
|
|
|
2019-08-30 01:17:46 +02:00
|
|
|
/*if (path == null) {
|
2019-08-29 02:15:52 +02:00
|
|
|
System.out.println("FIND PATH");
|
|
|
|
Player player = Main.getConnectionManager().getPlayer("Raulnil");
|
|
|
|
if (player != null) {
|
|
|
|
refreshPath(player);
|
|
|
|
this.target = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target == null) {
|
|
|
|
Cell cell = path.pollFirst();
|
|
|
|
if (cell != null) {
|
|
|
|
this.target = new Position(cell.getX(), cell.getY(), cell.getZ());
|
|
|
|
System.out.println("NEW TARGET");
|
|
|
|
} else {
|
|
|
|
path = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path != null && target != null) {
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
System.out.println("FINISHED PATH");
|
|
|
|
path = null;
|
|
|
|
} else {
|
|
|
|
float distance = getPosition().getDistance(target);
|
|
|
|
//System.out.println("DISTANCE: "+distance);
|
|
|
|
if (distance <= 1) {
|
|
|
|
System.out.println("RESET TARGET");
|
|
|
|
target = null;
|
|
|
|
} else {
|
|
|
|
//System.out.println("WALK");
|
|
|
|
moveTowards(target, speed);
|
|
|
|
}
|
|
|
|
}
|
2019-08-30 01:17:46 +02:00
|
|
|
}*/
|
2019-08-24 20:34:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void spawn() {
|
2019-08-27 20:49:11 +02:00
|
|
|
// setVelocity(new Vector(0, 1, 0), 3000);
|
2019-08-10 08:44:35 +02:00
|
|
|
}
|
2019-08-29 02:15:52 +02:00
|
|
|
|
|
|
|
private void refreshPath(Player target) {
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
Position position = getPosition();
|
|
|
|
Position targetPosition = target.getPosition();
|
|
|
|
CellSpace space = new CellSpace();
|
|
|
|
space.setGoalCell((int) targetPosition.getX(), (int) targetPosition.getY(), (int) targetPosition.getZ());
|
|
|
|
space.setStartCell((int) position.getX(), (int) position.getY(), (int) position.getZ());
|
|
|
|
|
|
|
|
CostBlockManager blockManager = new CostBlockManager(space);
|
|
|
|
blockManager.blockCell(space.makeNewCell(6, 6, 3));
|
|
|
|
blockManager.blockCell(space.makeNewCell(6, 5, 4));
|
|
|
|
|
|
|
|
Pathfinder pathfinder = new Pathfinder(blockManager);
|
|
|
|
|
|
|
|
this.path = pathfinder.findPath();
|
|
|
|
|
|
|
|
System.out.println("PATH FINDING: " + (System.currentTimeMillis() - time) + " ms");
|
|
|
|
}
|
2019-08-10 08:44:35 +02:00
|
|
|
}
|