Fix double updating bee/bat/ghast AI

This commit is contained in:
fullwall 2022-07-05 19:13:31 +08:00
parent dfbdfaed09
commit 35dd4078dd
25 changed files with 45 additions and 67 deletions

View File

@ -613,7 +613,7 @@ public class EventListen implements Listener {
if (npc == null) {
return;
}
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
event.setCancelled(npc.isProtected());
NPCVehicleDamageEvent damageEvent = new NPCVehicleDamageEvent(npc, event);
Bukkit.getPluginManager().callEvent(damageEvent);
@ -635,7 +635,7 @@ public class EventListen implements Listener {
if (npc == null) {
return;
}
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
event.setCancelled(npc.isProtected());
}
@EventHandler(ignoreCancelled = true)

View File

@ -2494,15 +2494,15 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "targetable",
usage = "targetable (-t(emporary))",
desc = "Toggles an NPC's targetability",
modifiers = { "targetable" },
min = 1,
max = 1,
flags = "t",
permission = "citizens.npc.targetable")
public void targetable(CommandContext args, CommandSender sender, NPC npc) {
boolean targetable = !npc.data().get(NPC.TARGETABLE_METADATA,
npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
boolean targetable = !npc.data().get(NPC.TARGETABLE_METADATA, npc.isProtected());
if (args.hasFlag('t')) {
npc.data().set(NPC.TARGETABLE_METADATA, targetable);
} else {
@ -2688,7 +2688,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "vulnerable (-t)",
usage = "vulnerable (-t(emporary))",
desc = "Toggles an NPC's vulnerability",
modifiers = { "vulnerable" },
min = 1,
@ -2696,7 +2696,7 @@ public class NPCCommands {
flags = "t",
permission = "citizens.npc.vulnerable")
public void vulnerable(CommandContext args, CommandSender sender, NPC npc) {
boolean vulnerable = !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
boolean vulnerable = !npc.isProtected();
if (args.hasFlag('t')) {
npc.data().set(NPC.DEFAULT_PROTECTED_METADATA, vulnerable);
} else {

View File

@ -183,8 +183,9 @@ public class EndermiteController extends MobEntityController {
@Override
public void mobTick() {
super.mobTick();
if (npc != null)
if (npc != null) {
npc.update();
}
}
@Override

View File

@ -154,8 +154,8 @@ public class BatController extends MobEntityController {
super.mobTick();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.mobTick();
}
npc.update();
}

View File

@ -153,10 +153,9 @@ public class BeeController extends MobEntityController {
super.mobTick();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.mobTick();
}
NMSImpl.updateAI(this);
npc.update();
}
}

View File

@ -184,9 +184,10 @@ public class EndermiteController extends MobEntityController {
@Override
public void mobTick() {
super.mobTick();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}
@Override

View File

@ -142,9 +142,6 @@ public class GhastController extends MobEntityController {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
}
super.mobTick();
}

View File

@ -147,8 +147,8 @@ public class BatController extends MobEntityController {
super.mobTick();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.mobTick();
}
npc.update();
}

View File

@ -146,10 +146,9 @@ public class BeeController extends MobEntityController {
super.mobTick();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.mobTick();
}
NMSImpl.updateAI(this);
npc.update();
}
}

View File

@ -177,9 +177,10 @@ public class EndermiteController extends MobEntityController {
@Override
public void mobTick() {
super.mobTick();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}
@Override

View File

@ -143,9 +143,6 @@ public class GhastController extends MobEntityController {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
}
super.mobTick();
}

View File

@ -76,8 +76,8 @@ public class BatController extends MobEntityController {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
npc.update();
}

View File

@ -75,10 +75,9 @@ public class BeeController extends MobEntityController {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
NMSImpl.updateAI(this);
npc.update();
}
}

View File

@ -90,9 +90,10 @@ public class EndermiteController extends MobEntityController {
@Override
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}
@Override

View File

@ -68,9 +68,6 @@ public class GhastController extends MobEntityController {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
}
super.customServerAiStep();
}

View File

@ -78,8 +78,8 @@ public class BatController extends MobEntityController {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
npc.update();
}

View File

@ -77,10 +77,9 @@ public class BeeController extends MobEntityController {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
NMSImpl.updateAI(this);
npc.update();
}
}

View File

@ -95,10 +95,6 @@ public class EndermanController extends MobEntityController {
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null) {
try {
} catch (Throwable e) {
e.printStackTrace();
}
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
}

View File

@ -91,9 +91,10 @@ public class EndermiteController extends MobEntityController {
@Override
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}
@Override

View File

@ -70,9 +70,6 @@ public class GhastController extends MobEntityController {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
}
super.customServerAiStep();
}

View File

@ -78,8 +78,8 @@ public class BatController extends MobEntityController {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
npc.update();
}

View File

@ -77,10 +77,9 @@ public class BeeController extends MobEntityController {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
NMSImpl.updateAI(this);
npc.update();
}
}

View File

@ -95,10 +95,6 @@ public class EndermanController extends MobEntityController {
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null) {
try {
} catch (Throwable e) {
e.printStackTrace();
}
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
}

View File

@ -91,9 +91,10 @@ public class EndermiteController extends MobEntityController {
@Override
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}
@Override

View File

@ -69,10 +69,7 @@ public class GhastController extends MobEntityController {
public void customServerAiStep() {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
NMSImpl.updateMinecraftAIState(npc, this);
}
super.customServerAiStep();
}