Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: MidCoard/BetterAI
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1
Choose a base ref
...
head repository: MidCoard/BetterAI
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 12 commits
  • 39 files changed
  • 2 contributors

Commits on Aug 10, 2020

  1. bug fix

    MidCoard committed Aug 10, 2020
    Copy the full SHA
    a9cc77f View commit details

Commits on Aug 18, 2020

  1. update

    byxiaobai committed Aug 18, 2020
    Copy the full SHA
    b2f2951 View commit details
  2. Delete .gitignore

    byxiaobai authored Aug 18, 2020
    Copy the full SHA
    2c68270 View commit details
  3. Copy the full SHA
    7e15587 View commit details
  4. update

    byxiaobai committed Aug 18, 2020
    Copy the full SHA
    fb55b6b View commit details
  5. 去除冗余

    byxiaobai committed Aug 18, 2020
    Copy the full SHA
    403fd2d View commit details

Commits on Aug 19, 2020

  1. Copy the full SHA
    28dda12 View commit details

Commits on Aug 20, 2020

  1. update

    byxiaobai committed Aug 20, 2020
    Copy the full SHA
    2b9d374 View commit details

Commits on Sep 4, 2020

  1. add FocessZombieNavigation

    MidCoard committed Sep 4, 2020
    Copy the full SHA
    45d56fc View commit details
  2. Copy the full SHA
    e0b3a4e View commit details
  3. update 1.2

    MidCoard committed Sep 4, 2020
    Copy the full SHA
    d2a50cd View commit details

Commits on Sep 5, 2020

  1. update Command System

    MidCoard committed Sep 5, 2020
    Copy the full SHA
    df0c9fc View commit details
Showing with 1,608 additions and 391 deletions.
  1. +12 −0 .settings/org.eclipse.jdt.core.prefs
  2. +2 −1 BetterAI.iml
  3. BIN D:/[1.8.00]craftbukkit by boge/[1.8.00]craftbukkit by boge/plugins/BetterAI-1.2.jar
  4. +3 −3 pom.xml
  5. +62 −9 src/main/java/com/focess/betterai/BetterAI.java
  6. +47 −18 src/main/java/com/focess/betterai/command/BetterAICommand.java
  7. +17 −17 src/main/java/com/focess/betterai/goal/ZombieAttackPlayerGoal.java
  8. +9 −32 src/main/java/com/focess/betterai/goal/ZombieBlockGoal.java
  9. +32 −58 src/main/java/com/focess/betterai/goal/ZombieBlockPlaceGoal.java
  10. +21 −28 src/main/java/com/focess/betterai/goal/ZombieInteractBlockGoal.java
  11. +30 −10 src/main/java/com/focess/betterai/listener/EntityListener.java
  12. +155 −0 src/main/java/com/focess/betterai/navigation/FocessZombieNavigation.java
  13. +13 −0 src/main/java/com/focess/betterai/navigation/FocessZombiePath.java
  14. +72 −0 src/main/java/com/focess/betterai/navigation/FocessZombiePathMode.java
  15. +72 −0 src/main/java/com/focess/betterai/navigation/FocessZombiePathPoint.java
  16. +0 −150 src/main/java/com/focess/betterai/util/command/Command.java
  17. +0 −9 src/main/java/com/focess/betterai/util/command/CommandExecutor.java
  18. +0 −21 src/main/java/com/focess/betterai/util/command/ConsoleCommandExecutor.java
  19. +0 −21 src/main/java/com/focess/betterai/util/command/PlayerCommandExecutor.java
  20. +8 −10 src/main/java/com/focess/betterai/{util → utils}/BetterAIConfiguration.java
  21. +39 −0 src/main/java/com/focess/betterai/utils/PacketUtil.java
  22. +15 −0 src/main/java/com/focess/betterai/utils/ZombieUtil.java
  23. +229 −0 src/main/java/com/focess/betterai/utils/command/Command.java
  24. +11 −0 src/main/java/com/focess/betterai/utils/command/CommandExecutor.java
  25. +26 −0 src/main/java/com/focess/betterai/utils/command/CommandResult.java
  26. +6 −0 src/main/java/com/focess/betterai/utils/command/CommandResultExecutor.java
  27. +17 −0 src/main/java/com/focess/betterai/utils/command/ConsoleCommandExecutor.java
  28. +109 −0 src/main/java/com/focess/betterai/utils/command/DataCollection.java
  29. +34 −0 src/main/java/com/focess/betterai/utils/command/DataConverter.java
  30. +17 −0 src/main/java/com/focess/betterai/utils/command/PlayerCommandExecutor.java
  31. +361 −0 src/main/java/com/focess/betterai/utils/command/TabCompleter.java
  32. +31 −0 src/main/java/com/focess/betterai/utils/command/data/BooleanBuffer.java
  33. +9 −0 src/main/java/com/focess/betterai/utils/command/data/DataBuffer.java
  34. +51 −0 src/main/java/com/focess/betterai/utils/command/data/ObjectBuffer.java
  35. +37 −0 src/main/java/com/focess/betterai/utils/command/data/StringBuffer.java
  36. +28 −0 src/main/java/com/focess/betterai/utils/command/data/UUIDBuffer.java
  37. +29 −0 src/main/java/com/focess/betterai/utils/command/data/WorldBuffer.java
  38. +2 −2 src/main/resources/config.yml
  39. +2 −2 src/main/resources/plugin.yml
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
3 changes: 2 additions & 1 deletion BetterAI.iml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
<platformType>PAPER</platformType>
</autoDetectTypes>
</configuration>
</facet>
@@ -16,6 +16,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/libs" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
Binary file not shown.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>BetterAI</groupId>
<artifactId>BetterAI</artifactId>
<version>1.1</version>
<version>1.2</version>
<dependencies>
<dependency>
<groupId>BukkitAPI_SpigotAPI_NMS</groupId>
71 changes: 62 additions & 9 deletions src/main/java/com/focess/betterai/BetterAI.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,81 @@
package com.focess.betterai;

import com.focess.betterai.command.BetterAICommand;
import com.focess.betterai.goal.ZombieAttackPlayerGoal;
import com.focess.betterai.goal.ZombieBlockGoal;
import com.focess.betterai.goal.ZombieBlockPlaceGoal;
import com.focess.betterai.goal.ZombieInteractBlockGoal;
import com.focess.betterai.listener.EntityListener;
import com.focess.betterai.util.BetterAIConfiguration;
import com.focess.betterai.util.command.Command;
import org.bukkit.entity.Animals;
import com.focess.betterai.navigation.FocessZombieNavigation;
import com.focess.betterai.navigation.FocessZombiePathMode;
import com.focess.betterai.utils.BetterAIConfiguration;
import com.focess.betterai.utils.command.Command;
import com.focess.pathfinder.entity.EntityManager;
import com.focess.pathfinder.entity.FocessEntity;
import com.focess.pathfinder.goal.FocessGoalItem;
import com.focess.pathfinder.goal.GoalItem;
import com.focess.pathfinder.goal.GoalSelector;
import com.focess.pathfinder.goals.Goals;
import com.focess.pathfinder.navigation.path.mode.PathModes;
import com.focess.pathfinder.wrapped.WrappedEntityCreature;
import com.focess.pathfinder.wrapped.WrappedEntityInsentient;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Creature;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Zombie;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.zip.ZipFile;

public class BetterAI extends JavaPlugin {

private static BetterAI instance;

public static BetterAI getInstance() {
return instance;
}

public void onEnable(){
public void onEnable() {
instance = this;
loadConfig();

loadConfig();//加载配置文件
BetterAIConfiguration.loadDefault(this);
this.getServer().getPluginManager().registerEvents(new EntityListener(),this);

this.getServer().getPluginManager().registerEvents(new EntityListener(), this);
//注册事件

Command.register(new BetterAICommand());

PathModes.registerPathMode("FocessZombie", FocessZombiePathMode.class);
FocessGoalItem.registerGoalItem("ZombieBlockPlace", ZombieBlockPlaceGoal.class);
FocessGoalItem.registerGoalItem("ZombieBlock", ZombieBlockGoal.class);
for (World world:Bukkit.getWorlds())
for (Zombie zombie:world.getEntitiesByClass(Zombie.class)) {
FocessEntity entity = EntityManager.getFocessEntity(zombie);
GoalSelector goalSelector = entity.getGoalSelector();
// for (WrappedGoal wrappedGoal:goalSelector.getGoals())
// if (wrappedGoal.getPriority() == 2 && wrappedGoal.getGoalItems().contains(Goals.TARGET.NEAREST_ATTACKABLE_TARGET))
// goalSelector.removeExactGoal(wrappedGoal);
if (!goalSelector.containsGoal(Goals.JUMP.FLOAT))
goalSelector.addGoal(Goals.JUMP.FLOAT
.clear()
.writeEntityInsentient(WrappedEntityInsentient.getWrappedEntityInsentient(zombie))
.build(0, false));


//躲避太阳
goalSelector.addGoal(Goals.MOVE.FLEE_SUN.clear().writeEntityCreature(WrappedEntityCreature.getWrappedEntityCreature(zombie)).writeDouble(1.0).build(3, false));
goalSelector.addGoal(Goals.RESTRICT_SUN.clear().writeEntityCreature(WrappedEntityCreature.getWrappedEntityCreature(zombie)).build(2, false));
//破坏方块
goalSelector.addGoal(new FocessGoalItem(new ZombieBlockGoal(zombie)).build(1, false));
//放置方块
goalSelector.addGoal(new FocessGoalItem(new ZombieBlockPlaceGoal(zombie)).build(1, false));
entity.getNavigationManager().addNavigation("FocessZombie", new FocessZombieNavigation(entity));
//攻击玩家
goalSelector.addGoal(new FocessGoalItem(new ZombieAttackPlayerGoal(zombie)).build(0, false));

}
//注册指令
}

private void loadConfig() {
@@ -36,6 +88,7 @@ private void loadConfig() {

@Override
public void onDisable() {

Command.unregisterAllCommand();
Bukkit.getScheduler().cancelTasks(this);
}
}
65 changes: 47 additions & 18 deletions src/main/java/com/focess/betterai/command/BetterAICommand.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,70 @@
package com.focess.betterai.command;


import com.focess.betterai.util.command.Command;
import com.focess.betterai.util.command.PlayerCommandExecutor;
import com.focess.betterai.utils.command.Command;
import com.focess.betterai.utils.command.CommandResult;
import com.focess.betterai.utils.command.PlayerCommandExecutor;
import com.focess.betterai.utils.command.TabCompleter;
import com.focess.pathfinder.entity.EntityManager;
import com.focess.pathfinder.entity.FocessEntity;
import com.focess.pathfinder.goal.WrappedGoal;
import com.focess.pathfinder.navigation.FocessNavigation;
import com.google.common.collect.Lists;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Zombie;
import org.bukkit.permissions.Permission;

import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class BetterAICommand extends Command {
public BetterAICommand() {
super("betterai", Lists.newArrayList("bai"), "betterai.command");
}

@Override
protected List<String> getCompleteLists(CommandSender sender, String cmd, String[] args) {
return Lists.newArrayList();
public static final Permission DEFAULT = new Permission("betterai.command");

public BetterAICommand() {
super("betterai", Lists.newArrayList("bai"));
}

@Override
public void init() {
this.addExecutor(1,(PlayerCommandExecutor)(sender, args)->{
FocessEntity focessEntity = EntityManager.getFocessEntity(Bukkit.getEntity(UUID.fromString(args[0])));
for (WrappedGoal goal:focessEntity.getGoalSelector().getGoals())
sender.sendMessage(goal.getNmsGoal().getClass().getName() + ":" + goal.getPriority() + ":" + goal.getControls().toString());
},"show");
this.addExecutor(2,(PlayerCommandExecutor)(sender,args)->{
Integer pos = Integer.parseInt(args[1]);
FocessEntity focessEntity = EntityManager.getFocessEntity(Bukkit.getEntity(UUID.fromString(args[0])));
this.addExecutor(1, (PlayerCommandExecutor) (sender, args) -> {
FocessEntity focessEntity = EntityManager.getFocessEntity(Bukkit.getEntity(args.getUUID()));
for (WrappedGoal goal : focessEntity.getGoalSelector().getGoals())
sender.sendMessage(goal.getGoal().getClass().getName() + ":" + goal.getPriority() + ":" + goal.getControls().toString());
return CommandResult.ALLOW;
}, "show").addTabComplete(TabCompleter.EntityExceptPlayerUUID);
this.addExecutor(2, (PlayerCommandExecutor) (sender, args) -> {
int pos = args.getInt();
FocessEntity focessEntity = EntityManager.getFocessEntity(Bukkit.getEntity(args.getUUID()));
focessEntity.getGoalSelector().removeExactGoal(focessEntity.getGoalSelector().getGoals().get(pos));
sender.sendMessage("Successfully");
},"remove");
return CommandResult.ALLOW;
}, "remove").addTabComplete(TabCompleter.EntityExceptPlayerUUID);
this.addExecutor(3, (PlayerCommandExecutor) (sender, args) -> {
FocessEntity focessEntity = null;
for (Zombie zombie : sender.getWorld().getEntitiesByClass(Zombie.class)) {
focessEntity = EntityManager.getFocessEntity(zombie);
break;
}
sender.sendMessage(Objects.toString(focessEntity));
if (focessEntity != null)
focessEntity.getNavigationManager().getNavigation("FocessZombie").findPathTo(args.getInt(), args.getInt(), args.getInt(), 20);
return CommandResult.ALLOW;
}).addTabComplete(TabCompleter.CoordinateIntX,TabCompleter.CoordinateIntY,TabCompleter.CoordinateIntZ);
this.addExecutor(3, (PlayerCommandExecutor) (sender, args) -> {
FocessEntity focessEntity = null;
for (Zombie zombie : sender.getWorld().getEntitiesByClass(Zombie.class)) {
focessEntity = EntityManager.getFocessEntity(zombie);
break;
}
sender.sendMessage(Objects.toString(focessEntity));
if (focessEntity != null)
((FocessNavigation) focessEntity.getNavigationManager().getNavigation("FocessZombie")).moveTo(args.getInt(), args.getInt(), args.getInt(), 10);
return CommandResult.ALLOW;
}, "move").addTabComplete(TabCompleter.CoordinateIntX,TabCompleter.CoordinateIntY,TabCompleter.CoordinateIntZ).addCommandResult(CommandResult.POSITIVE, () -> {
System.out.println("Hello World");
});;
}

@Override
34 changes: 17 additions & 17 deletions src/main/java/com/focess/betterai/goal/ZombieAttackPlayerGoal.java
Original file line number Diff line number Diff line change
@@ -8,15 +8,21 @@

public class ZombieAttackPlayerGoal extends Goal {

private final FocessEntity zombie;

private static final int TIMEOUT = 30;

private final FocessEntity zombie;
private Entity target = null;
private int time = 0;

public ZombieAttackPlayerGoal(Zombie zombie ){
public ZombieAttackPlayerGoal(Zombie zombie) {
this.zombie = EntityManager.getFocessEntity(zombie);
this.addControl(Control.LOOK);
}

private static boolean isPlayer(Entity entity) {
if (!entity.getType().equals(EntityType.PLAYER))
return false;
Player player = (Player) entity;
return player.getGameMode().equals(GameMode.ADVENTURE) || player.getGameMode().equals(GameMode.SURVIVAL);
}

@Override
@@ -27,37 +33,31 @@ public boolean canStart() {

@Override
public boolean shouldContinue() {
return this.target !=null && this.zombie.getBukkitEntity().getLocation().distance(this.target.getLocation()) < 20;
return this.target != null && this.zombie.getBukkitEntity().getLocation().distance(this.target.getLocation()) < 20;
}

@Override
public void stop() {
this.target = null;
((Creature) this.zombie.getBukkitEntity()).setTarget((LivingEntity) this.target);
this.time = 0;
}

@Override
public void tick() {
this.time++;
if (this.time % TIMEOUT == 0){
if (this.time % TIMEOUT == 0) {
this.time = 0;
searchTarget();
}
((Creature)this.zombie.getBukkitEntity()).setTarget((LivingEntity) this.target);
((Creature) this.zombie.getBukkitEntity()).setTarget((LivingEntity) this.target);
}

private void searchTarget() {
this.zombie.getBukkitEntity().getNearbyEntities(20,20,20).stream().filter(ZombieAttackPlayerGoal::isPlayer).sorted((i, j)->{
this.zombie.getBukkitEntity().getNearbyEntities(12, 12, 12).stream().filter(ZombieAttackPlayerGoal::isPlayer).sorted((i, j) -> {
double distance1 = this.zombie.getBukkitEntity().getLocation().distance(i.getLocation());
double distance2 = this.zombie.getBukkitEntity().getLocation().distance(j.getLocation());
return Double.compare(distance1,distance2);
}).findFirst().ifPresent((entity)->target = entity);
}

private static boolean isPlayer(Entity entity) {
if (!entity.getType().equals(EntityType.PLAYER))
return false;
Player player = (Player) entity;
return player.getGameMode().equals(GameMode.ADVENTURE) || player.getGameMode().equals(GameMode.SURVIVAL);
return Double.compare(distance1, distance2);
}).findFirst().ifPresent((entity) -> target = entity);
}
}
41 changes: 9 additions & 32 deletions src/main/java/com/focess/betterai/goal/ZombieBlockGoal.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package com.focess.betterai.goal;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.focess.betterai.utils.PacketUtil;
import com.focess.pathfinder.core.util.NMSManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Zombie;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.inventory.ItemStack;

import java.lang.reflect.InvocationTargetException;

public class ZombieBlockGoal extends ZombieInteractBlockGoal {
private int breakTime;
private int breakSit;
@@ -33,7 +26,7 @@ public boolean canStart() {

@Override
public boolean shouldContinue() {
return this.breakTime<=30;
return this.breakTime <= 30;
}

@Override
@@ -45,50 +38,34 @@ public void start() {
@Override
public void stop() {
super.stop();
sendBreakAnimationPacket(-1);
}

private void sendBreakAnimationPacket(int breakSit) {
for (World world:Bukkit.getWorlds())
for (Player player:world.getEntitiesByClass(Player.class)) {
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.BLOCK_BREAK_ANIMATION);
packet.getIntegers().write(0,this.zombie.getID()).write(1,breakSit);
packet.getBlockPositionModifier().write(0,new BlockPosition(this.block.getLocation().toVector()));
if (this.block.getLocation().distanceSquared(player.getLocation()) < 1024D) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player,packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
PacketUtil.sendBreakAnimationPacket(this.zombie.getID(), this.block, -1);
}

@Override
public void tick() {
super.tick();
this.breakTime++;
int breakSit = (int)(this.breakTime / 3.0F);
int breakSit = (int) (this.breakTime / 3.0F);
if (breakSit != this.breakSit) {
this.sendBreakAnimationPacket(breakSit);
PacketUtil.sendBreakAnimationPacket(this.zombie.getID(), this.block, breakSit);
this.breakSit = breakSit;
}
if (this.breakTime == 30) {
EntityChangeBlockEvent event;
if (NMSManager.getVersionInt() < 13) {
try {
event = EntityChangeBlockEvent.class.getConstructor(LivingEntity.class, Block.class,Material.class).newInstance(this.zombie.getBukkitEntity(),this.block, Material.AIR);
event = EntityChangeBlockEvent.class.getConstructor(LivingEntity.class, Block.class, Material.class).newInstance(this.zombie.getBukkitEntity(), this.block, Material.AIR);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
else event = new EntityChangeBlockEvent(this.zombie.getBukkitEntity(),this.block,Bukkit.createBlockData(Material.AIR));
} else
event = new EntityChangeBlockEvent(this.zombie.getBukkitEntity(), this.block, Bukkit.createBlockData(Material.AIR));
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
start();
return;
}
Zombie z = (Zombie)this.zombie.getBukkitEntity();
Zombie z = (Zombie) this.zombie.getBukkitEntity();
for (ItemStack itemStack : this.block.getDrops())
z.getWorld().dropItem(new Location(z.getWorld(), this.block.getX(), this.block.getY(),
this.block.getZ()), itemStack);
Loading