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

View File

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

View File

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