Fix controllable NPCs and add -m flag to instamount

This commit is contained in:
fullwall 2013-07-03 12:36:52 +08:00
parent c6e9cfa58a
commit fde461489a
3 changed files with 18 additions and 9 deletions

View File

@ -205,7 +205,7 @@ public class NPCCommands {
modifiers = { "controllable", "control" },
min = 1,
max = 1,
flags = "f")
flags = "m")
public void controllable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if ((npc.isSpawned() && !sender.hasPermission("citizens.npc.controllable."
+ npc.getBukkitEntity().getType().toString().toLowerCase()))
@ -218,6 +218,9 @@ public class NPCCommands {
boolean enabled = trait.toggle();
String key = enabled ? Messages.CONTROLLABLE_SET : Messages.CONTROLLABLE_REMOVED;
Messaging.sendTr(sender, key, npc.getName());
if (enabled && args.hasFlag('m') && sender instanceof Player) {
trait.mount((Player) sender);
}
}
@Command(

View File

@ -22,7 +22,10 @@ import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_6_R1.EntityHuman;
import net.minecraft.server.v1_6_R1.EntityLiving;
import net.minecraft.server.v1_6_R1.EntityPlayer;
import net.minecraft.server.v1_6_R1.Packet20NamedEntitySpawn;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -213,6 +216,10 @@ public class CitizensNPC extends AbstractNPC {
trait.onSpawn();
getBukkitEntity().setRemoveWhenFarAway(false);
getBukkitEntity().setCustomName(getFullName());
if (mcEntity instanceof EntityPlayer) {
Packet20NamedEntitySpawn packet = new Packet20NamedEntitySpawn((EntityHuman) mcEntity);
NMS.sendToOnline(packet);
}
return true;
}

View File

@ -48,13 +48,13 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@Override
public void configure(CommandContext args) {
if (args.hasFlag('f'))
if (args.hasFlag('f')) {
explicitType = EntityType.BLAZE;
else if (args.hasFlag('g'))
} else if (args.hasFlag('g')) {
explicitType = EntityType.OCELOT;
else if (args.hasFlag('r'))
} else if (args.hasFlag('r')) {
explicitType = null;
else if (args.hasValueFlag("explicittype"))
} else if (args.hasValueFlag("explicittype"))
explicitType = Util.matchEntityType(args.getFlag("explicittype"));
if (npc.isSpawned())
loadController();
@ -123,7 +123,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!npc.isSpawned() || !enabled || !event.getPlayer().isSneaking())
if (!npc.isSpawned() || !enabled)
return;
EntityPlayer handle = ((CraftPlayer) event.getPlayer()).getHandle();
Action performed = event.getAction();
@ -255,7 +255,6 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
boolean onGround = handle.onGround;
float speedMod = npc.getNavigator().getDefaultParameters()
.modifiedSpeed((onGround ? GROUND_SPEED : AIR_SPEED));
updateSpeed(handle, speedMod);
setMountedYaw(handle);
}
@ -266,8 +265,8 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
if (horizontal > 0.0D) {
double dXcos = -Math.sin(handle.passenger.yaw * Math.PI / 180.0F);
double dXsin = Math.cos(handle.passenger.yaw * Math.PI / 180.0F);
handle.motX += dXcos * this.speed * 0.05;
handle.motZ += dXsin * this.speed * 0.05;
handle.motX += dXcos * this.speed * 0.5;
handle.motZ += dXsin * this.speed * 0.5;
}
handle.motX += handle.passenger.motX * speedMod;
handle.motZ += handle.passenger.motZ * speedMod;