Fix /npc polarbear message and simplify behavior map entities to work with /npc ai

This commit is contained in:
fullwall 2020-12-17 13:38:02 +08:00
parent fe7f6e373f
commit 0111600aa8
17 changed files with 49 additions and 103 deletions

View File

@ -74,8 +74,9 @@ public class Commands {
String output = "";
if (args.hasFlag('r')) {
trait.setRearing(!trait.isRearing());
output += Messaging
.tr(trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING);
output += Messaging.tr(
trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING,
npc.getName());
}
if (!output.isEmpty()) {
Messaging.send(sender, output);

View File

@ -107,8 +107,9 @@ public class Commands {
String output = "";
if (args.hasFlag('r')) {
trait.setRearing(!trait.isRearing());
output += Messaging
.tr(trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING);
output += Messaging.tr(
trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING,
npc.getName());
}
if (!output.isEmpty()) {
Messaging.send(sender, output);

View File

@ -136,8 +136,9 @@ public class Commands {
String output = "";
if (args.hasFlag('r')) {
trait.setRearing(!trait.isRearing());
output += Messaging
.tr(trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING);
output += Messaging.tr(
trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING,
npc.getName());
}
if (!output.isEmpty()) {
Messaging.send(sender, output);

View File

@ -166,8 +166,9 @@ public class Commands {
String output = "";
if (args.hasFlag('r')) {
trait.setRearing(!trait.isRearing());
output += Messaging
.tr(trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING);
output += Messaging.tr(
trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING,
npc.getName());
}
if (!output.isEmpty()) {
Messaging.send(sender, output);

View File

@ -336,8 +336,9 @@ public class Commands {
String output = "";
if (args.hasFlag('r')) {
trait.setRearing(!trait.isRearing());
output += Messaging
.tr(trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING);
output += Messaging.tr(
trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING,
npc.getName());
}
if (!output.isEmpty()) {
Messaging.send(sender, output);

View File

@ -1,10 +1,8 @@
package net.citizensnpcs.nms.v1_15_R1.entity;
import java.util.List;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftVillager;
@ -18,7 +16,6 @@ import net.citizensnpcs.nms.v1_15_R1.util.NMSImpl;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_15_R1.BehaviorController;
import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.DamageSource;
import net.minecraft.server.v1_15_R1.DataWatcherObject;
@ -26,6 +23,7 @@ import net.minecraft.server.v1_15_R1.Entity;
import net.minecraft.server.v1_15_R1.EntityBoat;
import net.minecraft.server.v1_15_R1.EntityHuman;
import net.minecraft.server.v1_15_R1.EntityLightning;
import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_15_R1.EntityTypes;
import net.minecraft.server.v1_15_R1.EntityVillager;
import net.minecraft.server.v1_15_R1.EnumHand;
@ -48,12 +46,10 @@ public class VillagerController extends MobEntityController {
}
public static class EntityVillagerNPC extends EntityVillager implements NPCHolder {
private TreeMap<?, ?> behaviorMap;
private boolean blockingATrade;
private boolean blockTrades = true;
boolean calledNMSHeight = false;
private final CitizensNPC npc;
private BehaviorController<EntityVillager> previousBehaviorController;
public EntityVillagerNPC(EntityTypes<? extends EntityVillager> types, World world) {
this(types, world, null);
@ -238,14 +234,7 @@ public class VillagerController extends MobEntityController {
@Override
public void mobTick() {
if (npc != null) {
if (this.behaviorMap == null || this.previousBehaviorController != this.getBehaviorController()) {
this.behaviorMap = NMSImpl.getBehaviorMap(this);
this.previousBehaviorController = this.getBehaviorController();
}
if (this.behaviorMap.size() > 0) {
this.behaviorMap.clear();
NMSImpl.clearGoals(npc, goalSelector, targetSelector);
}
NMSImpl.updateMinecraftAIState(npc, this);
}
super.mobTick();
if (npc != null) {

View File

@ -1,10 +1,8 @@
package net.citizensnpcs.nms.v1_15_R1.entity;
import java.util.List;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftWanderingTrader;
@ -25,6 +23,7 @@ import net.minecraft.server.v1_15_R1.Entity;
import net.minecraft.server.v1_15_R1.EntityBoat;
import net.minecraft.server.v1_15_R1.EntityHuman;
import net.minecraft.server.v1_15_R1.EntityLightning;
import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_15_R1.EntityTypes;
import net.minecraft.server.v1_15_R1.EntityVillagerTrader;
import net.minecraft.server.v1_15_R1.EnumHand;
@ -46,7 +45,6 @@ public class WanderingTraderController extends MobEntityController {
}
public static class EntityWanderingTraderNPC extends EntityVillagerTrader implements NPCHolder {
private TreeMap<?, ?> behaviorMap;
private boolean blockingATrade;
private boolean blockTrades = true;
boolean calledNMSHeight = false;
@ -234,12 +232,6 @@ public class WanderingTraderController extends MobEntityController {
@Override
public void mobTick() {
if (npc != null) {
if (this.behaviorMap == null) {
this.behaviorMap = NMSImpl.getBehaviorMap(this);
}
if (this.behaviorMap.size() > 0) {
this.behaviorMap.clear();
}
NMSImpl.updateMinecraftAIState(npc, this);
}
super.mobTick();

View File

@ -380,8 +380,9 @@ public class Commands {
String output = "";
if (args.hasFlag('r')) {
trait.setRearing(!trait.isRearing());
output += Messaging
.tr(trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING);
output += Messaging.tr(
trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING,
npc.getName());
}
if (!output.isEmpty()) {
Messaging.send(sender, output);

View File

@ -1855,8 +1855,18 @@ public class NMSImpl implements NMSBridge {
return;
if (npc.useMinecraftAI()) {
NMSImpl.restoreGoals(npc, entity.goalSelector, entity.targetSelector);
if (npc.data().has("behavior-map")) {
TreeMap behavior = npc.data().get("behavior-map");
getBehaviorMap(entity).putAll(behavior);
npc.data().remove("behavior-map");
}
} else {
NMSImpl.clearGoals(npc, entity.goalSelector, entity.targetSelector);
TreeMap behaviorMap = getBehaviorMap(entity);
if (behaviorMap.size() > 0) {
npc.data().set("behavior-map", new TreeMap(behaviorMap));
behaviorMap.clear();
}
}
}

View File

@ -1,7 +1,5 @@
package net.citizensnpcs.nms.v1_16_R3.entity;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
@ -16,7 +14,6 @@ import net.citizensnpcs.nms.v1_16_R3.util.NMSImpl;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_16_R3.BehaviorController;
import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.DamageSource;
import net.minecraft.server.v1_16_R3.Entity;
@ -41,9 +38,7 @@ public class HoglinController extends MobEntityController {
}
public static class EntityHoglinNPC extends EntityHoglin implements NPCHolder {
private TreeMap<?, ?> behaviorMap;
private final CitizensNPC npc;
private BehaviorController<EntityHoglin> previousBehaviorController;
public EntityHoglinNPC(EntityTypes<? extends EntityHoglin> types, World world) {
this(types, world, null);
@ -191,14 +186,7 @@ public class HoglinController extends MobEntityController {
@Override
public void mobTick() {
if (npc != null) {
if (this.behaviorMap == null || this.previousBehaviorController != this.getBehaviorController()) {
this.behaviorMap = NMSImpl.getBehaviorMap(this);
this.previousBehaviorController = this.getBehaviorController();
}
if (this.behaviorMap.size() > 0) {
this.behaviorMap.clear();
NMSImpl.clearGoals(npc, goalSelector, targetSelector);
}
NMSImpl.updateMinecraftAIState(npc, this);
setImmuneToZombification(npc.isProtected());
}
super.mobTick();

View File

@ -191,14 +191,7 @@ public class PiglinBruteController extends MobEntityController {
@Override
public void mobTick() {
if (npc != null) {
if (this.behaviorMap == null || this.previousBehaviorController != this.getBehaviorController()) {
this.behaviorMap = NMSImpl.getBehaviorMap(this);
this.previousBehaviorController = this.getBehaviorController();
}
if (this.behaviorMap.size() > 0) {
this.behaviorMap.clear();
NMSImpl.clearGoals(npc, goalSelector, targetSelector);
}
NMSImpl.updateMinecraftAIState(npc, this);
setImmuneToZombification(npc.isProtected());
}
super.mobTick();

View File

@ -1,7 +1,5 @@
package net.citizensnpcs.nms.v1_16_R3.entity;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
@ -16,7 +14,6 @@ import net.citizensnpcs.nms.v1_16_R3.util.NMSImpl;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_16_R3.BehaviorController;
import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.DamageSource;
import net.minecraft.server.v1_16_R3.Entity;
@ -41,9 +38,7 @@ public class PiglinController extends MobEntityController {
}
public static class EntityPiglinNPC extends EntityPiglin implements NPCHolder {
private TreeMap<?, ?> behaviorMap;
private final CitizensNPC npc;
private BehaviorController<EntityPiglin> previousBehaviorController;
public EntityPiglinNPC(EntityTypes<? extends EntityPiglin> types, World world) {
this(types, world, null);
@ -191,14 +186,7 @@ public class PiglinController extends MobEntityController {
@Override
public void mobTick() {
if (npc != null) {
if (this.behaviorMap == null || this.previousBehaviorController != this.getBehaviorController()) {
this.behaviorMap = NMSImpl.getBehaviorMap(this);
this.previousBehaviorController = this.getBehaviorController();
}
if (this.behaviorMap.size() > 0) {
this.behaviorMap.clear();
NMSImpl.clearGoals(npc, goalSelector, targetSelector);
}
NMSImpl.updateMinecraftAIState(npc, this);
setImmuneToZombification(npc.isProtected());
}
super.mobTick();

View File

@ -1,7 +1,6 @@
package net.citizensnpcs.nms.v1_16_R3.entity;
import java.util.List;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
@ -17,7 +16,6 @@ import net.citizensnpcs.nms.v1_16_R3.util.NMSImpl;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_16_R3.BehaviorController;
import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.DamageSource;
import net.minecraft.server.v1_16_R3.DataWatcherObject;
@ -50,12 +48,10 @@ public class VillagerController extends MobEntityController {
}
public static class EntityVillagerNPC extends EntityVillager implements NPCHolder {
private TreeMap<?, ?> behaviorMap;
private boolean blockingATrade;
private boolean blockTrades = true;
boolean calledNMSHeight = false;
private final CitizensNPC npc;
private BehaviorController<EntityVillager> previousBehaviorController;
public EntityVillagerNPC(EntityTypes<? extends EntityVillager> types, World world) {
this(types, world, null);
@ -240,14 +236,7 @@ public class VillagerController extends MobEntityController {
@Override
public void mobTick() {
if (npc != null) {
if (this.behaviorMap == null || this.previousBehaviorController != this.getBehaviorController()) {
this.behaviorMap = NMSImpl.getBehaviorMap(this);
this.previousBehaviorController = this.getBehaviorController();
}
if (this.behaviorMap.size() > 0) {
this.behaviorMap.clear();
NMSImpl.clearGoals(npc, goalSelector, targetSelector);
}
NMSImpl.updateMinecraftAIState(npc, this);
}
super.mobTick();
if (npc != null) {

View File

@ -1,7 +1,6 @@
package net.citizensnpcs.nms.v1_16_R3.entity;
import java.util.List;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
@ -48,7 +47,6 @@ public class WanderingTraderController extends MobEntityController {
}
public static class EntityWanderingTraderNPC extends EntityVillagerTrader implements NPCHolder {
private TreeMap<?, ?> behaviorMap;
private boolean blockingATrade;
private boolean blockTrades = true;
boolean calledNMSHeight = false;
@ -236,12 +234,6 @@ public class WanderingTraderController extends MobEntityController {
@Override
public void mobTick() {
if (npc != null) {
if (this.behaviorMap == null) {
this.behaviorMap = NMSImpl.getBehaviorMap(this);
}
if (this.behaviorMap.size() > 0) {
this.behaviorMap.clear();
}
NMSImpl.updateMinecraftAIState(npc, this);
}
super.mobTick();

View File

@ -1,7 +1,5 @@
package net.citizensnpcs.nms.v1_16_R3.entity;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
@ -16,7 +14,6 @@ import net.citizensnpcs.nms.v1_16_R3.util.NMSImpl;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_16_R3.BehaviorController;
import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.DamageSource;
import net.minecraft.server.v1_16_R3.Entity;
@ -41,9 +38,7 @@ public class ZoglinController extends MobEntityController {
}
public static class EntityZoglinNPC extends EntityZoglin implements NPCHolder {
private TreeMap<?, ?> behaviorMap;
private final CitizensNPC npc;
private BehaviorController<EntityZoglin> previousBehaviorController;
public EntityZoglinNPC(EntityTypes<? extends EntityZoglin> types, World world) {
this(types, world, null);
@ -191,14 +186,7 @@ public class ZoglinController extends MobEntityController {
@Override
public void mobTick() {
if (npc != null) {
if (this.behaviorMap == null || this.previousBehaviorController != this.getBehaviorController()) {
this.behaviorMap = NMSImpl.getBehaviorMap(this);
this.previousBehaviorController = this.getBehaviorController();
}
if (this.behaviorMap.size() > 0) {
this.behaviorMap.clear();
NMSImpl.clearGoals(npc, goalSelector, targetSelector);
}
NMSImpl.updateMinecraftAIState(npc, this);
}
super.mobTick();
if (npc != null) {

View File

@ -380,8 +380,9 @@ public class Commands {
String output = "";
if (args.hasFlag('r')) {
trait.setRearing(!trait.isRearing());
output += Messaging
.tr(trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING);
output += Messaging.tr(
trait.isRearing() ? Messages.POLAR_BEAR_REARING : Messages.POLAR_BEAR_STOPPED_REARING,
npc.getName());
}
if (!output.isEmpty()) {
Messaging.send(sender, output);

View File

@ -1828,8 +1828,18 @@ public class NMSImpl implements NMSBridge {
return;
if (npc.useMinecraftAI()) {
NMSImpl.restoreGoals(npc, entity.goalSelector, entity.targetSelector);
if (npc.data().has("behavior-map")) {
TreeMap behavior = npc.data().get("behavior-map");
getBehaviorMap(entity).putAll(behavior);
npc.data().remove("behavior-map");
}
} else {
NMSImpl.clearGoals(npc, entity.goalSelector, entity.targetSelector);
TreeMap behaviorMap = getBehaviorMap(entity);
if (behaviorMap.size() > 0) {
npc.data().set("behavior-map", new TreeMap(behaviorMap));
behaviorMap.clear();
}
}
}