mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Improve /npc controllable with horses
This commit is contained in:
parent
2caadf5bad
commit
7cb7b36507
@ -14,12 +14,14 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.nms.v1_13_R2.util.NMSImpl;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.trait.Controllable;
|
||||
import net.citizensnpcs.trait.HorseModifiers;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.server.v1_13_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R2.DamageSource;
|
||||
import net.minecraft.server.v1_13_R2.EntityHorse;
|
||||
import net.minecraft.server.v1_13_R2.GenericAttributes;
|
||||
import net.minecraft.server.v1_13_R2.IBlockData;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
import net.minecraft.server.v1_13_R2.SoundEffect;
|
||||
@ -42,7 +44,9 @@ public class HorseController extends MobEntityController {
|
||||
}
|
||||
|
||||
public static class EntityHorseNPC extends EntityHorse implements NPCHolder {
|
||||
private double baseMovementSpeed;
|
||||
private final CitizensNPC npc;
|
||||
private boolean riding;
|
||||
|
||||
public EntityHorseNPC(World world) {
|
||||
this(world, null);
|
||||
@ -54,6 +58,7 @@ public class HorseController extends MobEntityController {
|
||||
if (npc != null) {
|
||||
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||
((Horse) getBukkitEntity()).setDomestication(((Horse) getBukkitEntity()).getMaxDomestication());
|
||||
baseMovementSpeed = this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,8 +90,18 @@ public class HorseController extends MobEntityController {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEffect cs() {
|
||||
return NMSImpl.getSoundEffect(npc, super.cs(), NPC.DEATH_SOUND_METADATA);
|
||||
public boolean bT() {
|
||||
if (npc != null && riding) {
|
||||
return true;
|
||||
}
|
||||
return super.bT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void c(float f, float f1) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.c(f, f1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -99,6 +114,11 @@ public class HorseController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEffect cs() {
|
||||
return NMSImpl.getSoundEffect(npc, super.cs(), NPC.DEATH_SOUND_METADATA);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEffect d(DamageSource damagesource) {
|
||||
return NMSImpl.getSoundEffect(npc, super.d(damagesource), NPC.HURT_SOUND_METADATA);
|
||||
@ -110,10 +130,8 @@ public class HorseController extends MobEntityController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void c(float f, float f1) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.c(f, f1);
|
||||
}
|
||||
protected SoundEffect D() {
|
||||
return NMSImpl.getSoundEffect(npc, super.D(), NPC.AMBIENT_SOUND_METADATA);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -151,11 +169,6 @@ public class HorseController extends MobEntityController {
|
||||
// cancelled.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEffect D() {
|
||||
return NMSImpl.getSoundEffect(npc, super.D(), NPC.AMBIENT_SOUND_METADATA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||
@ -169,6 +182,13 @@ public class HorseController extends MobEntityController {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void I() {
|
||||
if (npc == null) {
|
||||
super.I();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeashed() {
|
||||
if (npc == null)
|
||||
@ -182,17 +202,20 @@ public class HorseController extends MobEntityController {
|
||||
return false; // shouldLeash
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void I() {
|
||||
if (npc == null) {
|
||||
super.I();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mobTick() {
|
||||
super.mobTick();
|
||||
if (npc != null) {
|
||||
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
|
||||
riding = getBukkitEntity().getPassengers().size() > 0;
|
||||
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
|
||||
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());
|
||||
} else {
|
||||
riding = false;
|
||||
}
|
||||
if (riding) {
|
||||
d(4, true); // datawatcher method
|
||||
}
|
||||
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||
npc.update();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.trait.Controllable;
|
||||
import net.citizensnpcs.trait.HorseModifiers;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -22,6 +23,7 @@ import net.minecraft.server.v1_14_R1.DamageSource;
|
||||
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||
import net.minecraft.server.v1_14_R1.EntityHorse;
|
||||
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_14_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||
@ -45,9 +47,10 @@ public class HorseController extends MobEntityController {
|
||||
}
|
||||
|
||||
public static class EntityHorseNPC extends EntityHorse implements NPCHolder {
|
||||
boolean calledNMSHeight = false;
|
||||
|
||||
private double baseMovementSpeed;
|
||||
private boolean calledNMSHeight = false;
|
||||
private final CitizensNPC npc;
|
||||
private boolean riding;
|
||||
|
||||
public EntityHorseNPC(EntityTypes<? extends EntityHorse> types, World world) {
|
||||
this(types, world, null);
|
||||
@ -58,7 +61,9 @@ public class HorseController extends MobEntityController {
|
||||
this.npc = (CitizensNPC) npc;
|
||||
if (npc != null) {
|
||||
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||
((Horse) getBukkitEntity()).setDomestication(((Horse) getBukkitEntity()).getMaxDomestication());
|
||||
Horse horse = (Horse) getBukkitEntity();
|
||||
horse.setDomestication(horse.getMaxDomestication());
|
||||
baseMovementSpeed = this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,6 +92,14 @@ public class HorseController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ca() {
|
||||
if (npc != null && riding) {
|
||||
return true;
|
||||
}
|
||||
return super.ca();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkDespawn() {
|
||||
if (npc == null) {
|
||||
@ -207,6 +220,16 @@ public class HorseController extends MobEntityController {
|
||||
public void mobTick() {
|
||||
super.mobTick();
|
||||
if (npc != null) {
|
||||
if (npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled()) {
|
||||
riding = getBukkitEntity().getPassengers().size() > 0;
|
||||
getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
|
||||
.setValue(baseMovementSpeed * npc.getNavigator().getDefaultParameters().speedModifier());
|
||||
} else {
|
||||
riding = false;
|
||||
}
|
||||
if (riding) {
|
||||
d(4, true); // datawatcher method
|
||||
}
|
||||
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||
npc.update();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user