Use /npc item for minecarts, and add /npc hologram textshadow

This commit is contained in:
fullwall 2024-12-17 01:08:30 +08:00
parent 8d492ff0b2
commit a675406eae
18 changed files with 294 additions and 210 deletions

View File

@ -1281,7 +1281,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "hologram add [text] | insert [line #] [text] | set [line #] [text] | remove [line #] | bgcolor [line #] (red,green,blue(,alpha)) | clear | lineheight [height] | viewrange [range] | margintop [line #] [margin] | marginbottom [line #] [margin]",
usage = "hologram add [text] | insert [line #] [text] | set [line #] [text] | remove [line #] | textshadow [line #] | bgcolor [line #] (red,green,blue(,alpha)) | clear | lineheight [height] | viewrange [range] | margintop [line #] [margin] | marginbottom [line #] [margin]",
desc = "",
modifiers = { "hologram" },
min = 1,
@ -1290,8 +1290,8 @@ public class NPCCommands {
public void hologram(CommandContext args, CommandSender sender, NPC npc,
@Arg(
value = 1,
completions = { "add", "insert", "set", "bgcolor", "remove", "clear", "lineheight", "viewrange",
"margintop", "marginbottom" }) String action,
completions = { "add", "insert", "set", "bgcolor", "textshadow", "remove", "clear", "lineheight",
"viewrange", "margintop", "marginbottom" }) String action,
@Arg(value = 2, completionsProvider = HologramTrait.TabCompletions.class) String secondCompletion)
throws CommandException {
HologramTrait trait = npc.getOrAddTrait(HologramTrait.class);
@ -1332,6 +1332,21 @@ public class NPCCommands {
trait.setBackgroundColor(idx, Util.parseColor(args.getString(3)));
Messaging.sendTr(sender, Messages.HOLOGRAM_BACKGROUND_COLOR_SET, idx, args.getString(3));
}
} else if (action.equalsIgnoreCase("textshadow")) {
if (args.argsLength() == 3) {
trait.setDefaultTextShadow(!trait.isDefaultTextShadow());
Messaging.sendTr(sender, trait.isDefaultTextShadow() ? Messages.HOLOGRAM_DEFAULT_SHADOW_SET
: Messages.HOLOGRAM_DEFAULT_SHADOW_UNSET, npc.getName());
} else {
int idx = args.getString(2).equals("bottom") ? 0
: args.getString(2).equals("top") ? trait.getLines().size() - 1
: Math.max(0, args.getInteger(2));
if (idx >= trait.getLines().size())
throw new CommandException(Messages.HOLOGRAM_INVALID_LINE);
trait.setTextShadow(idx, Boolean.parseBoolean(args.getString(3)));
Messaging.sendTr(sender, Boolean.parseBoolean(args.getString(3)) ? Messages.HOLOGRAM_SHADOW_SET
: Messages.HOLOGRAM_SHADOW_UNSET, idx);
}
} else if (action.equalsIgnoreCase("viewrange")) {
if (args.argsLength() == 2)
throw new CommandUsageException();
@ -1566,9 +1581,9 @@ public class NPCCommands {
throws CommandException {
EntityType type = npc.getOrAddTrait(MobType.class).getType();
if (!type.name().equals("OMINOUS_ITEM_SPAWNER") && !type.name().contains("ITEM_FRAME")
&& !type.name().contains("ITEM_DISPLAY") && !type.name().contains("BLOCK_DISPLAY")
&& !type.name().equals("DROPPED_ITEM") && !type.name().equals("ITEM")
&& type != EntityType.FALLING_BLOCK)
&& !type.name().contains("MINECART") && !type.name().contains("ITEM_DISPLAY")
&& !type.name().contains("BLOCK_DISPLAY") && !type.name().equals("DROPPED_ITEM")
&& !type.name().equals("ITEM") && type != EntityType.FALLING_BLOCK)
throw new CommandException(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE, Util.prettyEnum(type));
ItemStack stack = args.hasFlag('h') ? ((Player) sender).getItemInHand() : new ItemStack(mat, 1);
if (modify != null) {
@ -1908,7 +1923,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "minecart (--item item_name(:data)) (--offset offset)",
usage = "minecart (--offset offset)",
desc = "",
modifiers = { "minecart" },
min = 1,
@ -1920,24 +1935,10 @@ public class NPCCommands {
throws CommandException {
if (!npc.getOrAddTrait(MobType.class).getType().name().contains("MINECRAFT"))
throw new CommandUsageException();
if (item != null) {
int data = 0;
if (item.contains(":")) {
int dataIndex = item.indexOf(':');
data = Integer.parseInt(item.substring(dataIndex + 1));
item = item.substring(0, dataIndex);
}
Material material = Material.matchMaterial(item);
if (material == null)
throw new CommandException();
npc.data().setPersistent(NPC.Metadata.MINECART_ITEM, material.name());
npc.data().setPersistent(NPC.Metadata.MINECART_ITEM_DATA, data);
}
if (args.hasValueFlag("offset")) {
npc.data().setPersistent(NPC.Metadata.MINECART_OFFSET, args.getFlagInteger("offset"));
}
Messaging.sendTr(sender, Messages.MINECART_SET, npc.data().get(NPC.Metadata.MINECART_ITEM, ""),
npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0), npc.data().get(NPC.Metadata.MINECART_OFFSET, 0));
Messaging.sendTr(sender, Messages.MINECART_SET, npc.getName(), npc.data().get(NPC.Metadata.MINECART_OFFSET, 0));
}
@Command(

View File

@ -82,9 +82,9 @@ public class CitizensNPCRegistry implements NPCRegistry {
public NPC createNPCUsingItem(EntityType type, String name, ItemStack item) {
NPC npc = createNPC(type, name);
if (type.name().equals("OMINOUS_ITEM_SPAWNER") || type.name().equals("DROPPED_ITEM")
|| type.name().equals("ITEM") || type == EntityType.FALLING_BLOCK || type == EntityType.ITEM_FRAME
|| type.name().equals("GLOW_ITEM_FRAME") || type.name().equals("ITEM_DISPLAY")
|| type.name().equals("BLOCK_DISPLAY")) {
|| type.name().contains("MINECART") || type.name().equals("ITEM") || type == EntityType.FALLING_BLOCK
|| type == EntityType.ITEM_FRAME || type.name().equals("GLOW_ITEM_FRAME")
|| type.name().equals("ITEM_DISPLAY") || type.name().equals("BLOCK_DISPLAY")) {
npc.data().set(NPC.Metadata.ITEM_AMOUNT, item.getAmount());
npc.data().set(NPC.Metadata.ITEM_ID, item.getType().name());
npc.data().set(NPC.Metadata.ITEM_DATA, item.getData().getData());

View File

@ -75,6 +75,8 @@ public class HologramTrait extends Trait {
private final NPCRegistry registry = CitizensAPI.getTemporaryNPCRegistry();
private int t;
@Persist
private boolean textShadow = true;
@Persist
private int viewRange = -1;
public HologramTrait() {
@ -226,6 +228,10 @@ public class HologramTrait extends Trait {
reloadLineHolograms();
}
public boolean isDefaultTextShadow() {
return textShadow;
}
@Override
public void load(DataKey root) {
clear();
@ -237,6 +243,9 @@ public class HologramTrait extends Trait {
if (key.keyExists("backgroundcolor")) {
line.setBackgroundColor(Color.fromARGB(key.getInt("backgroundcolor")));
}
if (key.keyExists("textshadow")) {
line.setTextShadow(key.getBoolean("textshadow"));
}
lines.add(line);
}
}
@ -355,6 +364,7 @@ public class HologramTrait extends Trait {
} else {
root.removeKey("lines." + i + ".backgroundcolor");
}
root.setBoolean("lines." + i + ".textshadow", line.shadow);
root.setString("lines." + i + ".text", line.text);
root.setDouble("lines." + i + ".margin.top", line.mt);
root.setDouble("lines." + i + ".margin.bottom", line.mb);
@ -377,6 +387,10 @@ public class HologramTrait extends Trait {
reloadLineHolograms();
}
public void setDefaultTextShadow(boolean shadow) {
this.textShadow = shadow;
}
/**
* Sets the hologram line at a specific index
*
@ -425,6 +439,11 @@ public class HologramTrait extends Trait {
reloadLineHolograms();
}
public void setTextShadow(int idx, boolean shadow) {
lines.get(idx).setTextShadow(shadow);
reloadLineHolograms();
}
public void setViewRange(int range) {
this.viewRange = range;
reloadLineHolograms();
@ -490,6 +509,7 @@ public class HologramTrait extends Trait {
double mb, mt;
boolean persist;
HologramRenderer renderer;
boolean shadow = textShadow;
String text;
int ticks;
@ -541,6 +561,14 @@ public class HologramTrait extends Trait {
}
renderer.updateText(npc, text);
}
public void setTextShadow(boolean shadow) {
this.shadow = shadow;
if (!shadow) {
renderer = new TextDisplayRenderer();
}
renderer.setTextShadow(shadow);
}
}
/**
@ -612,6 +640,9 @@ public class HologramTrait extends Trait {
default void setBackgroundColor(Color color) {
}
default void setTextShadow(boolean shadow) {
}
/**
* Update the hologram text. Will be called first before {@link #render(NPC, Vector3d)}.
*
@ -893,14 +924,11 @@ public class HologramTrait extends Trait {
public static class TextDisplayRenderer extends SingleEntityHologramRenderer {
private Color color;
private boolean shadow;
public TextDisplayRenderer() {
}
public TextDisplayRenderer(Color color) {
this.color = color;
}
@Override
protected NPC createNPC(Entity base, String name, Vector3d offset) {
NPC hologram = registry().createNPC(EntityType.TEXT_DISPLAY, "");
@ -918,6 +946,7 @@ public class HologramTrait extends Trait {
if (color != null) {
disp.setBackgroundColor(color);
}
disp.setShadowed(shadow);
if (SpigotUtil.getVersion()[1] >= 21 && base.getEntity() instanceof LivingEntity) {
AttributeInstance inst = ((LivingEntity) base.getEntity())
.getAttribute(Util.getRegistryValue(Registry.ATTRIBUTE, "generic.scale", "scale"));
@ -963,7 +992,9 @@ public class HologramTrait extends Trait {
}
private static final Pattern ITEM_MATCHER = Pattern.compile("<item:((?:minecraft:)?[a-zA-Z0-9_ ]*?)(:.*?)?>");
private static boolean SUPPORTS_DISPLAY = true;
static {
try {
Class.forName("org.bukkit.entity.Display");

View File

@ -169,6 +169,8 @@ public class Messages {
public static final String HOLOGRAM_BACKGROUND_COLOR_SET = "citizens.commands.npc.hologram.background-color-set";
public static final String HOLOGRAM_CLEARED = "citizens.commands.npc.hologram.cleared";
public static final String HOLOGRAM_DEFAULT_BACKGROUND_COLOR_SET = "citizens.commands.npc.hologram.default-background-color-set";
public static final String HOLOGRAM_DEFAULT_SHADOW_SET = "citizens.commands.npc.hologram.default-shadow-set";
public static final String HOLOGRAM_DEFAULT_SHADOW_UNSET = "citizens.commands.npc.hologram.default-shadow-unset";
public static final String HOLOGRAM_DESCRIBE_HEADER = "citizens.commands.npc.hologram.text-describe-header";
public static final String HOLOGRAM_INVALID_LINE = "citizens.commands.npc.hologram.invalid-text-id";
public static final String HOLOGRAM_LINE_ADD = "citizens.commands.npc.hologram.line-add";
@ -177,6 +179,8 @@ public class Messages {
public static final String HOLOGRAM_LINE_SET = "citizens.commands.npc.hologram.text-set";
public static final String HOLOGRAM_MARGIN_MISSING = "citizens.commands.npc.hologram.margin-missing";
public static final String HOLOGRAM_MARGIN_SET = "citizens.commands.npc.hologram.margin-set";
public static final String HOLOGRAM_SHADOW_SET = "citizens.commands.npc.hologram.shadow-set";
public static final String HOLOGRAM_SHADOW_UNSET = "citizens.commands.npc.hologram.shadow-unset";
public static final String HOLOGRAM_TEXT_MISSING = "citizens.commands.npc.hologram.text-missing";
public static final String HOLOGRAM_TEXT_REMOVED = "citizens.commands.npc.hologram.text-removed";
public static final String HOLOGRAM_VIEW_RANGE_SET = "citizens.commands.npc.hologram.view-range-set";

View File

@ -74,6 +74,10 @@
"citizens.commands.npc.axolotl.variant-set" : "Variant set to [[{0}]].",
"citizens.commands.npc.boat.type-set": "Boat type set to [[{0}]].",
"citizens.commands.npc.boat.description": "Sets boat modifiers",
"citizens.commands.npc.hologram.shadow-set" : "Line [[{0}]] now has text shadows.",
"citizens.commands.npc.hologram.shadow-unset" : "Line [[{0}]] no longer has text shadows.",
"citizens.commands.npc.hologram.default-shadow-set" : "[[{0}]]''s holograms now have text shadows by default.",
"citizens.commands.npc.hologram.default-shadow-unset" : "[[{0}]]''s holograms no longer have text shadows by default.",
"citizens.commands.npc.hologram.background-color-set": "Background color at line [[{0}]] set to [[{1}]].",
"citizens.commands.npc.hologram.default-background-color-set": "Default background color set to [[{0}]].",
"citizens.commands.npc.bee.anger-set" : "Anger set to [[{0}]].",
@ -337,7 +341,7 @@
"citizens.commands.npc.metadata.unset" : "Removed [[{0}]] from [[{1}]].",
"citizens.commands.npc.minecart.description" : "Sets minecart item",
"citizens.commands.npc.minecart.help" : "",
"citizens.commands.npc.minecart.set" : "[[{0}]] now has item [[{1}]]:[[{2}]] with offset [[{3}]].",
"citizens.commands.npc.minecart.set" : "[[{0}]] now has offset [[{1}]].",
"citizens.commands.npc.mirror.description" : "Controls mirroring of NPC skins and more",
"citizens.commands.npc.mirror.help" : "",
"citizens.commands.npc.mirror.namemirror-set" : "[[{0}]] will now mirror player names.",

View File

@ -18,7 +18,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -77,6 +76,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1593,16 +1593,21 @@ public class NMSImpl implements NMSBridge {
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ
|| what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw,
what.lastPitch);
Location to = new Location(what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw,
what.pitch);
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
@ -1856,12 +1861,11 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""));
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0);
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(data));
minecart.a(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(0));
}
minecart.setDisplayBlockOffset(offset);
}

View File

@ -18,7 +18,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -77,6 +76,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1652,16 +1652,21 @@ public class NMSImpl implements NMSBridge {
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ
|| what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw,
what.lastPitch);
Location to = new Location(what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw,
what.pitch);
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
@ -1914,12 +1919,11 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""));
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0);
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(data));
minecart.a(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(0));
}
minecart.setDisplayBlockOffset(offset);
}

View File

@ -19,7 +19,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -78,6 +77,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1660,16 +1660,21 @@ public class NMSImpl implements NMSBridge {
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ
|| what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw,
what.lastPitch);
Location to = new Location(what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw,
what.pitch);
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
@ -1922,12 +1927,11 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""));
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0);
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(data));
minecart.a(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlock(Block.getByCombinedId(mat.getId()).getBlock().getBlockData());
}
minecart.setDisplayBlockOffset(offset);
}

View File

@ -18,7 +18,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -79,6 +78,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1708,16 +1708,21 @@ public class NMSImpl implements NMSBridge {
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ
|| what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw,
what.lastPitch);
Location to = new Location(what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw,
what.pitch);
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
@ -2025,11 +2030,10 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""));
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0); // TODO: migration for this
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.a(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlock(Block.getByCombinedId(mat.getId()).getBlock().getBlockData());
}
minecart.setDisplayBlockOffset(offset);

View File

@ -17,7 +17,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -76,6 +75,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1805,16 +1805,21 @@ public class NMSImpl implements NMSBridge {
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ
|| what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw,
what.lastPitch);
Location to = new Location(what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw,
what.pitch);
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
@ -2099,11 +2104,10 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""));
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0); // TODO: migration for this
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.a(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlock(Block.getByCombinedId(mat.getId()).getBlock().getBlockData());
}
minecart.setDisplayBlockOffset(offset);

View File

@ -17,7 +17,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -76,6 +75,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1854,16 +1854,21 @@ public class NMSImpl implements NMSBridge {
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.lastX != what.locX() || what.lastY != what.locY() || what.lastZ != what.locZ() || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
Location to = new Location (what.world.getWorld(), what.locX(), what.locY(), what.locZ(), what.yaw, what.pitch);
if (what.lastX != what.locX() || what.lastY != what.locY() || what.lastZ != what.locZ()
|| what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw,
what.lastPitch);
Location to = new Location(what.world.getWorld(), what.locX(), what.locY(), what.locZ(), what.yaw,
what.pitch);
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
@ -2143,11 +2148,10 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""));
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0); // TODO: migration for this
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.a(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlock(Block.getByCombinedId(mat.getId()).getBlock().getBlockData());
}
minecart.setDisplayBlockOffset(offset);

View File

@ -17,7 +17,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -78,6 +77,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1874,16 +1874,21 @@ public class NMSImpl implements NMSBridge {
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.lastX != what.locX() || what.lastY != what.locY() || what.lastZ != what.locZ() || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
Location to = new Location (what.world.getWorld(), what.locX(), what.locY(), what.locZ(), what.yaw, what.pitch);
if (what.lastX != what.locX() || what.lastY != what.locY() || what.lastZ != what.locZ()
|| what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw,
what.lastPitch);
Location to = new Location(what.world.getWorld(), what.locX(), what.locY(), what.locZ(), what.yaw,
what.pitch);
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
@ -2135,11 +2140,10 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""));
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0); // TODO: migration for this
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.a(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlock(Block.getByCombinedId(mat.getId()).getBlock().getBlockData());
}
minecart.setDisplayBlockOffset(offset);

View File

@ -16,7 +16,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -73,6 +72,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1867,6 +1867,28 @@ public class NMSImpl implements NMSBridge {
}
}
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ()
|| what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
Location from = new Location(what.level.getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
Location to = new Location(what.level.getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(),
what.getXRot());
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
}
public static void checkAndUpdateHeight(LivingEntity living, EntityDataAccessor<?> datawatcherobject,
Consumer<EntityDataAccessor<?>> cb) {
EntityDimensions size;
@ -2037,24 +2059,6 @@ public class NMSImpl implements NMSBridge {
entity.calculateEntityAnimation(entity, entity instanceof net.minecraft.world.entity.animal.FlyingAnimal);
}
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
Location from = new Location(what.level.getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
Location to = new Location(what.level.getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), what.getXRot());
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
}
public static TreeMap<?, ?> getBehaviorMap(LivingEntity entity) {
try {
return (TreeMap<?, ?>) BEHAVIOR_MAP.invoke(entity.getBrain());
@ -2135,11 +2139,10 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""));
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0); // TODO: migration for this
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.setCustomDisplay(mat != null);
if (mat != null) {
minecart.setCustomDisplay(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlockState(Registry.BLOCK.byId(mat.getId()).defaultBlockState());
}
minecart.setDisplayOffset(offset);

View File

@ -15,7 +15,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -74,6 +73,7 @@ import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1875,6 +1875,28 @@ public class NMSImpl implements NMSBridge {
}
}
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ()
|| what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
Location from = new Location(what.level.getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
Location to = new Location(what.level.getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(),
what.getXRot());
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
}
public static void checkAndUpdateHeight(LivingEntity living, EntityDataAccessor<?> datawatcherobject,
Consumer<EntityDataAccessor<?>> cb) {
EntityDimensions size;
@ -2045,24 +2067,6 @@ public class NMSImpl implements NMSBridge {
entity.calculateEntityAnimation(entity, entity instanceof net.minecraft.world.entity.animal.FlyingAnimal);
}
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
Location from = new Location(what.level.getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
Location to = new Location(what.level.getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), what.getXRot());
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
}
public static TreeMap<?, ?> getBehaviorMap(LivingEntity entity) {
try {
return (TreeMap<?, ?>) BEHAVIOR_TREE_MAP.invoke(entity.getBrain());
@ -2143,11 +2147,10 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""), false);
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0); // TODO: migration for this
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.setCustomDisplay(mat != null);
if (mat != null) {
minecart.setCustomDisplay(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlockState(Registry.BLOCK.byId(mat.getId()).defaultBlockState());
}
minecart.setDisplayOffset(offset);

View File

@ -20,7 +20,6 @@ import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -81,6 +80,7 @@ import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -2079,6 +2079,28 @@ public class NMSImpl implements NMSBridge {
}
}
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ()
|| what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
Location from = new Location(what.level.getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
Location to = new Location(what.level.getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(),
what.getXRot());
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
}
public static void checkAndUpdateHeight(LivingEntity living, EntityDataAccessor<?> datawatcherobject,
Consumer<EntityDataAccessor<?>> cb) {
EntityDimensions size;
@ -2245,24 +2267,6 @@ public class NMSImpl implements NMSBridge {
entity.calculateEntityAnimation(entity instanceof net.minecraft.world.entity.animal.FlyingAnimal);
}
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
Location from = new Location(what.level.getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
Location to = new Location(what.level.getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), what.getXRot());
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
}
public static TreeMap<?, ?> getBehaviorMap(LivingEntity entity) {
try {
return (TreeMap<?, ?>) BEHAVIOR_TREE_MAP.invoke(entity.getBrain());
@ -2376,11 +2380,10 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""), false);
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0); // TODO: migration for this
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.setCustomDisplay(mat != null);
if (mat != null) {
minecart.setCustomDisplay(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlockState(BuiltInRegistries.BLOCK.byId(mat.getId()).defaultBlockState());
}
minecart.setDisplayOffset(offset);

View File

@ -18,7 +18,6 @@ import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -77,6 +76,7 @@ import net.citizensnpcs.api.astar.pathfinder.DoorExaminer;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -2119,6 +2119,29 @@ public class NMSImpl implements NMSBridge {
}
}
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ()
|| what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
Location from = new Location(what.level().getWorld(), what.xo, what.yo, what.zo, what.yRotO,
what.xRotO);
Location to = new Location(what.level().getWorld(), what.getX(), what.getY(), what.getZ(),
what.getYRot(), what.getXRot());
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
}
public static void checkAndUpdateHeight(LivingEntity living, EntityDataAccessor<?> datawatcherobject,
Consumer<EntityDataAccessor<?>> cb) {
EntityDimensions size;
@ -2321,24 +2344,6 @@ public class NMSImpl implements NMSBridge {
entity.calculateEntityAnimation(entity instanceof net.minecraft.world.entity.animal.FlyingAnimal);
}
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) {
Location from = new Location(what.level().getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO);
Location to = new Location(what.level().getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), what.getXRot());
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
}
public static TreeMap<?, ?> getBehaviorMap(LivingEntity entity) {
try {
return (TreeMap<?, ?>) AVAILABLE_BEHAVIORS_BY_PRIORITY.invoke(entity.getBrain());
@ -2450,11 +2455,10 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""), false);
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0); // TODO: migration for this
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.setCustomDisplay(mat != null);
if (mat != null) {
minecart.setCustomDisplay(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlockState(BuiltInRegistries.BLOCK.byId(mat.getId()).defaultBlockState());
}
minecart.setDisplayOffset(offset);

View File

@ -2339,11 +2339,10 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""), false);
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0); // TODO: migration for this
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.setCustomDisplay(mat != null);
if (mat != null) {
minecart.setCustomDisplay(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlockState(BuiltInRegistries.BLOCK.byId(mat.getId()).defaultBlockState());
}
minecart.setDisplayOffset(offset);

View File

@ -19,7 +19,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import net.citizensnpcs.api.event.NPCMoveEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -75,6 +74,7 @@ import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.command.CommandManager;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCMoveEvent;
import net.citizensnpcs.api.gui.ForwardingInventory;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -1524,16 +1524,21 @@ public class NMSImpl implements NMSBridge {
public static <T extends Entity & NPCHolder> void callNPCMoveEvent(T what) {
final NPC npc = what.getNPC();
if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) {
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ || what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw, what.lastPitch);
Location to = new Location (what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw, what.pitch);
if (what.lastX != what.locX || what.lastY != what.locY || what.lastZ != what.locZ
|| what.lastYaw != what.yaw || what.lastPitch != what.pitch) {
Location from = new Location(what.world.getWorld(), what.lastX, what.lastY, what.lastZ, what.lastYaw,
what.lastPitch);
Location to = new Location(what.world.getWorld(), what.locX, what.locY, what.locZ, what.yaw,
what.pitch);
final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
final Location eventFrom = event.getFrom();
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch());
what.setLocation(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(),
eventFrom.getPitch());
} else if (!to.equals(event.getTo())) {
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
what.setLocation(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(),
event.getTo().getYaw(), event.getTo().getPitch());
}
}
}
@ -1718,12 +1723,11 @@ public class NMSImpl implements NMSBridge {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.Metadata.MINECART_ITEM, ""));
int data = npc.data().get(NPC.Metadata.MINECART_ITEM_DATA, 0);
int offset = npc.data().get(NPC.Metadata.MINECART_OFFSET, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(data));
minecart.a(npc.getItemProvider().get() != null);
if (npc.getItemProvider().get() != null) {
Material mat = npc.getItemProvider().get().getType();
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(0));
}
minecart.SetDisplayBlockOffset(offset);
}