Add /npc minecart

This commit is contained in:
fullwall 2014-02-01 12:50:20 +08:00
parent d7f483ccf9
commit 29806e00e6
11 changed files with 71 additions and 7 deletions

View File

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.UUID;
import net.citizensnpcs.Citizens; import net.citizensnpcs.Citizens;
import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.Settings.Setting;
@ -689,6 +688,41 @@ public class NPCCommands {
: Messages.LOOKCLOSE_STOPPED, npc.getName()); : Messages.LOOKCLOSE_STOPPED, npc.getName());
} }
@Command(
aliases = { "npc" },
usage = "minecart (--item item_name(:data)) (--offset offset)",
desc = "Sets minecart item",
modifiers = { "minecart" },
min = 1,
max = 1,
flags = "",
permission = "citizens.npc.minecart")
@Requirements(selected = true, ownership = true, types = { EntityType.MINECART, EntityType.MINECART_CHEST,
EntityType.MINECART_COMMAND, EntityType.MINECART_FURNACE, EntityType.MINECART_HOPPER,
EntityType.MINECART_MOB_SPAWNER, EntityType.MINECART_TNT })
public void minecart(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (args.hasValueFlag("item")) {
String raw = args.getFlag("item");
int data = 0;
if (raw.contains(":")) {
int dataIndex = raw.indexOf(':');
data = Integer.parseInt(raw.substring(dataIndex + 1));
raw = raw.substring(0, dataIndex);
}
Material material = Material.matchMaterial(raw);
if (material == null)
throw new CommandException();
npc.data().setPersistent(NPC.MINECART_ITEM_METADATA, material.name());
npc.data().setPersistent(NPC.MINECART_ITEM_DATA_METADATA, data);
}
if (args.hasValueFlag("offset")) {
npc.data().setPersistent(NPC.MINECART_OFFSET_METADATA, args.getFlagInteger("offset"));
}
Messaging.sendTr(sender, Messages.MINECART_SET, npc.data().get(NPC.MINECART_ITEM_METADATA, ""),
npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0), npc.data().get(NPC.MINECART_OFFSET_METADATA, 0));
}
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "mount", usage = "mount",
@ -1489,10 +1523,4 @@ public class NPCCommands {
npc.getName()); npc.getName());
} }
} }
public static void main(String[] args) {
long bits = UUID.randomUUID().getLeastSignificantBits();
int id = (int) (bits & 0x7FFFFFFF);
System.err.println(id);
}
} }

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_7_R1.EntityMinecartChest; import net.minecraft.server.v1_7_R1.EntityMinecartChest;
import net.minecraft.server.v1_7_R1.World; import net.minecraft.server.v1_7_R1.World;
@ -87,6 +88,7 @@ public class MinecartChestController extends MobEntityController {
public void h() { public void h() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
NMS.minecartItemLogic(this);
} else { } else {
super.h(); super.h();
} }

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_7_R1.EntityMinecartCommandBlock; import net.minecraft.server.v1_7_R1.EntityMinecartCommandBlock;
import net.minecraft.server.v1_7_R1.World; import net.minecraft.server.v1_7_R1.World;
@ -87,6 +88,7 @@ public class MinecartCommandController extends MobEntityController {
public void h() { public void h() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
NMS.minecartItemLogic(this);
} else { } else {
super.h(); super.h();
} }

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_7_R1.EntityMinecartFurnace; import net.minecraft.server.v1_7_R1.EntityMinecartFurnace;
import net.minecraft.server.v1_7_R1.World; import net.minecraft.server.v1_7_R1.World;
@ -87,6 +88,7 @@ public class MinecartFurnaceController extends MobEntityController {
public void h() { public void h() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
NMS.minecartItemLogic(this);
} else { } else {
super.h(); super.h();
} }

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_7_R1.EntityMinecartHopper; import net.minecraft.server.v1_7_R1.EntityMinecartHopper;
import net.minecraft.server.v1_7_R1.World; import net.minecraft.server.v1_7_R1.World;
@ -75,6 +76,7 @@ public class MinecartHopperController extends MobEntityController {
public void h() { public void h() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
NMS.minecartItemLogic(this);
} else { } else {
super.h(); super.h();
} }

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_7_R1.EntityMinecartRideable; import net.minecraft.server.v1_7_R1.EntityMinecartRideable;
import net.minecraft.server.v1_7_R1.World; import net.minecraft.server.v1_7_R1.World;
@ -87,6 +88,7 @@ public class MinecartRideableController extends MobEntityController {
public void h() { public void h() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
NMS.minecartItemLogic(this);
} else { } else {
super.h(); super.h();
} }

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_7_R1.EntityMinecartMobSpawner; import net.minecraft.server.v1_7_R1.EntityMinecartMobSpawner;
import net.minecraft.server.v1_7_R1.World; import net.minecraft.server.v1_7_R1.World;
@ -75,6 +76,7 @@ public class MinecartSpawnerController extends MobEntityController {
public void h() { public void h() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
NMS.minecartItemLogic(this);
} else { } else {
super.h(); super.h();
} }

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_7_R1.EntityMinecartTNT; import net.minecraft.server.v1_7_R1.EntityMinecartTNT;
import net.minecraft.server.v1_7_R1.World; import net.minecraft.server.v1_7_R1.World;
@ -75,6 +76,7 @@ public class MinecartTNTController extends MobEntityController {
public void h() { public void h() {
if (npc != null) { if (npc != null) {
npc.update(); npc.update();
NMS.minecartItemLogic(this);
} else { } else {
super.h(); super.h();
} }

View File

@ -123,6 +123,7 @@ public class Messages {
public static final String LOOKCLOSE_SET = "citizens.commands.npc.lookclose.set"; public static final String LOOKCLOSE_SET = "citizens.commands.npc.lookclose.set";
public static final String LOOKCLOSE_STOPPED = "citizens.commands.npc.lookclose.stopped"; public static final String LOOKCLOSE_STOPPED = "citizens.commands.npc.lookclose.stopped";
public static final String METRICS_ERROR_NOTIFICATION = "citizens.notifications.metrics-load-error"; public static final String METRICS_ERROR_NOTIFICATION = "citizens.notifications.metrics-load-error";
public static final String MINECART_SET = "citizens.commands.npc.minecart.set";
public static final String MINIMUM_COST_REQUIRED = "citizens.economy.minimum-cost-required"; public static final String MINIMUM_COST_REQUIRED = "citizens.economy.minimum-cost-required";
public static final String MISSING_TRANSLATIONS = "citizens.notifications.missing-translations"; public static final String MISSING_TRANSLATIONS = "citizens.notifications.missing-translations";
public static final String MOBTYPE_CANNOT_BE_AGED = "citizens.commands.npc.age.cannot-be-aged"; public static final String MOBTYPE_CANNOT_BE_AGED = "citizens.commands.npc.age.cannot-be-aged";

View File

@ -13,6 +13,7 @@ import java.util.WeakHashMap;
import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.npc.entity.EntityHumanNPC; import net.citizensnpcs.npc.entity.EntityHumanNPC;
import net.citizensnpcs.npc.network.EmptyChannel; import net.citizensnpcs.npc.network.EmptyChannel;
import net.minecraft.server.v1_7_R1.AttributeInstance; import net.minecraft.server.v1_7_R1.AttributeInstance;
@ -24,6 +25,7 @@ import net.minecraft.server.v1_7_R1.EntityHorse;
import net.minecraft.server.v1_7_R1.EntityHuman; import net.minecraft.server.v1_7_R1.EntityHuman;
import net.minecraft.server.v1_7_R1.EntityInsentient; import net.minecraft.server.v1_7_R1.EntityInsentient;
import net.minecraft.server.v1_7_R1.EntityLiving; import net.minecraft.server.v1_7_R1.EntityLiving;
import net.minecraft.server.v1_7_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_7_R1.EntityPlayer; import net.minecraft.server.v1_7_R1.EntityPlayer;
import net.minecraft.server.v1_7_R1.EntityTypes; import net.minecraft.server.v1_7_R1.EntityTypes;
import net.minecraft.server.v1_7_R1.GenericAttributes; import net.minecraft.server.v1_7_R1.GenericAttributes;
@ -38,6 +40,7 @@ import net.minecraft.server.v1_7_R1.World;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_7_R1.CraftServer; import org.bukkit.craftbukkit.v1_7_R1.CraftServer;
import org.bukkit.craftbukkit.v1_7_R1.CraftSound; import org.bukkit.craftbukkit.v1_7_R1.CraftSound;
@ -278,6 +281,22 @@ public class NMS {
handle.pitch = pitch; handle.pitch = pitch;
} }
@SuppressWarnings("deprecation")
public static void minecartItemLogic(EntityMinecartAbstract minecart) {
NPC npc = ((NPCHolder) minecart).getNPC();
Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, ""));
int data = npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0);
int offset = npc.data().get(NPC.MINECART_OFFSET_METADATA, 0);
if (mat == null) {
minecart.a(false);
} else {
minecart.a(true);
minecart.k(mat.getId());
}
minecart.l(data);
minecart.m(offset);
}
public static float modifiedSpeed(float baseSpeed, NPC npc) { public static float modifiedSpeed(float baseSpeed, NPC npc) {
return npc == null ? baseSpeed : baseSpeed * npc.getNavigator().getLocalParameters().speedModifier(); return npc == null ? baseSpeed : baseSpeed * npc.getNavigator().getLocalParameters().speedModifier();
} }
@ -523,6 +542,7 @@ public class NMS {
private static Field NETWORK_CHANNEL = getField(NetworkManager.class, "k"); private static Field NETWORK_CHANNEL = getField(NetworkManager.class, "k");
private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
private static Field PATHFINDING_RANGE = getField(Navigation.class, "e"); private static Field PATHFINDING_RANGE = getField(Navigation.class, "e");
private static final Random RANDOM = Util.getFastRandom(); private static final Random RANDOM = Util.getFastRandom();
// true field above false and three synchronised lists // true field above false and three synchronised lists

View File

@ -57,6 +57,7 @@ citizens.commands.npc.leashable.set=[[{0}]] is now leashable.
citizens.commands.npc.leashable.stopped=[[{0}]] is no longer leashable. citizens.commands.npc.leashable.stopped=[[{0}]] is no longer leashable.
citizens.commands.npc.lookclose.set=[[{0}]] will now rotate when players are nearby. citizens.commands.npc.lookclose.set=[[{0}]] will now rotate when players are nearby.
citizens.commands.npc.lookclose.stopped=[[{0}]] will no longer rotate when players are nearby. citizens.commands.npc.lookclose.stopped=[[{0}]] will no longer rotate when players are nearby.
citizens.commands.npc.minecart.set=[[{0}]] now has item [[{1}]]:[[{2}]] with offset [[{3}]].
citizens.commands.npc.mount.failed=Couldn''t mount [[{0}]]. citizens.commands.npc.mount.failed=Couldn''t mount [[{0}]].
citizens.commands.npc.moveto.format=Format is x:y:z(:world) or x y z( world). citizens.commands.npc.moveto.format=Format is x:y:z(:world) or x y z( world).
citizens.commands.npc.moveto.teleported=[[{0}]] teleported to {1}. citizens.commands.npc.moveto.teleported=[[{0}]] teleported to {1}.