mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Fix some issues with controllable
This commit is contained in:
parent
86d6794b43
commit
afb7e13ee6
@ -199,15 +199,18 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
|
||||
return; // EnderDragon handles this separately
|
||||
Location loc = entity.getLocation();
|
||||
Vector vel = entity.getVelocity();
|
||||
if (vel.lengthSquared() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
double tX = loc.getX() + vel.getX();
|
||||
double tZ = loc.getZ() + vel.getZ();
|
||||
if (loc.getX() > tZ) {
|
||||
if (loc.getZ() > tZ) {
|
||||
loc.setYaw((float) -Math.toDegrees(Math.atan((loc.getX() - tX) / (loc.getZ() - tZ))) + 180F);
|
||||
} else if (loc.getZ() < tZ) {
|
||||
loc.setYaw((float) -Math.toDegrees(Math.atan((loc.getX() - tX) / (loc.getZ() - tZ))));
|
||||
}
|
||||
entity.teleport(loc);
|
||||
NMS.setHeadYaw(entity, loc.getYaw());
|
||||
NMS.look(entity, loc.getYaw(), loc.getPitch());
|
||||
}
|
||||
|
||||
public void setOwnerRequired(boolean ownerRequired) {
|
||||
@ -224,14 +227,27 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
|
||||
}
|
||||
|
||||
private double updateHorizontalSpeed(Entity handle, Entity passenger, double speed, float speedMod) {
|
||||
Vector hvel = handle.getVelocity();
|
||||
double oldSpeed = Math.sqrt(hvel.getX() * hvel.getX() + hvel.getZ() * hvel.getZ());
|
||||
double angle = Math.toRadians(passenger.getLocation().getYaw() - NMS.getVerticalMovement(passenger) * 45.0F);
|
||||
hvel = hvel.add(new Vector(speedMod * -Math.sin(angle) * NMS.getHorizontalMovement(passenger) * 0.05, 0,
|
||||
speedMod * Math.cos(angle) * NMS.getHorizontalMovement(passenger) * 0.05));
|
||||
handle.setVelocity(hvel);
|
||||
Vector vel = handle.getVelocity();
|
||||
double oldSpeed = Math.sqrt(vel.getX() * vel.getX() + vel.getZ() * vel.getZ());
|
||||
double horizontal = NMS.getHorizontalMovement(passenger);
|
||||
double yaw = passenger.getLocation().getYaw();
|
||||
if (horizontal > 0.0D) {
|
||||
double dXcos = -Math.sin(yaw * Math.PI / 180.0F);
|
||||
double dXsin = Math.cos(yaw * Math.PI / 180.0F);
|
||||
|
||||
vel = vel.setX(dXcos * speed * 0.5).setZ(dXsin * speed * 0.5);
|
||||
}
|
||||
vel = vel.add(
|
||||
new Vector(passenger.getVelocity().getX() * speedMod, 0D, passenger.getVelocity().getZ() * speedMod));
|
||||
|
||||
double newSpeed = Math.sqrt(vel.getX() * vel.getX() + vel.getZ() * vel.getZ());
|
||||
if (newSpeed > 0.35D) {
|
||||
double movementFactor = 0.35D / newSpeed;
|
||||
vel = vel.multiply(new Vector(movementFactor, 1, movementFactor));
|
||||
newSpeed = 0.35D;
|
||||
}
|
||||
handle.setVelocity(vel);
|
||||
|
||||
double newSpeed = Math.sqrt(hvel.getX() * hvel.getX() + hvel.getZ() * hvel.getZ());
|
||||
if (newSpeed > oldSpeed && speed < 0.35D) {
|
||||
return (float) Math.min(0.35D, (speed + ((0.35D - speed) / 35.0D)));
|
||||
} else {
|
||||
|
@ -86,6 +86,10 @@ public class NMS {
|
||||
return BRIDGE.getGameProfileRepository();
|
||||
}
|
||||
|
||||
public static float getHeadYaw(org.bukkit.entity.Entity entity) {
|
||||
return BRIDGE.getHeadYaw(entity);
|
||||
}
|
||||
|
||||
public static float getHorizontalMovement(org.bukkit.entity.Entity bukkitEntity) {
|
||||
return BRIDGE.getHorizontalMovement(bukkitEntity);
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ public interface NMSBridge {
|
||||
|
||||
public GameProfileRepository getGameProfileRepository();
|
||||
|
||||
public float getHeadYaw(Entity entity);
|
||||
|
||||
public float getHorizontalMovement(Entity entity);
|
||||
|
||||
public NPC getNPC(Entity entity);
|
||||
|
@ -13,6 +13,7 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.nms.v1_10_R1.util.NMSImpl;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.trait.Controllable;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.server.v1_10_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_10_R1.EntityLightning;
|
||||
@ -85,6 +86,14 @@ public class PigController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cP() {
|
||||
if (npc == null) {
|
||||
return super.cP();
|
||||
}
|
||||
return npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean d(NBTTagCompound save) {
|
||||
return npc == null ? super.d(save) : false;
|
||||
|
@ -332,6 +332,14 @@ public class NMSImpl implements NMSBridge {
|
||||
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeadYaw(org.bukkit.entity.Entity entity) {
|
||||
if (!(entity instanceof LivingEntity)) {
|
||||
return entity.getLocation().getYaw();
|
||||
}
|
||||
return getHandle((LivingEntity) entity).aQ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHorizontalMovement(org.bukkit.entity.Entity entity) {
|
||||
if (!entity.getType().isAlive())
|
||||
@ -1387,7 +1395,6 @@ public class NMSImpl implements NMSBridge {
|
||||
EntityType.GHAST);
|
||||
|
||||
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
||||
|
||||
private static final float DEFAULT_SPEED = 1F;
|
||||
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c");
|
||||
private static final Field ENDERDRAGON_BATTLE_FIELD = NMS.getField(EntityEnderDragon.class, "bK");
|
||||
|
@ -349,6 +349,14 @@ public class NMSImpl implements NMSBridge {
|
||||
return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeadYaw(org.bukkit.entity.Entity entity) {
|
||||
if (!(entity instanceof LivingEntity)) {
|
||||
return entity.getLocation().getYaw();
|
||||
}
|
||||
return getHandle((LivingEntity) entity).aP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHorizontalMovement(org.bukkit.entity.Entity entity) {
|
||||
if (!entity.getType().isAlive())
|
||||
@ -1429,7 +1437,6 @@ public class NMSImpl implements NMSBridge {
|
||||
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE,
|
||||
EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE,
|
||||
EntityType.GHAST);
|
||||
|
||||
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
||||
private static final float DEFAULT_SPEED = 1F;
|
||||
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c");
|
||||
@ -1446,6 +1453,7 @@ public class NMSImpl implements NMSBridge {
|
||||
private static final Field RABBIT_FIELD = NMS.getField(EntityRabbit.class, "bx");
|
||||
private static final Random RANDOM = Util.getFastRandom();
|
||||
private static Field SKULL_PROFILE_FIELD;
|
||||
|
||||
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
|
||||
|
||||
private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bF");
|
||||
|
Loading…
Reference in New Issue
Block a user