Adjust /npc wither charged -> invulnerable, add arrow-shield

This commit is contained in:
fullwall 2022-09-08 13:28:14 +08:00
parent a70ca4fe8b
commit 1ccc2eae6d
14 changed files with 98 additions and 14 deletions

View File

@ -2804,7 +2804,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "wither (--charged [charged])",
usage = "wither (--invulnerable [true|false]) (--arrow-shield [true|false])",
desc = "Sets wither modifiers",
modifiers = { "wither" },
min = 1,
@ -2812,11 +2812,14 @@ public class NPCCommands {
max = 1,
permission = "citizens.npc.wither")
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER })
public void wither(CommandContext args, CommandSender sender, NPC npc, @Flag("charged") Boolean charged)
throws CommandException {
public void wither(CommandContext args, CommandSender sender, NPC npc, @Flag("invulnerable") Boolean invulnerable,
@Flag("arrow-shield") Boolean arrows) throws CommandException {
WitherTrait trait = npc.getOrAddTrait(WitherTrait.class);
if (charged != null) {
trait.setCharged(charged);
if (invulnerable != null) {
trait.setInvulnerable(invulnerable);
}
if (arrows != null) {
trait.setBlocksArrows(arrows);
}
}

View File

@ -14,26 +14,41 @@ import net.citizensnpcs.util.NMS;
*/
@TraitName("withertrait")
public class WitherTrait extends Trait {
@Persist("arrowshield")
private Boolean arrowShield;
@Persist("charged")
private boolean charged = false;
private Boolean invulnerable;
public WitherTrait() {
super("withertrait");
}
public boolean isCharged() {
return charged;
public Boolean blocksArrows() {
return arrowShield;
}
public boolean isInvulnerable() {
return invulnerable == null ? npc.isProtected() : invulnerable;
}
@Override
public void run() {
if (npc.getEntity() instanceof Wither) {
Wither wither = (Wither) npc.getEntity();
NMS.setWitherCharged(wither, charged);
if (!(npc.getEntity() instanceof Wither))
return;
Wither wither = (Wither) npc.getEntity();
NMS.setWitherInvulnerable(wither, invulnerable == null ? npc.isProtected() : invulnerable);
if (arrowShield != null) {
npc.data().set("wither-arrow-shield", arrowShield);
} else {
npc.data().remove("wither-arrow-shield");
}
}
public void setCharged(boolean charged) {
this.charged = charged;
public void setBlocksArrows(boolean arrowShield) {
this.arrowShield = arrowShield;
}
public void setInvulnerable(boolean invulnerable) {
this.invulnerable = invulnerable;
}
}

View File

@ -607,7 +607,7 @@ public class NMS {
BRIDGE.setVerticalMovement(bukkitEntity, d);
}
public static void setWitherCharged(Wither wither, boolean charged) {
public static void setWitherInvulnerable(Wither wither, boolean charged) {
BRIDGE.setWitherCharged(wither, charged);
}

View File

@ -64,6 +64,12 @@ public class WitherController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
public boolean df() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.df()
: npc.data().get("wither-arrow-damageable");
}
@Override
public void enderTeleportTo(double d0, double d1, double d2) {
if (npc == null)

View File

@ -64,6 +64,12 @@ public class WitherController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
public boolean di() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.di()
: npc.data().get("wither-arrow-damageable");
}
@Override
public void enderTeleportTo(double d0, double d1, double d2) {
if (npc == null)

View File

@ -65,6 +65,12 @@ public class WitherController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
public boolean dn() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.dn()
: npc.data().get("wither-arrow-damageable");
}
@Override
public void enderTeleportTo(double d0, double d1, double d2) {
if (npc == null) {

View File

@ -73,6 +73,12 @@ public class WitherController extends MobEntityController {
return NMSImpl.getSoundEffect(npc, super.D(), NPC.AMBIENT_SOUND_METADATA);
}
@Override
public boolean dA() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.dA()
: npc.data().get("wither-arrow-damageable");
}
@Override
public void enderTeleportTo(double d0, double d1, double d2) {
if (npc == null) {

View File

@ -66,6 +66,12 @@ public class WitherController extends MobEntityController {
return npc == null ? super.d(save) : false;
}
@Override
public boolean dW() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.dW()
: npc.data().get("wither-arrow-damageable");
}
@Override
public void enderTeleportTo(double d0, double d1, double d2) {
if (npc == null) {

View File

@ -129,6 +129,12 @@ public class WitherController extends MobEntityController {
return false; // shouldLeash
}
@Override
public boolean J_() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.J_()
: npc.data().get("wither-arrow-damageable");
}
@Override
public int l(int i) {
return npc == null ? super.l(i) : 0;

View File

@ -154,6 +154,12 @@ public class WitherController extends MobEntityController {
}
return super.n(entity);
}
@Override
public boolean S_() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.S_()
: npc.data().get("wither-arrow-damageable");
}
}
public static class WitherNPC extends CraftWither implements ForwardingNPCHolder {

View File

@ -132,6 +132,12 @@ public class WitherController extends MobEntityController {
return false; // shouldLeash
}
@Override
public boolean isPowered() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.isPowered()
: npc.data().get("wither-arrow-damageable");
}
@Override
public void push(double x, double y, double z) {
Vector vector = Util.callPushEvent(npc, x, y, z);

View File

@ -134,6 +134,12 @@ public class WitherController extends MobEntityController {
return false; // shouldLeash
}
@Override
public boolean isPowered() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.isPowered()
: npc.data().get("wither-arrow-damageable");
}
@Override
public void push(double x, double y, double z) {
Vector vector = Util.callPushEvent(npc, x, y, z);

View File

@ -126,6 +126,12 @@ public class WitherController extends MobEntityController {
return NMSImpl.isLeashed(this, super.isLeashed());
}
@Override
public boolean isPowered() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.isPowered()
: npc.data().get("wither-arrow-damageable");
}
@Override
public void push(double x, double y, double z) {
Vector vector = Util.callPushEvent(npc, x, y, z);

View File

@ -62,6 +62,12 @@ public class WitherController extends MobEntityController {
return false; // shouldLeash
}
@Override
public boolean cm() {
return npc == null || !npc.data().has("wither-arrow-damageable") ? super.cm()
: npc.data().<Boolean> get("wither-arrow-damageable");
}
@Override
public void collide(net.minecraft.server.v1_8_R3.Entity entity) {
// this method is called by both the entities involved - cancelling