mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-27 22:58:41 +02:00
Preliminary 1.14 update
This commit is contained in:
parent
d08f56e6b1
commit
2d05ca134e
9
dist/pom.xml
vendored
9
dist/pom.xml
vendored
@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.citizensnpcs</groupId>
|
<groupId>net.citizensnpcs</groupId>
|
||||||
<artifactId>citizens-parent</artifactId>
|
<artifactId>citizens-parent</artifactId>
|
||||||
<version>2.0.24-SNAPSHOT</version>
|
<version>2.0.25-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>citizens</artifactId>
|
<artifactId>citizens</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
@ -79,5 +79,12 @@
|
|||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>citizens-v1_14_R1</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -6,13 +6,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.citizensnpcs</groupId>
|
<groupId>net.citizensnpcs</groupId>
|
||||||
<artifactId>citizens-parent</artifactId>
|
<artifactId>citizens-parent</artifactId>
|
||||||
<version>2.0.24-SNAPSHOT</version>
|
<version>2.0.25-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>citizens-main</artifactId>
|
<artifactId>citizens-main</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<craftbukkit.version>1.13.2-R0.1-SNAPSHOT</craftbukkit.version>
|
<craftbukkit.version>1.14-pre5-SNAPSHOT</craftbukkit.version>
|
||||||
<citizensapi.version>${project.version}</citizensapi.version>
|
<citizensapi.version>${project.version}</citizensapi.version>
|
||||||
<powermock.version>1.4.12</powermock.version>
|
<powermock.version>1.4.12</powermock.version>
|
||||||
<bstats.version>1.4</bstats.version>
|
<bstats.version>1.4</bstats.version>
|
||||||
|
@ -8,7 +8,6 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
@ -1269,7 +1268,7 @@ public class NPCCommands {
|
|||||||
Profession parsed = Util.matchEnum(Profession.values(), profession.toUpperCase());
|
Profession parsed = Util.matchEnum(Profession.values(), profession.toUpperCase());
|
||||||
if (parsed == null) {
|
if (parsed == null) {
|
||||||
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
|
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
|
||||||
StringUtils.join(Profession.values(), ","));
|
Joiner.on(',').join(Profession.values()));
|
||||||
}
|
}
|
||||||
npc.getTrait(VillagerProfession.class).setProfession(parsed);
|
npc.getTrait(VillagerProfession.class).setProfession(parsed);
|
||||||
Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession);
|
Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession);
|
||||||
@ -1288,7 +1287,7 @@ public class NPCCommands {
|
|||||||
try {
|
try {
|
||||||
type = Rabbit.Type.valueOf(args.getString(1).toUpperCase());
|
type = Rabbit.Type.valueOf(args.getString(1).toUpperCase());
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
throw new CommandException(Messages.INVALID_RABBIT_TYPE, StringUtils.join(Rabbit.Type.values(), ","));
|
throw new CommandException(Messages.INVALID_RABBIT_TYPE, Joiner.on(',').join(Rabbit.Type.values()));
|
||||||
}
|
}
|
||||||
npc.getTrait(RabbitType.class).setType(type);
|
npc.getTrait(RabbitType.class).setType(type);
|
||||||
Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());
|
Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());
|
||||||
|
@ -21,6 +21,9 @@ public class Messages {
|
|||||||
public static final String BEHAVIOURS_ADDED = "citizens.commands.npc.behaviour.added";
|
public static final String BEHAVIOURS_ADDED = "citizens.commands.npc.behaviour.added";
|
||||||
public static final String BEHAVIOURS_REMOVED = "citizens.commands.npc.behaviour.removed";
|
public static final String BEHAVIOURS_REMOVED = "citizens.commands.npc.behaviour.removed";
|
||||||
public static final String CANNOT_TELEPORT_ACROSS_WORLDS = "citizens.commands.npc.tphere.multiworld-not-allowed";
|
public static final String CANNOT_TELEPORT_ACROSS_WORLDS = "citizens.commands.npc.tphere.multiworld-not-allowed";
|
||||||
|
public static final String CAT_STARTED_SITTING = "citizens.commands.npc.cat.sitting-start";
|
||||||
|
public static final String CAT_STOPPED_SITTING = "citizens.commands.npc.cat.sitting-stop";
|
||||||
|
public static final String CAT_TYPE_SET = "citizens.commands.npc.cat.type-set";
|
||||||
public static final String CHAT_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.chat.prompt";
|
public static final String CHAT_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.chat.prompt";
|
||||||
public static final String CITIZENS_IMPLEMENTATION_DISABLED = "citizens.changed-implementation";
|
public static final String CITIZENS_IMPLEMENTATION_DISABLED = "citizens.changed-implementation";
|
||||||
public static final String CITIZENS_INCOMPATIBLE = "citizens.notifications.incompatible-version";
|
public static final String CITIZENS_INCOMPATIBLE = "citizens.notifications.incompatible-version";
|
||||||
@ -106,12 +109,14 @@ public class Messages {
|
|||||||
public static final String INVALID_AGE = "citizens.commands.npc.age.invalid-age";
|
public static final String INVALID_AGE = "citizens.commands.npc.age.invalid-age";
|
||||||
public static final String INVALID_ANCHOR_NAME = "citizens.commands.npc.anchor.invalid-name";
|
public static final String INVALID_ANCHOR_NAME = "citizens.commands.npc.anchor.invalid-name";
|
||||||
public static final String INVALID_ANIMATION = "citizens.editors.waypoints.triggers.animation.invalid-animation";
|
public static final String INVALID_ANIMATION = "citizens.editors.waypoints.triggers.animation.invalid-animation";
|
||||||
|
public static final String INVALID_CAT_TYPE = "citizens.commands.npc.cat.invalid-type";
|
||||||
public static final String INVALID_ENTITY_TYPE = "citizens.commands.npc.type.invalid";
|
public static final String INVALID_ENTITY_TYPE = "citizens.commands.npc.type.invalid";
|
||||||
public static final String INVALID_HORSE_COLOR = "citizens.commands.npc.horse.invalid-color";
|
public static final String INVALID_HORSE_COLOR = "citizens.commands.npc.horse.invalid-color";
|
||||||
public static final String INVALID_HORSE_STYLE = "citizens.commands.npc.horse.invalid-style";
|
public static final String INVALID_HORSE_STYLE = "citizens.commands.npc.horse.invalid-style";
|
||||||
public static final String INVALID_HORSE_VARIANT = "citizens.commands.npc.horse.invalid-variant";
|
public static final String INVALID_HORSE_VARIANT = "citizens.commands.npc.horse.invalid-variant";
|
||||||
public static final String INVALID_LLAMA_COLOR = "citizens.commands.npc.llama.invalid-color";
|
public static final String INVALID_LLAMA_COLOR = "citizens.commands.npc.llama.invalid-color";
|
||||||
public static final String INVALID_OCELOT_TYPE = "citizens.commands.npc.ocelot.invalid-type";
|
public static final String INVALID_OCELOT_TYPE = "citizens.commands.npc.ocelot.invalid-type";
|
||||||
|
public static final String INVALID_PANDA_GENE = "citizens.commands.npc.panda.invalid-gene";
|
||||||
public static final String INVALID_PARROT_VARIANT = "citizens.commands.npc.parrot.invalid-variant";
|
public static final String INVALID_PARROT_VARIANT = "citizens.commands.npc.parrot.invalid-variant";
|
||||||
public static final String INVALID_POSE_NAME = "citizens.commands.npc.pose.invalid-name";
|
public static final String INVALID_POSE_NAME = "citizens.commands.npc.pose.invalid-name";
|
||||||
public static final String INVALID_PROFESSION = "citizens.commands.npc.profession.invalid-profession";
|
public static final String INVALID_PROFESSION = "citizens.commands.npc.profession.invalid-profession";
|
||||||
@ -181,6 +186,8 @@ public class Messages {
|
|||||||
public static final String OVER_NPC_LIMIT = "citizens.limits.over-npc-limit";
|
public static final String OVER_NPC_LIMIT = "citizens.limits.over-npc-limit";
|
||||||
public static final String OWNER_SET = "citizens.commands.npc.owner.set";
|
public static final String OWNER_SET = "citizens.commands.npc.owner.set";
|
||||||
public static final String OWNER_SET_SERVER = "citizens.commands.npc.owner.set-server";
|
public static final String OWNER_SET_SERVER = "citizens.commands.npc.owner.set-server";
|
||||||
|
public static final String PANDA_HIDDEN_GENE_SET = "citizens.commands.npc.panda.hidden-gene-set";
|
||||||
|
public static final String PANDA_MAIN_GENE_SET = "citizens.commands.npc.panda.main-gene-set";
|
||||||
public static final String PARROT_VARIANT_SET = "citizens.commands.npc.parrot.variant-set";
|
public static final String PARROT_VARIANT_SET = "citizens.commands.npc.parrot.variant-set";
|
||||||
public static final String PASSIVE_SET = "citizens.commands.npc.passive.set";
|
public static final String PASSIVE_SET = "citizens.commands.npc.passive.set";
|
||||||
public static final String PASSIVE_UNSET = "citizens.commands.npc.passive.unset";
|
public static final String PASSIVE_UNSET = "citizens.commands.npc.passive.unset";
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.FishHook;
|
import org.bukkit.entity.FishHook;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Ocelot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.entity.Wither;
|
import org.bukkit.entity.Wither;
|
||||||
@ -294,6 +295,10 @@ public class NMS {
|
|||||||
BRIDGE.setShouldJump(entity);
|
BRIDGE.setShouldJump(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setSitting(Ocelot ocelot, boolean sitting) {
|
||||||
|
BRIDGE.setSitting(ocelot, sitting);
|
||||||
|
}
|
||||||
|
|
||||||
public static void setSitting(Tameable tameable, boolean sitting) {
|
public static void setSitting(Tameable tameable, boolean sitting) {
|
||||||
BRIDGE.setSitting(tameable, sitting);
|
BRIDGE.setSitting(tameable, sitting);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.FishHook;
|
import org.bukkit.entity.FishHook;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Ocelot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.entity.Wither;
|
import org.bukkit.entity.Wither;
|
||||||
@ -125,6 +126,8 @@ public interface NMSBridge {
|
|||||||
|
|
||||||
public void setShouldJump(Entity entity);
|
public void setShouldJump(Entity entity);
|
||||||
|
|
||||||
|
public void setSitting(Ocelot ocelot, boolean sitting);
|
||||||
|
|
||||||
public void setSitting(Tameable tameable, boolean sitting);
|
public void setSitting(Tameable tameable, boolean sitting);
|
||||||
|
|
||||||
public void setStepHeight(Entity entity, float height);
|
public void setStepHeight(Entity entity, float height);
|
||||||
|
@ -25,6 +25,10 @@ citizens.commands.npc.anchor.removed=Anchor removed.
|
|||||||
citizens.commands.npc.behaviour.added=Behaviours added.
|
citizens.commands.npc.behaviour.added=Behaviours added.
|
||||||
citizens.commands.npc.behaviour.help=The scripts argument is a comma-separated list of file names. Scripts will be loaded automatically and run every tick. Use the [[-r]] flag to remove behaviours.
|
citizens.commands.npc.behaviour.help=The scripts argument is a comma-separated list of file names. Scripts will be loaded automatically and run every tick. Use the [[-r]] flag to remove behaviours.
|
||||||
citizens.commands.npc.behaviour.removed=Behaviours removed.
|
citizens.commands.npc.behaviour.removed=Behaviours removed.
|
||||||
|
citizens.commands.npc.cat.invalid-type=Invalid type specified. Valid types are [[{0}]].
|
||||||
|
citizens.commands.npc.cat.sitting-start=[[{0}]] started sitting.
|
||||||
|
citizens.commands.npc.cat.sitting-stop=[[{0}]] stopped sitting.
|
||||||
|
citizens.commands.npc.cat.type-set=Type set to [[{0}]].
|
||||||
citizens.commands.npc.collidable.set=[[{0}]] will now collide with entities.
|
citizens.commands.npc.collidable.set=[[{0}]] will now collide with entities.
|
||||||
citizens.commands.npc.collidable.unset=[[{0}]] will no longer collide with entities.
|
citizens.commands.npc.collidable.unset=[[{0}]] will no longer collide with entities.
|
||||||
citizens.commands.npc.controllable.not-controllable=[[{0}]] is not controllable.
|
citizens.commands.npc.controllable.not-controllable=[[{0}]] is not controllable.
|
||||||
@ -82,6 +86,9 @@ citizens.commands.npc.owner.already-owner={0} is already the owner of [[{1}]].
|
|||||||
citizens.commands.npc.owner.owner=[[{0}]]''s owner is [[{1}]].
|
citizens.commands.npc.owner.owner=[[{0}]]''s owner is [[{1}]].
|
||||||
citizens.commands.npc.owner.set-server=[[The server]] is now the owner of [[{0}]].
|
citizens.commands.npc.owner.set-server=[[The server]] is now the owner of [[{0}]].
|
||||||
citizens.commands.npc.owner.set=[[{1}]] is now the owner of [[{0}]].
|
citizens.commands.npc.owner.set=[[{1}]] is now the owner of [[{0}]].
|
||||||
|
citizens.commands.npc.panda.invalid-gene=Invalid gene. Valid genes are [[{0}]].
|
||||||
|
citizens.commands.npc.panda.main-gene-set=Main gene set to [[{0}]].
|
||||||
|
citizens.commands.npc.panda.hidden-gene-set=Hidden gene set to [[{0}]].
|
||||||
citizens.commands.npc.passive.set=[[{0}]] will no longer damage entities.
|
citizens.commands.npc.passive.set=[[{0}]] will no longer damage entities.
|
||||||
citizens.commands.npc.passive.unset=[[{0}]] will now damage entities.
|
citizens.commands.npc.passive.unset=[[{0}]] will now damage entities.
|
||||||
citizens.commands.npc.pathfindingrange.set=Pathfinding range set to [[{0}]].
|
citizens.commands.npc.pathfindingrange.set=Pathfinding range set to [[{0}]].
|
||||||
|
@ -4,7 +4,7 @@ softdepend: [Vault]
|
|||||||
version: ${project.version} (build ${BUILD_NUMBER})
|
version: ${project.version} (build ${BUILD_NUMBER})
|
||||||
main: net.citizensnpcs.Citizens
|
main: net.citizensnpcs.Citizens
|
||||||
website: http://www.citizensnpcs.co
|
website: http://www.citizensnpcs.co
|
||||||
api-version: "1.13"
|
api-version: "1.14"
|
||||||
commands:
|
commands:
|
||||||
traitc:
|
traitc:
|
||||||
aliases: [trc]
|
aliases: [trc]
|
||||||
|
5
pom.xml
5
pom.xml
@ -7,10 +7,10 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<groupId>net.citizensnpcs</groupId>
|
<groupId>net.citizensnpcs</groupId>
|
||||||
<artifactId>citizens-parent</artifactId>
|
<artifactId>citizens-parent</artifactId>
|
||||||
<version>2.0.24-SNAPSHOT</version>
|
<version>2.0.25-SNAPSHOT</version>
|
||||||
<properties>
|
<properties>
|
||||||
<BUILD_NUMBER>Unknown</BUILD_NUMBER>
|
<BUILD_NUMBER>Unknown</BUILD_NUMBER>
|
||||||
<CITIZENS_VERSION>2.0.24</CITIZENS_VERSION>
|
<CITIZENS_VERSION>2.0.25</CITIZENS_VERSION>
|
||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean package install</defaultGoal>
|
<defaultGoal>clean package install</defaultGoal>
|
||||||
@ -22,6 +22,7 @@
|
|||||||
<module>v1_11_R1</module>
|
<module>v1_11_R1</module>
|
||||||
<module>v1_12_R1</module>
|
<module>v1_12_R1</module>
|
||||||
<module>v1_13_R2</module>
|
<module>v1_13_R2</module>
|
||||||
|
<module>v1_14_R1</module>
|
||||||
<module>dist</module>
|
<module>dist</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.citizensnpcs</groupId>
|
<groupId>net.citizensnpcs</groupId>
|
||||||
<artifactId>citizens-parent</artifactId>
|
<artifactId>citizens-parent</artifactId>
|
||||||
<version>2.0.24-SNAPSHOT</version>
|
<version>2.0.25-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>citizens-v1_10_R1</artifactId>
|
<artifactId>citizens-v1_10_R1</artifactId>
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.FishHook;
|
import org.bukkit.entity.FishHook;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Ocelot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Shulker;
|
import org.bukkit.entity.Shulker;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
@ -882,6 +883,11 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSitting(Ocelot ocelot, boolean sitting) {
|
||||||
|
setSitting((Tameable) ocelot, sitting);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSitting(Tameable tameable, boolean sitting) {
|
public void setSitting(Tameable tameable, boolean sitting) {
|
||||||
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);
|
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.citizensnpcs</groupId>
|
<groupId>net.citizensnpcs</groupId>
|
||||||
<artifactId>citizens-parent</artifactId>
|
<artifactId>citizens-parent</artifactId>
|
||||||
<version>2.0.24-SNAPSHOT</version>
|
<version>2.0.25-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>citizens-v1_11_R1</artifactId>
|
<artifactId>citizens-v1_11_R1</artifactId>
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ import org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.FishHook;
|
import org.bukkit.entity.FishHook;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Ocelot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Shulker;
|
import org.bukkit.entity.Shulker;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
@ -941,6 +942,11 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSitting(Ocelot ocelot, boolean sitting) {
|
||||||
|
setSitting((Tameable) ocelot, sitting);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSitting(Tameable tameable, boolean sitting) {
|
public void setSitting(Tameable tameable, boolean sitting) {
|
||||||
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);
|
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.citizensnpcs</groupId>
|
<groupId>net.citizensnpcs</groupId>
|
||||||
<artifactId>citizens-parent</artifactId>
|
<artifactId>citizens-parent</artifactId>
|
||||||
<version>2.0.24-SNAPSHOT</version>
|
<version>2.0.25-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>citizens-v1_12_R1</artifactId>
|
<artifactId>citizens-v1_12_R1</artifactId>
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ import org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.FishHook;
|
import org.bukkit.entity.FishHook;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Ocelot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Shulker;
|
import org.bukkit.entity.Shulker;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
@ -955,6 +956,11 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSitting(Ocelot ocelot, boolean sitting) {
|
||||||
|
setSitting((Tameable) ocelot, sitting);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSitting(Tameable tameable, boolean sitting) {
|
public void setSitting(Tameable tameable, boolean sitting) {
|
||||||
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);
|
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.citizensnpcs</groupId>
|
<groupId>net.citizensnpcs</groupId>
|
||||||
<artifactId>citizens-parent</artifactId>
|
<artifactId>citizens-parent</artifactId>
|
||||||
<version>2.0.24-SNAPSHOT</version>
|
<version>2.0.25-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>citizens-v1_13_R2</artifactId>
|
<artifactId>citizens-v1_13_R2</artifactId>
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
private void moveOnCurrentHeading() {
|
private void moveOnCurrentHeading() {
|
||||||
if (bg) {
|
if (bg) {
|
||||||
if (onGround && jumpTicks == 0) {
|
if (onGround && jumpTicks == 0) {
|
||||||
cG();
|
cH();
|
||||||
jumpTicks = 10;
|
jumpTicks = 10;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -190,7 +190,9 @@ public class RabbitController extends MobEntityController {
|
|||||||
public void mobTick() {
|
public void mobTick() {
|
||||||
if (npc != null) {
|
if (npc != null) {
|
||||||
super.mobTick();
|
super.mobTick();
|
||||||
|
if (npc.getNavigator().isNavigating()) {
|
||||||
NMS.setShouldJump(getBukkitEntity());
|
NMS.setShouldJump(getBukkitEntity());
|
||||||
|
}
|
||||||
npc.update();
|
npc.update();
|
||||||
} else {
|
} else {
|
||||||
super.mobTick();
|
super.mobTick();
|
||||||
|
@ -34,6 +34,7 @@ import org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.FishHook;
|
import org.bukkit.entity.FishHook;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Ocelot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Shulker;
|
import org.bukkit.entity.Shulker;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
@ -981,6 +982,11 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSitting(Ocelot ocelot, boolean sitting) {
|
||||||
|
setSitting((Tameable) ocelot, sitting);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSitting(Tameable tameable, boolean sitting) {
|
public void setSitting(Tameable tameable, boolean sitting) {
|
||||||
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);
|
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);
|
||||||
@ -988,7 +994,7 @@ public class NMSImpl implements NMSBridge {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStepHeight(org.bukkit.entity.Entity entity, float height) {
|
public void setStepHeight(org.bukkit.entity.Entity entity, float height) {
|
||||||
NMSImpl.getHandle(entity).P = height;
|
NMSImpl.getHandle(entity).Q = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1002,7 +1008,7 @@ public class NMSImpl implements NMSBridge {
|
|||||||
@Override
|
@Override
|
||||||
public void setWitherCharged(Wither wither, boolean charged) {
|
public void setWitherCharged(Wither wither, boolean charged) {
|
||||||
EntityWither handle = ((CraftWither) wither).getHandle();
|
EntityWither handle = ((CraftWither) wither).getHandle();
|
||||||
handle.g(charged ? 20 : 0);
|
handle.d(charged ? 20 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1320,7 +1326,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
} else {
|
} else {
|
||||||
float f9 = 0.91F;
|
float f9 = 0.91F;
|
||||||
BoundingBox bb = NMSBoundingBox.wrap(entity.getBoundingBox());
|
BoundingBox bb = NMSBoundingBox.wrap(entity.getBoundingBox());
|
||||||
BlockPosition.PooledBlockPosition blockposition_b = BlockPosition.PooledBlockPosition.d(entity.locX, bb.minY - 1.0D, entity.locZ);
|
BlockPosition.PooledBlockPosition blockposition_b = BlockPosition.PooledBlockPosition.d(entity.locX,
|
||||||
|
bb.minY - 1.0D, entity.locZ);
|
||||||
Throwable throwable = null;
|
Throwable throwable = null;
|
||||||
float f4;
|
float f4;
|
||||||
float f3;
|
float f3;
|
||||||
@ -1407,7 +1414,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
entity.aK += entity.aJ;
|
entity.aK += entity.aJ;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BlockPosition.PooledBlockPosition getBlockPositionBE(BlockPosition.PooledBlockPosition blockPos, double x, double y, double z) {
|
private static BlockPosition.PooledBlockPosition getBlockPositionBE(BlockPosition.PooledBlockPosition blockPos,
|
||||||
|
double x, double y, double z) {
|
||||||
try {
|
try {
|
||||||
return blockPos.c(x, y, z);
|
return blockPos.c(x, y, z);
|
||||||
} catch (NoSuchMethodError ex) {
|
} catch (NoSuchMethodError ex) {
|
||||||
@ -1596,7 +1604,7 @@ public class NMSImpl implements NMSBridge {
|
|||||||
|
|
||||||
public static void stopNavigation(NavigationAbstract navigation) {
|
public static void stopNavigation(NavigationAbstract navigation) {
|
||||||
navigation.q();
|
navigation.q();
|
||||||
}
|
};
|
||||||
|
|
||||||
public static void updateAI(EntityLiving entity) {
|
public static void updateAI(EntityLiving entity) {
|
||||||
if (entity instanceof EntityInsentient) {
|
if (entity instanceof EntityInsentient) {
|
||||||
@ -1609,7 +1617,7 @@ public class NMSImpl implements NMSBridge {
|
|||||||
} else if (entity instanceof EntityHumanNPC) {
|
} else if (entity instanceof EntityHumanNPC) {
|
||||||
((EntityHumanNPC) entity).updateAI();
|
((EntityHumanNPC) entity).updateAI();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
public static void updateNavigation(NavigationAbstract navigation) {
|
public static void updateNavigation(NavigationAbstract navigation) {
|
||||||
navigation.d();
|
navigation.d();
|
||||||
@ -1619,8 +1627,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
|
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
|
||||||
EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME,
|
EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME,
|
||||||
EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST);
|
EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST);
|
||||||
private static final Method BLOCK_POSITION_B_D = NMS.getMethod(BlockPosition.PooledBlockPosition.class, "e", false, double.class,
|
private static final Method BLOCK_POSITION_B_D = NMS.getMethod(BlockPosition.PooledBlockPosition.class, "e", false,
|
||||||
double.class, double.class);
|
double.class, double.class, double.class);
|
||||||
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
||||||
private static final float DEFAULT_SPEED = 1F;
|
private static final float DEFAULT_SPEED = 1F;
|
||||||
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c", false);
|
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c", false);
|
||||||
|
@ -43,7 +43,7 @@ public class PlayerControllerMove extends ControllerMove {
|
|||||||
double d2 = this.c - i;
|
double d2 = this.c - i;
|
||||||
double d3 = d0 * d0 + d2 * d2 + d1 * d1;
|
double d3 = d0 * d0 + d2 * d2 + d1 * d1;
|
||||||
if (d3 < 2.500000277905201E-007D) {
|
if (d3 < 2.500000277905201E-007D) {
|
||||||
this.a.bi = (0.0F);
|
this.a.bj = (0.0F); // bi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
|
float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
|
||||||
|
77
v1_14_R1/pom.xml
Normal file
77
v1_14_R1/pom.xml
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<!-- Citizens build file -->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>net.citizensnpcs</groupId>
|
||||||
|
<artifactId>citizens-parent</artifactId>
|
||||||
|
<version>2.0.25-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>citizens-v1_14_R1</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<craftbukkit.version>1.14-pre5-SNAPSHOT</craftbukkit.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>everything</id>
|
||||||
|
<url>http://repo.citizensnpcs.co</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>citizens-main</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>${craftbukkit.version}</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<defaultGoal>clean package install</defaultGoal>
|
||||||
|
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>2.3.2</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>2.3.2</version>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,179 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftBat;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Bat;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityBat;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class BatController extends MobEntityController {
|
||||||
|
public BatController() {
|
||||||
|
super(EntityBatNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Bat getBukkitEntity() {
|
||||||
|
return (Bat) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BatNPC extends CraftBat implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public BatNPC(EntityBatNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityBatNPC extends EntityBat implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityBatNPC(EntityTypes<? extends EntityBat> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityBatNPC(EntityTypes<? extends EntityBat> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
setFlying(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new BatNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null) {
|
||||||
|
return super.isLeashed();
|
||||||
|
}
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.mobTick();
|
||||||
|
} else {
|
||||||
|
NMSImpl.updateAI(this);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFlying(boolean flying) {
|
||||||
|
setAsleep(flying);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,170 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftBlaze;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Blaze;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityBlaze;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class BlazeController extends MobEntityController {
|
||||||
|
public BlazeController() {
|
||||||
|
super(EntityBlazeNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Blaze getBukkitEntity() {
|
||||||
|
return (Blaze) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BlazeNPC extends CraftBlaze implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public BlazeNPC(EntityBlazeNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityBlazeNPC extends EntityBlaze implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityBlazeNPC(EntityTypes<? extends EntityBlaze> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityBlazeNPC(EntityTypes<? extends EntityBlaze> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new BlazeNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftCat;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Cat;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityCat;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class CatController extends MobEntityController {
|
||||||
|
public CatController() {
|
||||||
|
super(EntityCatNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cat getBukkitEntity() {
|
||||||
|
return (Cat) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CatNPC extends CraftCat implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public CatNPC(EntityCatNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityCatNPC extends EntityCat implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityCatNPC(EntityTypes<? extends EntityCat> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityCatNPC(EntityTypes<? extends EntityCat> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new CatNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,215 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftCaveSpider;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.CaveSpider;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityCaveSpider;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class CaveSpiderController extends MobEntityController {
|
||||||
|
public CaveSpiderController() {
|
||||||
|
super(EntityCaveSpiderNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CaveSpider getBukkitEntity() {
|
||||||
|
return (CaveSpider) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CaveSpiderNPC extends CraftCaveSpider implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public CaveSpiderNPC(EntityCaveSpiderNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityCaveSpiderNPC(EntityTypes<? extends EntityCaveSpider> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityCaveSpiderNPC(EntityTypes<? extends EntityCaveSpider> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new CaveSpiderNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null) {
|
||||||
|
return super.isLeashed();
|
||||||
|
}
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) {
|
||||||
|
return super.isLeashed();
|
||||||
|
}
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,239 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftChicken;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Chicken;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityChicken;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class ChickenController extends MobEntityController {
|
||||||
|
public ChickenController() {
|
||||||
|
super(EntityChickenNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Chicken getBukkitEntity() {
|
||||||
|
return (Chicken) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ChickenNPC extends CraftChicken implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public ChickenNPC(EntityChickenNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityChickenNPC extends EntityChicken implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityChickenNPC(EntityTypes<? extends EntityChicken> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityChickenNPC(EntityTypes<? extends EntityChicken> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new ChickenNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void movementTick() {
|
||||||
|
if (npc != null) {
|
||||||
|
this.eggLayTime = 100; // egg timer
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
super.movementTick();
|
||||||
|
} catch (NoSuchMethodError ex) {
|
||||||
|
try {
|
||||||
|
MOVEMENT_TICK.invoke(this);
|
||||||
|
} catch (Throwable ex2) {
|
||||||
|
ex2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Method MOVEMENT_TICK = NMS.getMethod(EntityChicken.class, "k", false);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,208 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftCod;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Cod;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.ControllerMove;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityCod;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class CodController extends MobEntityController {
|
||||||
|
public CodController() {
|
||||||
|
super(EntityCodNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cod getBukkitEntity() {
|
||||||
|
return (Cod) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CodNPC extends CraftCod implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public CodNPC(EntityCodNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityCodNPC extends EntityCod implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityCodNPC(EntityTypes<? extends EntityCod> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityCodNPC(EntityTypes<? extends EntityCod> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
this.moveController = new ControllerMove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new CodNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.setNotInSchool(this);
|
||||||
|
}
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftCow;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Cow;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityCow;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class CowController extends MobEntityController {
|
||||||
|
public CowController() {
|
||||||
|
super(EntityCowNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cow getBukkitEntity() {
|
||||||
|
return (Cow) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CowNPC extends CraftCow implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public CowNPC(EntityCowNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityCowNPC extends EntityCow implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityCowNPC(EntityTypes<? extends EntityCow> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityCowNPC(EntityTypes<? extends EntityCow> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new CowNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,226 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftCreeper;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Creeper;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityCreeper;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityLightning;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class CreeperController extends MobEntityController {
|
||||||
|
public CreeperController() {
|
||||||
|
super(EntityCreeperNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Creeper getBukkitEntity() {
|
||||||
|
return (Creeper) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CreeperNPC extends CraftCreeper implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public CreeperNPC(EntityCreeperNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityCreeperNPC extends EntityCreeper implements NPCHolder {
|
||||||
|
private boolean allowPowered;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityCreeperNPC(EntityTypes<? extends EntityCreeper> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityCreeperNPC(EntityTypes<? extends EntityCreeper> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new CreeperNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightningStrike(EntityLightning entitylightning) {
|
||||||
|
if (npc == null || allowPowered) {
|
||||||
|
super.onLightningStrike(entitylightning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowPowered(boolean allowPowered) {
|
||||||
|
this.allowPowered = allowPowered;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,204 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftDolphin;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Dolphin;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityDolphin;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class DolphinController extends MobEntityController {
|
||||||
|
public DolphinController() {
|
||||||
|
super(EntityDolphinNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dolphin getBukkitEntity() {
|
||||||
|
return (Dolphin) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DolphinNPC extends CraftDolphin implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public DolphinNPC(EntityDolphinNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityDolphinNPC extends EntityDolphin implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityDolphinNPC(EntityTypes<? extends EntityDolphin> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityDolphinNPC(EntityTypes<? extends EntityDolphin> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
this.setNoAI(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new DolphinNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,203 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftDrowned;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Drowned;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityDrowned;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class DrownedController extends MobEntityController {
|
||||||
|
public DrownedController() {
|
||||||
|
super(EntityDrownedNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drowned getBukkitEntity() {
|
||||||
|
return (Drowned) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DrownedNPC extends CraftDrowned implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public DrownedNPC(EntityDrownedNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityDrownedNPC extends EntityDrowned implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityDrownedNPC(EntityTypes<? extends EntityDrowned> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityDrownedNPC(EntityTypes<? extends EntityDrowned> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new DrownedNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,186 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEnderDragon;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.EnderDragon;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityEnderDragon;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class EnderDragonController extends MobEntityController {
|
||||||
|
public EnderDragonController() {
|
||||||
|
super(EntityEnderDragonNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnderDragon getBukkitEntity() {
|
||||||
|
return (EnderDragon) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EnderDragonNPC extends CraftEnderDragon implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EnderDragonNPC(EntityEnderDragonNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityEnderDragonNPC(EntityTypes<? extends EntityEnderDragon> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEnderDragonNPC(EntityTypes<? extends EntityEnderDragon> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new EnderDragonNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getCorrectYaw(double tX, double tZ) {
|
||||||
|
if (locZ > tZ)
|
||||||
|
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ))));
|
||||||
|
if (locZ < tZ) {
|
||||||
|
return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))) + 180.0F;
|
||||||
|
}
|
||||||
|
return yaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void movementTick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
Vec3D mot = getMot();
|
||||||
|
if (mot.getX() != 0 || mot.getY() != 0 || mot.getZ() != 0) {
|
||||||
|
mot = mot.d(0.98, 0.98, 0.98);
|
||||||
|
yaw = getCorrectYaw(locX + mot.getX(), locZ + mot.getZ());
|
||||||
|
setPosition(locX + mot.getX(), locY + mot.getY(), locZ + mot.getZ());
|
||||||
|
setMot(mot);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.movementTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,220 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEnderman;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Enderman;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityEnderman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class EndermanController extends MobEntityController {
|
||||||
|
public EndermanController() {
|
||||||
|
super(EntityEndermanNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Enderman getBukkitEntity() {
|
||||||
|
return (Enderman) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EndermanNPC extends CraftEnderman implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EndermanNPC(EntityEndermanNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEndermanNPC extends EntityEnderman implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityEndermanNPC(EntityTypes<? extends EntityEnderman> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEndermanNPC(EntityTypes<? extends EntityEnderman> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean a(double d1, double d2, double d3, boolean b) {
|
||||||
|
if (npc == null) {
|
||||||
|
return super.a(d1, d2, d3, b);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new EndermanNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,211 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEndermite;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Endermite;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityEndermite;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class EndermiteController extends MobEntityController {
|
||||||
|
public EndermiteController() {
|
||||||
|
super(EntityEndermiteNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Endermite getBukkitEntity() {
|
||||||
|
return (Endermite) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EndermiteNPC extends CraftEndermite implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EndermiteNPC(EntityEndermiteNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEndermiteNPC extends EntityEndermite implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityEndermiteNPC(EntityTypes<? extends EntityEndermite> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEndermiteNPC(EntityTypes<? extends EntityEndermite> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new EndermiteNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null)
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,549 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
|
import net.citizensnpcs.Settings.Setting;
|
||||||
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.MetadataStore;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.api.trait.trait.Inventory;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.network.EmptyNetHandler;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.network.EmptyNetworkManager;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.network.EmptySocket;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.EmptyAdvancementDataPlayer;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.PlayerControllerJump;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.PlayerControllerLook;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.PlayerControllerMove;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.PlayerNavigation;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.npc.skin.SkinPacketTracker;
|
||||||
|
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||||
|
import net.citizensnpcs.trait.Gravity;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.AttributeInstance;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.ChatComponentText;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.Entity;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumGamemode;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumItemSlot;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumProtocolDirection;
|
||||||
|
import net.minecraft.server.v1_14_R1.GenericAttributes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
|
||||||
|
import net.minecraft.server.v1_14_R1.MathHelper;
|
||||||
|
import net.minecraft.server.v1_14_R1.MinecraftServer;
|
||||||
|
import net.minecraft.server.v1_14_R1.NavigationAbstract;
|
||||||
|
import net.minecraft.server.v1_14_R1.NetworkManager;
|
||||||
|
import net.minecraft.server.v1_14_R1.Packet;
|
||||||
|
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment;
|
||||||
|
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityHeadRotation;
|
||||||
|
import net.minecraft.server.v1_14_R1.PathType;
|
||||||
|
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||||
|
|
||||||
|
public class EntityHumanNPC extends EntityPlayer implements NPCHolder, SkinnableEntity {
|
||||||
|
private final Map<PathType, Float> bz = Maps.newEnumMap(PathType.class);
|
||||||
|
private PlayerControllerJump controllerJump;
|
||||||
|
private PlayerControllerLook controllerLook;
|
||||||
|
private PlayerControllerMove controllerMove;
|
||||||
|
private boolean isTracked = false;
|
||||||
|
private int jumpTicks = 0;
|
||||||
|
private PlayerNavigation navigation;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||||
|
private final SkinPacketTracker skinTracker;
|
||||||
|
private int updateCounter = 0;
|
||||||
|
|
||||||
|
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||||
|
PlayerInteractManager playerInteractManager, NPC npc) {
|
||||||
|
super(minecraftServer, world, gameProfile, playerInteractManager);
|
||||||
|
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
skinTracker = new SkinPacketTracker(this);
|
||||||
|
playerInteractManager.setGameMode(EnumGamemode.SURVIVAL);
|
||||||
|
initialise(minecraftServer);
|
||||||
|
} else {
|
||||||
|
skinTracker = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean a(EntityPlayer entityplayer) {
|
||||||
|
if (npc != null && !isTracked) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.a(entityplayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a(PathType pathtype) {
|
||||||
|
return this.bz.containsKey(pathtype) ? this.bz.get(pathtype).floatValue() : pathtype.a();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(PathType pathtype, float f) {
|
||||||
|
this.bz.put(pathtype, Float.valueOf(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean damageEntity(DamageSource damagesource, float f) {
|
||||||
|
// knock back velocity is cancelled and sent to client for handling when
|
||||||
|
// the entity is a player. there is no client so make this happen
|
||||||
|
// manually.
|
||||||
|
boolean damaged = super.damageEntity(damagesource, f);
|
||||||
|
if (damaged && velocityChanged) {
|
||||||
|
velocityChanged = false;
|
||||||
|
Bukkit.getScheduler().runTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
EntityHumanNPC.this.velocityChanged = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return damaged;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
super.die();
|
||||||
|
getAdvancementData().a();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die(DamageSource damagesource) {
|
||||||
|
// players that die are not normally removed from the world. when the
|
||||||
|
// NPC dies, we are done with the instance and it should be removed.
|
||||||
|
if (dead) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.die(damagesource);
|
||||||
|
Bukkit.getScheduler().runTaskLater(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
((WorldServer) world).removeEntity(EntityHumanNPC.this);
|
||||||
|
}
|
||||||
|
}, 35); // give enough time for death and smoke animation
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftPlayer getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new PlayerNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerControllerJump getControllerJump() {
|
||||||
|
return controllerJump;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerControllerMove getControllerMove() {
|
||||||
|
return controllerMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NavigationAbstract getNavigation() {
|
||||||
|
return navigation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IChatBaseComponent getPlayerListName() {
|
||||||
|
if (Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()) {
|
||||||
|
return new ChatComponentText("");
|
||||||
|
}
|
||||||
|
return super.getPlayerListName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSkinName() {
|
||||||
|
MetadataStore meta = npc.data();
|
||||||
|
|
||||||
|
String skinName = meta.get(NPC.PLAYER_SKIN_UUID_METADATA);
|
||||||
|
if (skinName == null) {
|
||||||
|
skinName = ChatColor.stripColor(getName());
|
||||||
|
}
|
||||||
|
return skinName.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SkinPacketTracker getSkinTracker() {
|
||||||
|
return skinTracker;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialise(MinecraftServer minecraftServer) {
|
||||||
|
Socket socket = new EmptySocket();
|
||||||
|
NetworkManager conn = null;
|
||||||
|
try {
|
||||||
|
conn = new EmptyNetworkManager(EnumProtocolDirection.CLIENTBOUND);
|
||||||
|
playerConnection = new EmptyNetHandler(minecraftServer, conn, this);
|
||||||
|
conn.setPacketListener(playerConnection);
|
||||||
|
socket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// swallow
|
||||||
|
}
|
||||||
|
|
||||||
|
AttributeInstance range = getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
|
||||||
|
if (range == null) {
|
||||||
|
range = getAttributeMap().b(GenericAttributes.FOLLOW_RANGE);
|
||||||
|
}
|
||||||
|
range.setValue(Setting.DEFAULT_PATHFINDING_RANGE.asDouble());
|
||||||
|
|
||||||
|
controllerJump = new PlayerControllerJump(this);
|
||||||
|
controllerLook = new PlayerControllerLook(this);
|
||||||
|
controllerMove = new PlayerControllerMove(this);
|
||||||
|
navigation = new PlayerNavigation(this, world);
|
||||||
|
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
|
||||||
|
setSkinFlags((byte) 0xFF);
|
||||||
|
|
||||||
|
EmptyAdvancementDataPlayer.clear(this.getAdvancementData());
|
||||||
|
NMSImpl.setAdvancement(this.getBukkitEntity(),
|
||||||
|
new EmptyAdvancementDataPlayer(minecraftServer, CitizensAPI.getDataFolder().getParentFile(), this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCollidable() {
|
||||||
|
return npc == null ? super.isCollidable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNavigating() {
|
||||||
|
return npc.getNavigator().isNavigating();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void livingEntityBaseTick() {
|
||||||
|
entityBaseTick();
|
||||||
|
this.aB = this.aC;
|
||||||
|
if (this.hurtTicks > 0) {
|
||||||
|
this.hurtTicks -= 1;
|
||||||
|
}
|
||||||
|
tickPotionEffects();
|
||||||
|
this.aW = this.aV;
|
||||||
|
this.aL = this.aK;
|
||||||
|
this.aN = this.aM;
|
||||||
|
this.lastYaw = this.yaw;
|
||||||
|
this.lastPitch = this.pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveOnCurrentHeading() {
|
||||||
|
if (jumping) {
|
||||||
|
if (onGround && jumpTicks == 0) {
|
||||||
|
jump();
|
||||||
|
jumpTicks = 10;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
jumpTicks = 0;
|
||||||
|
}
|
||||||
|
bb *= 0.98F;
|
||||||
|
bd *= 0.98F;
|
||||||
|
be *= 0.9F;
|
||||||
|
e(new Vec3D(this.bb, this.bc, this.bd)); // movement method
|
||||||
|
NMS.setHeadYaw(getBukkitEntity(), yaw);
|
||||||
|
if (jumpTicks > 0) {
|
||||||
|
jumpTicks--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMoveDestination(double x, double y, double z, double speed) {
|
||||||
|
controllerMove.a(x, y, z, speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShouldJump() {
|
||||||
|
controllerJump.jump();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkinFlags(byte flags) {
|
||||||
|
// set skin flag byte
|
||||||
|
getDataWatcher().set(EntityHuman.bt, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkinName(String name) {
|
||||||
|
setSkinName(name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkinName(String name, boolean forceUpdate) {
|
||||||
|
Preconditions.checkNotNull(name);
|
||||||
|
|
||||||
|
npc.data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, name.toLowerCase());
|
||||||
|
skinTracker.notifySkinChange(forceUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkinPersistent(String skinName, String signature, String data) {
|
||||||
|
Preconditions.checkNotNull(skinName);
|
||||||
|
Preconditions.checkNotNull(signature);
|
||||||
|
Preconditions.checkNotNull(data);
|
||||||
|
|
||||||
|
npc.data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, skinName.toLowerCase());
|
||||||
|
npc.data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA, signature);
|
||||||
|
npc.data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA, data);
|
||||||
|
npc.data().setPersistent(NPC.PLAYER_SKIN_USE_LATEST, false);
|
||||||
|
npc.data().setPersistent("cached-skin-uuid-name", skinName.toLowerCase());
|
||||||
|
skinTracker.notifySkinChange(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
|
||||||
|
controllerLook.a(target, yawOffset, renderOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetLook(Location target) {
|
||||||
|
controllerLook.a(target.getX(), target.getY(), target.getZ(), 10, 40);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTracked() {
|
||||||
|
isTracked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
super.tick();
|
||||||
|
if (npc == null)
|
||||||
|
return;
|
||||||
|
this.noclip = isSpectator();
|
||||||
|
if (updateCounter + 1 > Setting.PACKET_UPDATE_DELAY.asInt()) {
|
||||||
|
updateEffects = true;
|
||||||
|
}
|
||||||
|
Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity);
|
||||||
|
livingEntityBaseTick();
|
||||||
|
|
||||||
|
boolean navigating = npc.getNavigator().isNavigating();
|
||||||
|
updatePackets(navigating);
|
||||||
|
if (!navigating && getBukkitEntity() != null && npc.getTrait(Gravity.class).hasGravity()
|
||||||
|
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||||
|
a(0, 0, 0);
|
||||||
|
}
|
||||||
|
Vec3D mot = getMot();
|
||||||
|
if (Math.abs(mot.getX()) < EPSILON && Math.abs(mot.getY()) < EPSILON && Math.abs(mot.getZ()) < EPSILON) {
|
||||||
|
setMot(new Vec3D(0, 0, 0));
|
||||||
|
}
|
||||||
|
if (navigating) {
|
||||||
|
if (!NMSImpl.isNavigationFinished(navigation)) {
|
||||||
|
NMSImpl.updateNavigation(navigation);
|
||||||
|
}
|
||||||
|
moveOnCurrentHeading();
|
||||||
|
}
|
||||||
|
NMSImpl.updateAI(this);
|
||||||
|
|
||||||
|
if (noDamageTicks > 0) {
|
||||||
|
--noDamageTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateAI() {
|
||||||
|
controllerMove.a();
|
||||||
|
controllerLook.a();
|
||||||
|
controllerJump.b();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePackets(boolean navigating) {
|
||||||
|
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt())
|
||||||
|
return;
|
||||||
|
|
||||||
|
updateCounter = 0;
|
||||||
|
Location current = getBukkitEntity().getLocation(packetLocationCache);
|
||||||
|
Packet<?>[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1];
|
||||||
|
if (!navigating) {
|
||||||
|
packets[5] = new PacketPlayOutEntityHeadRotation(this,
|
||||||
|
(byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
for (EnumItemSlot slot : EnumItemSlot.values()) {
|
||||||
|
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
|
||||||
|
}
|
||||||
|
NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePathfindingRange(float pathfindingRange) {
|
||||||
|
this.navigation.setRange(pathfindingRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PlayerNPC extends CraftPlayer implements NPCHolder, SkinnableEntity {
|
||||||
|
private final CraftServer cserver;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
private PlayerNPC(EntityHumanNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
this.cserver = (CraftServer) Bukkit.getServer();
|
||||||
|
npc.getTrait(Inventory.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player getBukkitEntity() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityHumanNPC getHandle() {
|
||||||
|
return (EntityHumanNPC) this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MetadataValue> getMetadata(String metadataKey) {
|
||||||
|
return cserver.getEntityMetadata().getMetadata(this, metadataKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSkinName() {
|
||||||
|
return ((SkinnableEntity) this.entity).getSkinName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SkinPacketTracker getSkinTracker() {
|
||||||
|
return ((SkinnableEntity) this.entity).getSkinTracker();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMetadata(String metadataKey) {
|
||||||
|
return cserver.getEntityMetadata().hasMetadata(this, metadataKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
|
||||||
|
cserver.getEntityMetadata().removeMetadata(this, metadataKey, owningPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
|
||||||
|
cserver.getEntityMetadata().setMetadata(this, metadataKey, newMetadataValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkinFlags(byte flags) {
|
||||||
|
((SkinnableEntity) this.entity).setSkinFlags(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkinName(String name) {
|
||||||
|
((SkinnableEntity) this.entity).setSkinName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkinName(String skinName, boolean forceUpdate) {
|
||||||
|
((SkinnableEntity) this.entity).setSkinName(skinName, forceUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkinPersistent(String skinName, String signature, String data) {
|
||||||
|
((SkinnableEntity) this.entity).setSkinPersistent(skinName, signature, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final float EPSILON = 0.005F;
|
||||||
|
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
|
||||||
|
}
|
@ -0,0 +1,205 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEvoker;
|
||||||
|
import org.bukkit.entity.Evoker;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityEvoker;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class EvokerController extends MobEntityController {
|
||||||
|
public EvokerController() {
|
||||||
|
super(EntityEvokerNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Evoker getBukkitEntity() {
|
||||||
|
return (Evoker) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEvokerNPC extends EntityEvoker implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityEvokerNPC(EntityTypes<? extends EntityEvoker> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEvokerNPC(EntityTypes<? extends EntityEvoker> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new EvokerNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EvokerNPC extends CraftEvoker implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EvokerNPC(EntityEvokerNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftFox;
|
||||||
|
import org.bukkit.entity.Fox;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityFox;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class FoxController extends MobEntityController {
|
||||||
|
public FoxController() {
|
||||||
|
super(EntityFoxNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fox getBukkitEntity() {
|
||||||
|
return (Fox) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityFoxNPC extends EntityFox implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityFoxNPC(EntityTypes<? extends EntityFox> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityFoxNPC(EntityTypes<? extends EntityFox> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new FoxNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FoxNPC extends CraftFox implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public FoxNPC(EntityFoxNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,176 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftGhast;
|
||||||
|
import org.bukkit.entity.Ghast;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityGhast;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class GhastController extends MobEntityController {
|
||||||
|
public GhastController() {
|
||||||
|
super(EntityGhastNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ghast getBukkitEntity() {
|
||||||
|
return (Ghast) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityGhastNPC extends EntityGhast implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityGhastNPC(EntityTypes<? extends EntityGhast> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityGhastNPC(EntityTypes<? extends EntityGhast> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new GhastNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRiptiding() {
|
||||||
|
return npc != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
super.mobTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GhastNPC extends CraftGhast implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public GhastNPC(EntityGhastNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,212 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftGiant;
|
||||||
|
import org.bukkit.entity.Giant;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityGiantZombie;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class GiantController extends MobEntityController {
|
||||||
|
public GiantController() {
|
||||||
|
super(EntityGiantNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Giant getBukkitEntity() {
|
||||||
|
return (Giant) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityGiantNPC extends EntityGiantZombie implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityGiantNPC(EntityTypes<? extends EntityGiantZombie> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityGiantNPC(EntityTypes<? extends EntityGiantZombie> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new GiantNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GiantNPC extends CraftGiant implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public GiantNPC(EntityGiantNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,228 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftGuardian;
|
||||||
|
import org.bukkit.entity.Guardian;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityGuardian;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class GuardianController extends MobEntityController {
|
||||||
|
public GuardianController() {
|
||||||
|
super(EntityGuardianNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Guardian getBukkitEntity() {
|
||||||
|
return (Guardian) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityGuardianNPC extends EntityGuardian implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityGuardianNPC(EntityTypes<? extends EntityGuardian> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityGuardianNPC(EntityTypes<? extends EntityGuardian> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new GuardianNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void movementTick() {
|
||||||
|
if (npc == null) {
|
||||||
|
try {
|
||||||
|
super.movementTick();
|
||||||
|
} catch (NoSuchMethodError ex) {
|
||||||
|
try {
|
||||||
|
MOVEMENT_TICK.invoke(this);
|
||||||
|
} catch (Throwable ex2) {
|
||||||
|
ex2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NMSImpl.updateAI(this);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Method MOVEMENT_TICK = NMS.getMethod(EntityGuardian.class, "k", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GuardianNPC extends CraftGuardian implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public GuardianNPC(EntityGuardianNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,228 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftElderGuardian;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.ElderGuardian;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityGuardianElder;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class GuardianElderController extends MobEntityController {
|
||||||
|
public GuardianElderController() {
|
||||||
|
super(EntityGuardianElderNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ElderGuardian getBukkitEntity() {
|
||||||
|
return (ElderGuardian) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityGuardianElderNPC extends EntityGuardianElder implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityGuardianElderNPC(EntityTypes<? extends EntityGuardianElder> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityGuardianElderNPC(EntityTypes<? extends EntityGuardianElder> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new GuardianElderNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void movementTick() {
|
||||||
|
if (npc == null) {
|
||||||
|
try {
|
||||||
|
super.movementTick();
|
||||||
|
} catch (NoSuchMethodError ex) {
|
||||||
|
try {
|
||||||
|
MOVEMENT_TICK.invoke(this);
|
||||||
|
} catch (Throwable ex2) {
|
||||||
|
ex2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NMSImpl.updateAI(this);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Method MOVEMENT_TICK = NMS.getMethod(EntityGuardianElder.class, "k", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GuardianElderNPC extends CraftElderGuardian implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public GuardianElderNPC(EntityGuardianElderNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,229 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHorse;
|
||||||
|
import org.bukkit.entity.Horse;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.trait.HorseModifiers;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHorse;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class HorseController extends MobEntityController {
|
||||||
|
public HorseController() {
|
||||||
|
super(EntityHorseNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Horse getBukkitEntity() {
|
||||||
|
return (Horse) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawn(Location at, NPC npc) {
|
||||||
|
npc.getTrait(HorseModifiers.class);
|
||||||
|
super.spawn(at, npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityHorseNPC extends EntityHorse implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityHorseNPC(EntityTypes<? extends EntityHorse> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityHorseNPC(EntityTypes<? extends EntityHorse> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
((Horse) getBukkitEntity()).setDomestication(((Horse) getBukkitEntity()).getMaxDomestication());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new HorseNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HorseNPC extends CraftHorse implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public HorseNPC(EntityHorseNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,229 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftDonkey;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Donkey;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.trait.HorseModifiers;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHorseDonkey;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class HorseDonkeyController extends MobEntityController {
|
||||||
|
public HorseDonkeyController() {
|
||||||
|
super(EntityHorseDonkeyNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Donkey getBukkitEntity() {
|
||||||
|
return (Donkey) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawn(Location at, NPC npc) {
|
||||||
|
npc.addTrait(HorseModifiers.class);
|
||||||
|
super.spawn(at, npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityHorseDonkeyNPC extends EntityHorseDonkey implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityHorseDonkeyNPC(EntityTypes<? extends EntityHorseDonkey> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityHorseDonkeyNPC(EntityTypes<? extends EntityHorseDonkey> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
((Donkey) getBukkitEntity()).setDomestication(((Donkey) getBukkitEntity()).getMaxDomestication());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new HorseDonkeyNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HorseDonkeyNPC extends CraftDonkey implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public HorseDonkeyNPC(EntityHorseDonkeyNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,229 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftMule;
|
||||||
|
import org.bukkit.entity.Mule;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.trait.HorseModifiers;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHorseMule;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class HorseMuleController extends MobEntityController {
|
||||||
|
public HorseMuleController() {
|
||||||
|
super(EntityHorseMuleNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mule getBukkitEntity() {
|
||||||
|
return (Mule) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawn(Location at, NPC npc) {
|
||||||
|
npc.getTrait(HorseModifiers.class);
|
||||||
|
super.spawn(at, npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityHorseMuleNPC extends EntityHorseMule implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityHorseMuleNPC(EntityTypes<? extends EntityHorseMule> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityHorseMuleNPC(EntityTypes<? extends EntityHorseMule> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
((Mule) getBukkitEntity()).setDomestication(((Mule) getBukkitEntity()).getMaxDomestication());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new HorseMuleNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HorseMuleNPC extends CraftMule implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public HorseMuleNPC(EntityHorseMuleNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,230 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSkeletonHorse;
|
||||||
|
import org.bukkit.entity.SkeletonHorse;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.trait.HorseModifiers;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHorseSkeleton;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class HorseSkeletonController extends MobEntityController {
|
||||||
|
public HorseSkeletonController() {
|
||||||
|
super(EntityHorseSkeletonNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SkeletonHorse getBukkitEntity() {
|
||||||
|
return (SkeletonHorse) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawn(Location at, NPC npc) {
|
||||||
|
npc.getTrait(HorseModifiers.class);
|
||||||
|
super.spawn(at, npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityHorseSkeletonNPC extends EntityHorseSkeleton implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityHorseSkeletonNPC(EntityTypes<? extends EntityHorseSkeleton> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityHorseSkeletonNPC(EntityTypes<? extends EntityHorseSkeleton> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
((SkeletonHorse) getBukkitEntity())
|
||||||
|
.setDomestication(((SkeletonHorse) getBukkitEntity()).getMaxDomestication());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new HorseSkeletonNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HorseSkeletonNPC extends CraftSkeletonHorse implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public HorseSkeletonNPC(EntityHorseSkeletonNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,230 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftZombieHorse;
|
||||||
|
import org.bukkit.entity.ZombieHorse;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.trait.HorseModifiers;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHorseZombie;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class HorseZombieController extends MobEntityController {
|
||||||
|
public HorseZombieController() {
|
||||||
|
super(EntityHorseZombieNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ZombieHorse getBukkitEntity() {
|
||||||
|
return (ZombieHorse) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawn(Location at, NPC npc) {
|
||||||
|
npc.getTrait(HorseModifiers.class);
|
||||||
|
super.spawn(at, npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityHorseZombieNPC extends EntityHorseZombie implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityHorseZombieNPC(EntityTypes<? extends EntityHorseZombie> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityHorseZombieNPC(EntityTypes<? extends EntityHorseZombie> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
((ZombieHorse) getBukkitEntity())
|
||||||
|
.setDomestication(((ZombieHorse) getBukkitEntity()).getMaxDomestication());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new HorseZombieNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HorseZombieNPC extends CraftZombieHorse implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public HorseZombieNPC(EntityHorseZombieNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
|
import net.citizensnpcs.Settings.Setting;
|
||||||
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.api.util.Colorizer;
|
||||||
|
import net.citizensnpcs.npc.AbstractEntityController;
|
||||||
|
import net.citizensnpcs.npc.skin.Skin;
|
||||||
|
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
|
||||||
|
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||||
|
|
||||||
|
public class HumanController extends AbstractEntityController {
|
||||||
|
public HumanController() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Entity createEntity(final Location at, final NPC npc) {
|
||||||
|
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
|
||||||
|
String coloredName = Colorizer.parseColors(npc.getFullName());
|
||||||
|
|
||||||
|
String[] nameSplit = Util.splitPlayerName(coloredName);
|
||||||
|
String name = nameSplit[0];
|
||||||
|
|
||||||
|
final String prefixCapture = nameSplit[1], suffixCapture = nameSplit[2];
|
||||||
|
|
||||||
|
UUID uuid = npc.getUniqueId();
|
||||||
|
if (uuid.version() == 4) { // clear version
|
||||||
|
long msb = uuid.getMostSignificantBits();
|
||||||
|
msb &= ~0x0000000000004000L;
|
||||||
|
msb |= 0x0000000000002000L;
|
||||||
|
uuid = new UUID(msb, uuid.getLeastSignificantBits());
|
||||||
|
}
|
||||||
|
|
||||||
|
final GameProfile profile = new GameProfile(uuid, name);
|
||||||
|
|
||||||
|
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
|
||||||
|
new PlayerInteractManager(nmsWorld), npc);
|
||||||
|
|
||||||
|
Skin skin = handle.getSkinTracker().getSkin();
|
||||||
|
if (skin != null) {
|
||||||
|
skin.apply(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (getBukkitEntity() == null || !getBukkitEntity().isValid())
|
||||||
|
return;
|
||||||
|
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
|
||||||
|
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
|
||||||
|
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
|
||||||
|
|
||||||
|
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||||
|
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||||
|
String teamName = profile.getId().toString().substring(0, 16);
|
||||||
|
|
||||||
|
Team team = scoreboard.getTeam(teamName);
|
||||||
|
if (team == null) {
|
||||||
|
team = scoreboard.registerNewTeam(teamName);
|
||||||
|
}
|
||||||
|
if (prefixCapture != null) {
|
||||||
|
team.setPrefix(prefixCapture);
|
||||||
|
}
|
||||||
|
if (suffixCapture != null) {
|
||||||
|
team.setSuffix(suffixCapture);
|
||||||
|
}
|
||||||
|
team.addPlayer(handle.getBukkitEntity());
|
||||||
|
|
||||||
|
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 20);
|
||||||
|
|
||||||
|
handle.getBukkitEntity().setSleepingIgnored(true);
|
||||||
|
|
||||||
|
return handle.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player getBukkitEntity() {
|
||||||
|
return (Player) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove() {
|
||||||
|
Player entity = getBukkitEntity();
|
||||||
|
if (entity != null) {
|
||||||
|
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||||
|
String teamName = entity.getUniqueId().toString().substring(0, 16);
|
||||||
|
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||||
|
Team team = scoreboard.getTeam(teamName);
|
||||||
|
if (team != null && team.hasPlayer(entity)) {
|
||||||
|
if (team.getSize() == 1) {
|
||||||
|
team.setPrefix("");
|
||||||
|
team.setSuffix("");
|
||||||
|
}
|
||||||
|
team.removePlayer(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NMS.removeFromWorld(entity);
|
||||||
|
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||||
|
npc.getSkinTracker().onRemoveNPC();
|
||||||
|
}
|
||||||
|
NMS.remove(entity);
|
||||||
|
// Paper decided to break Spigot compatibility.
|
||||||
|
// super.remove();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,204 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftIllusioner;
|
||||||
|
import org.bukkit.entity.Illusioner;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityIllagerIllusioner;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class IllusionerController extends MobEntityController {
|
||||||
|
public IllusionerController() {
|
||||||
|
super(EntityIllusionerNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Illusioner getBukkitEntity() {
|
||||||
|
return (Illusioner) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityIllusionerNPC extends EntityIllagerIllusioner implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityIllusionerNPC(EntityTypes<? extends EntityIllagerIllusioner> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityIllusionerNPC(EntityTypes<? extends EntityIllagerIllusioner> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new IllusionerNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class IllusionerNPC extends CraftIllusioner implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public IllusionerNPC(EntityIllusionerNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,212 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftIronGolem;
|
||||||
|
import org.bukkit.entity.IronGolem;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityIronGolem;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class IronGolemController extends MobEntityController {
|
||||||
|
public IronGolemController() {
|
||||||
|
super(EntityIronGolemNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IronGolem getBukkitEntity() {
|
||||||
|
return (IronGolem) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityIronGolemNPC extends EntityIronGolem implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityIronGolemNPC(EntityTypes<? extends EntityIronGolem> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityIronGolemNPC(EntityTypes<? extends EntityIronGolem> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new IronGolemNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class IronGolemNPC extends CraftIronGolem implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public IronGolemNPC(EntityIronGolemNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,230 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftLlama;
|
||||||
|
import org.bukkit.entity.Llama;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.trait.HorseModifiers;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityLlama;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class LlamaController extends MobEntityController {
|
||||||
|
public LlamaController() {
|
||||||
|
super(EntityLlamaNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Llama getBukkitEntity() {
|
||||||
|
return (Llama) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawn(Location at, NPC npc) {
|
||||||
|
npc.getTrait(HorseModifiers.class);
|
||||||
|
super.spawn(at, npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityLlamaNPC extends EntityLlama implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityLlamaNPC(EntityTypes<? extends EntityLlama> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityLlamaNPC(EntityTypes<? extends EntityLlama> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
((Llama) getBukkitEntity()).setDomestication(((Llama) getBukkitEntity()).getMaxDomestication());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new LlamaNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.mobTick();
|
||||||
|
} else {
|
||||||
|
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LlamaNPC extends CraftLlama implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public LlamaNPC(EntityLlamaNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,223 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftMagmaCube;
|
||||||
|
import org.bukkit.entity.MagmaCube;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.PlayerControllerMove;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityMagmaCube;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class MagmaCubeController extends MobEntityController {
|
||||||
|
public MagmaCubeController() {
|
||||||
|
super(EntityMagmaCubeNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MagmaCube getBukkitEntity() {
|
||||||
|
return (MagmaCube) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityMagmaCubeNPC extends EntityMagmaCube implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityMagmaCubeNPC(EntityTypes<? extends EntityMagmaCube> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityMagmaCubeNPC(EntityTypes<? extends EntityMagmaCube> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
setSize(3, true);
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
this.moveController = new PlayerControllerMove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new MagmaCubeNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pickup(EntityHuman human) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.pickup(human);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
super.tick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MagmaCubeNPC extends CraftMagmaCube implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public MagmaCubeNPC(EntityMagmaCubeNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.AbstractEntityController;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public abstract class MobEntityController extends AbstractEntityController {
|
||||||
|
private final Class<?> clazz;
|
||||||
|
private final Constructor<?> constructor;
|
||||||
|
|
||||||
|
protected MobEntityController(Class<?> clazz) {
|
||||||
|
super(clazz);
|
||||||
|
this.constructor = getConstructor(clazz);
|
||||||
|
this.clazz = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Entity createEntity(Location at, NPC npc) {
|
||||||
|
EntityTypes<?> type = NMSImpl.getEntityType(clazz);
|
||||||
|
net.minecraft.server.v1_14_R1.Entity entity = createEntityFromClass(type,
|
||||||
|
((CraftWorld) at.getWorld()).getHandle(), npc);
|
||||||
|
entity.setPositionRotation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
|
||||||
|
|
||||||
|
// entity.onGround isn't updated right away - we approximate here so
|
||||||
|
// that things like pathfinding still work *immediately* after spawn.
|
||||||
|
org.bukkit.Material beneath = at.getBlock().getRelative(BlockFace.DOWN).getType();
|
||||||
|
if (beneath.isBlock()) {
|
||||||
|
entity.onGround = true;
|
||||||
|
}
|
||||||
|
return entity.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
private net.minecraft.server.v1_14_R1.Entity createEntityFromClass(Object... args) {
|
||||||
|
try {
|
||||||
|
return (net.minecraft.server.v1_14_R1.Entity) constructor.newInstance(args);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Constructor<?> getConstructor(Class<?> clazz) {
|
||||||
|
Constructor<?> constructor = CONSTRUCTOR_CACHE.get(clazz);
|
||||||
|
if (constructor != null)
|
||||||
|
return constructor;
|
||||||
|
try {
|
||||||
|
return clazz.getConstructor(EntityTypes.class, World.class, NPC.class);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new IllegalStateException("unable to find an entity constructor");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<Class<?>, Constructor<?>> CONSTRUCTOR_CACHE = Maps.newHashMap();
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftMushroomCow;
|
||||||
|
import org.bukkit.entity.MushroomCow;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityMushroomCow;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class MushroomCowController extends MobEntityController {
|
||||||
|
|
||||||
|
public MushroomCowController() {
|
||||||
|
super(EntityMushroomCowNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MushroomCow getBukkitEntity() {
|
||||||
|
return (MushroomCow) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityMushroomCowNPC extends EntityMushroomCow implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityMushroomCowNPC(EntityTypes<? extends EntityMushroomCow> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityMushroomCowNPC(EntityTypes<? extends EntityMushroomCow> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new MushroomCowNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null)
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MushroomCowNPC extends CraftMushroomCow implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public MushroomCowNPC(EntityMushroomCowNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,224 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftOcelot;
|
||||||
|
import org.bukkit.entity.Ocelot;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityOcelot;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class OcelotController extends MobEntityController {
|
||||||
|
public OcelotController() {
|
||||||
|
super(EntityOcelotNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ocelot getBukkitEntity() {
|
||||||
|
return (Ocelot) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityOcelotNPC extends EntityOcelot implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityOcelotNPC(EntityTypes<? extends EntityOcelot> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityOcelotNPC(EntityTypes<? extends EntityOcelot> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void dV() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.dV();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new OcelotNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class OcelotNPC extends CraftOcelot implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public OcelotNPC(EntityOcelotNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPanda;
|
||||||
|
import org.bukkit.entity.Panda;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityPanda;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class PandaController extends MobEntityController {
|
||||||
|
public PandaController() {
|
||||||
|
super(EntityPandaNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Panda getBukkitEntity() {
|
||||||
|
return (Panda) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityPandaNPC extends EntityPanda implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityPandaNPC(EntityTypes<? extends EntityPanda> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPandaNPC(EntityTypes<? extends EntityPanda> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new PandaNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PandaNPC extends CraftPanda implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public PandaNPC(EntityPandaNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,183 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftParrot;
|
||||||
|
import org.bukkit.entity.Parrot;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityParrot;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumHand;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class ParrotController extends MobEntityController {
|
||||||
|
public ParrotController() {
|
||||||
|
super(EntityParrotNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Parrot getBukkitEntity() {
|
||||||
|
return (Parrot) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityParrotNPC extends EntityParrot implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityParrotNPC(EntityTypes<? extends EntityParrot> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityParrotNPC(EntityTypes<? extends EntityParrot> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean a(EntityHuman paramEntityHuman, EnumHand paramEnumHand) {
|
||||||
|
// block feeding
|
||||||
|
if (npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||||
|
return super.a(paramEntityHuman, paramEnumHand);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new ParrotNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null) {
|
||||||
|
return super.isLeashed();
|
||||||
|
}
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.mobTick();
|
||||||
|
} else {
|
||||||
|
NMSImpl.updateAI(this);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ParrotNPC extends CraftParrot implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public ParrotNPC(EntityParrotNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,245 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPhantom;
|
||||||
|
import org.bukkit.entity.Phantom;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.ControllerLook;
|
||||||
|
import net.minecraft.server.v1_14_R1.ControllerMove;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityPhantom;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumDifficulty;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class PhantomController extends MobEntityController {
|
||||||
|
public PhantomController() {
|
||||||
|
super(EntityPhantomNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Phantom getBukkitEntity() {
|
||||||
|
return (Phantom) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityPhantomNPC extends EntityPhantom implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityPhantomNPC(EntityTypes<? extends EntityPhantom> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPhantomNPC(EntityTypes<? extends EntityPhantom> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
setNoAI(true);
|
||||||
|
this.moveController = new ControllerMove(this);
|
||||||
|
this.lookController = new ControllerLook(this);
|
||||||
|
// TODO: phantom pitch reversed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dS() {
|
||||||
|
if (npc == null || !npc.isProtected())
|
||||||
|
return super.dS();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new PhantomNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void movementTick() {
|
||||||
|
try {
|
||||||
|
super.movementTick();
|
||||||
|
} catch (NoSuchMethodError ex) {
|
||||||
|
try {
|
||||||
|
MOVEMENT_TICK.invoke(this);
|
||||||
|
} catch (Throwable ex2) {
|
||||||
|
ex2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (npc != null) {
|
||||||
|
if (npc.isProtected()) {
|
||||||
|
this.setOnFire(0);
|
||||||
|
}
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
// avoid suicide
|
||||||
|
boolean resetDifficulty = this.world.getDifficulty() == EnumDifficulty.PEACEFUL;
|
||||||
|
if (npc != null && resetDifficulty) {
|
||||||
|
this.world.getWorldData().setDifficulty(EnumDifficulty.NORMAL);
|
||||||
|
}
|
||||||
|
super.tick();
|
||||||
|
if (npc != null && resetDifficulty) {
|
||||||
|
this.world.getWorldData().setDifficulty(EnumDifficulty.PEACEFUL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Method MOVEMENT_TICK = NMS.getMethod(EntityPhantom.class, "k", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PhantomNPC extends CraftPhantom implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public PhantomNPC(EntityPhantomNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,232 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPig;
|
||||||
|
import org.bukkit.entity.Pig;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityLightning;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityPig;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class PigController extends MobEntityController {
|
||||||
|
public PigController() {
|
||||||
|
super(EntityPigNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pig getBukkitEntity() {
|
||||||
|
return (Pig) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityPigNPC extends EntityPig implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityPigNPC(EntityTypes<? extends EntityPig> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPigNPC(EntityTypes<? extends EntityPig> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dD() {
|
||||||
|
// block carrot-on-a-stick behaviour
|
||||||
|
return npc == null ? super.dD() : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new PigNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightningStrike(EntityLightning entitylightning) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.onLightningStrike(entitylightning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PigNPC extends CraftPig implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public PigNPC(EntityPigNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,206 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPigZombie;
|
||||||
|
import org.bukkit.entity.PigZombie;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityPigZombie;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class PigZombieController extends MobEntityController {
|
||||||
|
|
||||||
|
public PigZombieController() {
|
||||||
|
super(EntityPigZombieNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PigZombie getBukkitEntity() {
|
||||||
|
return (PigZombie) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityPigZombieNPC extends EntityPigZombie implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityPigZombieNPC(EntityTypes<? extends EntityPigZombie> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPigZombieNPC(EntityTypes<? extends EntityPigZombie> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new PigZombieNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PigZombieNPC extends CraftPigZombie implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public PigZombieNPC(EntityPigZombieNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPillager;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Pillager;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityPillager;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class PillagerController extends MobEntityController {
|
||||||
|
public PillagerController() {
|
||||||
|
super(EntityPillagerNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pillager getBukkitEntity() {
|
||||||
|
return (Pillager) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PillagerNPC extends CraftPillager implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public PillagerNPC(EntityPillagerNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityPillagerNPC extends EntityPillager implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityPillagerNPC(EntityTypes<? extends EntityPillager> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPillagerNPC(EntityTypes<? extends EntityPillager> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new PillagerNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,184 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPolarBear;
|
||||||
|
import org.bukkit.entity.PolarBear;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityPolarBear;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class PolarBearController extends MobEntityController {
|
||||||
|
public PolarBearController() {
|
||||||
|
super(EntityPolarBearNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolarBear getBukkitEntity() {
|
||||||
|
return (PolarBear) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityPolarBearNPC extends EntityPolarBear implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityPolarBearNPC(EntityTypes<? extends EntityPolarBear> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPolarBearNPC(EntityTypes<? extends EntityPolarBear> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new PolarBearNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null) {
|
||||||
|
return super.isLeashed();
|
||||||
|
}
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PolarBearNPC extends CraftPolarBear implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public PolarBearNPC(EntityPolarBearNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,208 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPufferFish;
|
||||||
|
import org.bukkit.entity.PufferFish;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.ControllerMove;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityPufferFish;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class PufferFishController extends MobEntityController {
|
||||||
|
public PufferFishController() {
|
||||||
|
super(EntityPufferFishNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PufferFish getBukkitEntity() {
|
||||||
|
return (PufferFish) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityPufferFishNPC extends EntityPufferFish implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityPufferFishNPC(EntityTypes<? extends EntityPufferFish> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPufferFishNPC(EntityTypes<? extends EntityPufferFish> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
this.moveController = new ControllerMove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new PufferFishNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.setNotInSchool(this);
|
||||||
|
}
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PufferFishNPC extends CraftPufferFish implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public PufferFishNPC(EntityPufferFishNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,241 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftRabbit;
|
||||||
|
import org.bukkit.entity.Rabbit;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityLiving;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityRabbit;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class RabbitController extends MobEntityController {
|
||||||
|
public RabbitController() {
|
||||||
|
super(EntityRabbitNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rabbit getBukkitEntity() {
|
||||||
|
return (Rabbit) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityRabbitNPC extends EntityRabbit implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityRabbitNPC(EntityTypes<? extends EntityRabbit> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityRabbitNPC(EntityTypes<? extends EntityRabbit> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new RabbitNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityLiving getGoalTarget() {
|
||||||
|
return npc != null ? null : super.getGoalTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc != null) {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc.getNavigator().isNavigating()) {
|
||||||
|
NMS.setShouldJump(getBukkitEntity());
|
||||||
|
}
|
||||||
|
npc.update();
|
||||||
|
} else {
|
||||||
|
super.mobTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRabbitType(int i) {
|
||||||
|
if (npc != null) {
|
||||||
|
if (NMSImpl.getRabbitTypeField() == null)
|
||||||
|
return;
|
||||||
|
this.datawatcher.set(NMSImpl.getRabbitTypeField(), i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.setRabbitType(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RabbitNPC extends CraftRabbit implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public RabbitNPC(EntityRabbitNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftRavager;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Ravager;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityRavager;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class RavagerController extends MobEntityController {
|
||||||
|
public RavagerController() {
|
||||||
|
super(EntityRavagerNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ravager getBukkitEntity() {
|
||||||
|
return (Ravager) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RavagerNPC extends CraftRavager implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public RavagerNPC(EntityRavagerNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityRavagerNPC extends EntityRavager implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityRavagerNPC(EntityTypes<? extends EntityRavager> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityRavagerNPC(EntityTypes<? extends EntityRavager> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new RavagerNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,208 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSalmon;
|
||||||
|
import org.bukkit.entity.Salmon;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.ControllerMove;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySalmon;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SalmonController extends MobEntityController {
|
||||||
|
public SalmonController() {
|
||||||
|
super(EntitySalmonNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Salmon getBukkitEntity() {
|
||||||
|
return (Salmon) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySalmonNPC extends EntitySalmon implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntitySalmonNPC(EntityTypes<? extends EntitySalmon> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntitySalmonNPC(EntityTypes<? extends EntitySalmon> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
this.moveController = new ControllerMove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new SalmonNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.setNotInSchool(this);
|
||||||
|
}
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SalmonNPC extends CraftSalmon implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public SalmonNPC(EntitySalmonNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,216 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSheep;
|
||||||
|
import org.bukkit.entity.Sheep;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySheep;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SheepController extends MobEntityController {
|
||||||
|
public SheepController() {
|
||||||
|
super(EntitySheepNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Sheep getBukkitEntity() {
|
||||||
|
return (Sheep) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySheepNPC extends EntitySheep implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntitySheepNPC(EntityTypes<? extends EntitySheep> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntitySheepNPC(EntityTypes<? extends EntitySheep> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new SheepNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null)
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SheepNPC extends CraftSheep implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public SheepNPC(EntitySheepNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,239 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftShulker;
|
||||||
|
import org.bukkit.entity.Shulker;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityAIBodyControl;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityShulker;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class ShulkerController extends MobEntityController {
|
||||||
|
public ShulkerController() {
|
||||||
|
super(EntityShulkerNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Shulker getBukkitEntity() {
|
||||||
|
return (Shulker) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityShulkerNPC extends EntityShulker implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityShulkerNPC(EntityTypes<? extends EntityShulker> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityShulkerNPC(EntityTypes<? extends EntityShulker> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new ShulkerNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void movementTick() {
|
||||||
|
if (npc == null) {
|
||||||
|
try {
|
||||||
|
super.movementTick();
|
||||||
|
} catch (NoSuchMethodError ex) {
|
||||||
|
try {
|
||||||
|
MOVEMENT_TICK.invoke(this);
|
||||||
|
} catch (Throwable ex2) {
|
||||||
|
ex2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EntityAIBodyControl o() {
|
||||||
|
return new EntityAIBodyControl(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Method MOVEMENT_TICK = NMS.getMethod(EntityShulker.class, "k", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ShulkerNPC extends CraftShulker implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public ShulkerNPC(EntityShulkerNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,209 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSilverfish;
|
||||||
|
import org.bukkit.entity.Silverfish;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySilverfish;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SilverfishController extends MobEntityController {
|
||||||
|
public SilverfishController() {
|
||||||
|
super(EntitySilverfishNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Silverfish getBukkitEntity() {
|
||||||
|
return (Silverfish) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntitySilverfishNPC(EntityTypes<? extends EntitySilverfish> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntitySilverfishNPC(EntityTypes<? extends EntitySilverfish> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null)
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new SilverfishNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null)
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SilverfishNPC extends CraftSilverfish implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public SilverfishNPC(EntitySilverfishNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,212 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSkeleton;
|
||||||
|
import org.bukkit.entity.Skeleton;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySkeleton;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SkeletonController extends MobEntityController {
|
||||||
|
public SkeletonController() {
|
||||||
|
super(EntitySkeletonNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Skeleton getBukkitEntity() {
|
||||||
|
return (Skeleton) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySkeletonNPC extends EntitySkeleton implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntitySkeletonNPC(EntityTypes<? extends EntitySkeleton> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntitySkeletonNPC(EntityTypes<? extends EntitySkeleton> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new SkeletonNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SkeletonNPC extends CraftSkeleton implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public SkeletonNPC(EntitySkeletonNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,212 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftStray;
|
||||||
|
import org.bukkit.entity.Stray;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySkeletonStray;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SkeletonStrayController extends MobEntityController {
|
||||||
|
public SkeletonStrayController() {
|
||||||
|
super(EntityStrayNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stray getBukkitEntity() {
|
||||||
|
return (Stray) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityStrayNPC extends EntitySkeletonStray implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityStrayNPC(EntityTypes<? extends EntitySkeletonStray> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityStrayNPC(EntityTypes<? extends EntitySkeletonStray> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new StrayNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class StrayNPC extends CraftStray implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public StrayNPC(EntityStrayNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,212 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftWitherSkeleton;
|
||||||
|
import org.bukkit.entity.WitherSkeleton;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySkeletonWither;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SkeletonWitherController extends MobEntityController {
|
||||||
|
public SkeletonWitherController() {
|
||||||
|
super(EntitySkeletonWitherNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WitherSkeleton getBukkitEntity() {
|
||||||
|
return (WitherSkeleton) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySkeletonWitherNPC extends EntitySkeletonWither implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntitySkeletonWitherNPC(EntityTypes<? extends EntitySkeletonWither> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntitySkeletonWitherNPC(EntityTypes<? extends EntitySkeletonWither> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new SkeletonWitherNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SkeletonWitherNPC extends CraftWitherSkeleton implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public SkeletonWitherNPC(EntitySkeletonWitherNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,223 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSlime;
|
||||||
|
import org.bukkit.entity.Slime;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.PlayerControllerMove;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySlime;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SlimeController extends MobEntityController {
|
||||||
|
public SlimeController() {
|
||||||
|
super(EntitySlimeNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Slime getBukkitEntity() {
|
||||||
|
return (Slime) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySlimeNPC extends EntitySlime implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntitySlimeNPC(EntityTypes<? extends EntitySlime> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntitySlimeNPC(EntityTypes<? extends EntitySlime> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
setSize(3, true);
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
this.moveController = new PlayerControllerMove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new SlimeNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pickup(EntityHuman human) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.pickup(human);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
super.tick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SlimeNPC extends CraftSlime implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public SlimeNPC(EntitySlimeNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,238 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSnowman;
|
||||||
|
import org.bukkit.entity.Snowman;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySnowman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SnowmanController extends MobEntityController {
|
||||||
|
public SnowmanController() {
|
||||||
|
super(EntitySnowmanNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Snowman getBukkitEntity() {
|
||||||
|
return (Snowman) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySnowmanNPC extends EntitySnowman implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntitySnowmanNPC(EntityTypes<? extends EntitySnowman> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntitySnowmanNPC(EntityTypes<? extends EntitySnowman> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new SnowmanNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void movementTick() {
|
||||||
|
boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing");
|
||||||
|
if (npc != null) {
|
||||||
|
this.world.getGameRules().set("mobGriefing", "false", this.world.getMinecraftServer());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
super.movementTick();
|
||||||
|
} catch (NoSuchMethodError ex) {
|
||||||
|
try {
|
||||||
|
MOVEMENT_TICK.invoke(this);
|
||||||
|
} catch (Throwable ex2) {
|
||||||
|
ex2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (npc != null) {
|
||||||
|
this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing),
|
||||||
|
this.world.getMinecraftServer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Method MOVEMENT_TICK = NMS.getMethod(EntitySnowman.class, "k", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SnowmanNPC extends CraftSnowman implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public SnowmanNPC(EntitySnowmanNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,212 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSpider;
|
||||||
|
import org.bukkit.entity.Spider;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySpider;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SpiderController extends MobEntityController {
|
||||||
|
public SpiderController() {
|
||||||
|
super(EntitySpiderNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Spider getBukkitEntity() {
|
||||||
|
return (Spider) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySpiderNPC extends EntitySpider implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntitySpiderNPC(EntityTypes<? extends EntitySpider> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntitySpiderNPC(EntityTypes<? extends EntitySpider> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new SpiderNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null)
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SpiderNPC extends CraftSpider implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public SpiderNPC(EntitySpiderNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,204 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftSquid;
|
||||||
|
import org.bukkit.entity.Squid;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntitySquid;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class SquidController extends MobEntityController {
|
||||||
|
public SquidController() {
|
||||||
|
super(EntitySquidNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Squid getBukkitEntity() {
|
||||||
|
return (Squid) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntitySquidNPC extends EntitySquid implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntitySquidNPC(EntityTypes<? extends EntitySquid> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntitySquidNPC(EntityTypes<? extends EntitySquid> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new SquidNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SquidNPC extends CraftSquid implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public SquidNPC(EntitySquidNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,231 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftTraderLlama;
|
||||||
|
import org.bukkit.entity.TraderLlama;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.trait.HorseModifiers;
|
||||||
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityLLamaTrader;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class TraderLlamaController extends MobEntityController {
|
||||||
|
public TraderLlamaController() {
|
||||||
|
super(EntityTraderLlamaNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TraderLlama getBukkitEntity() {
|
||||||
|
return (TraderLlama) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawn(Location at, NPC npc) {
|
||||||
|
npc.getTrait(HorseModifiers.class);
|
||||||
|
super.spawn(at, npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityTraderLlamaNPC extends EntityLLamaTrader implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityTraderLlamaNPC(EntityTypes<? extends EntityLLamaTrader> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityTraderLlamaNPC(EntityTypes<? extends EntityLLamaTrader> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
((TraderLlama) getBukkitEntity())
|
||||||
|
.setDomestication(((TraderLlama) getBukkitEntity()).getMaxDomestication());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new TraderLlamaNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.mobTick();
|
||||||
|
} else {
|
||||||
|
NMS.setStepHeight(getBukkitEntity(), 1);
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TraderLlamaNPC extends CraftTraderLlama implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public TraderLlamaNPC(EntityTraderLlamaNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,208 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftTropicalFish;
|
||||||
|
import org.bukkit.entity.TropicalFish;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.ControllerMove;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTropicalFish;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class TropicalFishController extends MobEntityController {
|
||||||
|
public TropicalFishController() {
|
||||||
|
super(EntityTropicalFishNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TropicalFish getBukkitEntity() {
|
||||||
|
return (TropicalFish) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityTropicalFishNPC extends EntityTropicalFish implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityTropicalFishNPC(EntityTypes<? extends EntityTropicalFish> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityTropicalFishNPC(EntityTypes<? extends EntityTropicalFish> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
this.moveController = new ControllerMove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new TropicalFishNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.setNotInSchool(this);
|
||||||
|
}
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TropicalFishNPC extends CraftTropicalFish implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public TropicalFishNPC(EntityTropicalFishNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,219 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftTurtle;
|
||||||
|
import org.bukkit.entity.Turtle;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.ControllerJump;
|
||||||
|
import net.minecraft.server.v1_14_R1.ControllerMove;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityInsentient;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTurtle;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class TurtleController extends MobEntityController {
|
||||||
|
public TurtleController() {
|
||||||
|
super(EntityTurtleNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Turtle getBukkitEntity() {
|
||||||
|
return (Turtle) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityTurtleNPC extends EntityTurtle implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityTurtleNPC(EntityTypes<? extends EntityTurtle> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityTurtleNPC(EntityTypes<? extends EntityTurtle> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
this.moveController = new ControllerMove(this);
|
||||||
|
this.bt = new EmptyControllerJump(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new TurtleNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class EmptyControllerJump extends ControllerJump {
|
||||||
|
|
||||||
|
public EmptyControllerJump(EntityInsentient var1) {
|
||||||
|
super(var1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b() {
|
||||||
|
this.a = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TurtleNPC extends CraftTurtle implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public TurtleNPC(EntityTurtleNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,172 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftVex;
|
||||||
|
import org.bukkit.entity.Vex;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityVex;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class VexController extends MobEntityController {
|
||||||
|
public VexController() {
|
||||||
|
super(EntityVexNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vex getBukkitEntity() {
|
||||||
|
return (Vex) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityVexNPC extends EntityVex implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityVexNPC(EntityTypes<? extends EntityVex> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityVexNPC(EntityTypes<? extends EntityVex> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
setNoGravity(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new VexNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null) {
|
||||||
|
return super.isLeashed();
|
||||||
|
}
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class VexNPC extends CraftVex implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public VexNPC(EntityVexNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,261 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftVillager;
|
||||||
|
import org.bukkit.entity.Villager;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityLightning;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityVillager;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumHand;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.MerchantRecipe;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class VillagerController extends MobEntityController {
|
||||||
|
public VillagerController() {
|
||||||
|
super(EntityVillagerNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Villager getBukkitEntity() {
|
||||||
|
return (Villager) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityVillagerNPC extends EntityVillager implements NPCHolder {
|
||||||
|
private boolean blockingATrade;
|
||||||
|
private boolean blockTrades = true;
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityVillagerNPC(EntityTypes<? extends EntityVillager> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityVillagerNPC(EntityTypes<? extends EntityVillager> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean a(EntityHuman entityhuman, EnumHand enumhand) {
|
||||||
|
if (npc != null && blockTrades) {
|
||||||
|
blockingATrade = true;
|
||||||
|
List<MerchantRecipe> list = getOffers();
|
||||||
|
if (list != null) {
|
||||||
|
list.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.a(entityhuman, enumhand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dX() {
|
||||||
|
if (blockingATrade) {
|
||||||
|
blockingATrade = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.dX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new VillagerNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBlockingTrades() {
|
||||||
|
return blockTrades;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightningStrike(EntityLightning entitylightning) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.onLightningStrike(entitylightning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockTrades(boolean blocked) {
|
||||||
|
this.blockTrades = blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class VillagerNPC extends CraftVillager implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public VillagerNPC(EntityVillagerNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftVindicator;
|
||||||
|
import org.bukkit.entity.Vindicator;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityVindicator;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class VindicatorController extends MobEntityController {
|
||||||
|
public VindicatorController() {
|
||||||
|
super(EntityVindicatorNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vindicator getBukkitEntity() {
|
||||||
|
return (Vindicator) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityVindicatorNPC extends EntityVindicator implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityVindicatorNPC(EntityTypes<? extends EntityVindicator> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityVindicatorNPC(EntityTypes<? extends EntityVindicator> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new VindicatorNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class VindicatorNPC extends CraftVindicator implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public VindicatorNPC(EntityVindicatorNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,260 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftWanderingTrader;
|
||||||
|
import org.bukkit.entity.WanderingTrader;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityLightning;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityVillagerTrader;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumHand;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.MerchantRecipe;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class WanderingTraderController extends MobEntityController {
|
||||||
|
public WanderingTraderController() {
|
||||||
|
super(EntityWanderingTraderNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WanderingTrader getBukkitEntity() {
|
||||||
|
return (WanderingTrader) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityWanderingTraderNPC extends EntityVillagerTrader implements NPCHolder {
|
||||||
|
private boolean blockingATrade;
|
||||||
|
private boolean blockTrades = true;
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityWanderingTraderNPC(EntityTypes<? extends EntityVillagerTrader> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityWanderingTraderNPC(EntityTypes<? extends EntityVillagerTrader> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean a(EntityHuman entityhuman, EnumHand enumhand) {
|
||||||
|
if (npc != null && blockTrades) {
|
||||||
|
blockingATrade = true;
|
||||||
|
List<MerchantRecipe> list = getOffers();
|
||||||
|
if (list != null) {
|
||||||
|
list.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.a(entityhuman, enumhand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dX() {
|
||||||
|
if (blockingATrade) {
|
||||||
|
blockingATrade = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.dX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new WanderingTraderNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBlockingTrades() {
|
||||||
|
return blockTrades;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightningStrike(EntityLightning entitylightning) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.onLightningStrike(entitylightning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockTrades(boolean blocked) {
|
||||||
|
this.blockTrades = blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WanderingTraderNPC extends CraftWanderingTrader implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public WanderingTraderNPC(EntityWanderingTraderNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,211 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftWitch;
|
||||||
|
import org.bukkit.entity.Witch;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityWitch;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class WitchController extends MobEntityController {
|
||||||
|
public WitchController() {
|
||||||
|
super(EntityWitchNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Witch getBukkitEntity() {
|
||||||
|
return (Witch) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityWitchNPC extends EntityWitch implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityWitchNPC(EntityTypes<? extends EntityWitch> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityWitchNPC(EntityTypes<? extends EntityWitch> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new WitchNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null)
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WitchNPC extends CraftWitch implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public WitchNPC(EntityWitchNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,175 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftWither;
|
||||||
|
import org.bukkit.entity.Wither;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityWither;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class WitherController extends MobEntityController {
|
||||||
|
public WitherController() {
|
||||||
|
super(EntityWitherNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Wither getBukkitEntity() {
|
||||||
|
return (Wither) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityWitherNPC extends EntityWither implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityWitherNPC(EntityTypes<? extends EntityWither> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityWitherNPC(EntityTypes<? extends EntityWither> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new WitherNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int l(int i) {
|
||||||
|
return npc == null ? super.l(i) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mobTick() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.mobTick();
|
||||||
|
} else {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WitherNPC extends CraftWither implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public WitherNPC(EntityWitherNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,229 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftWolf;
|
||||||
|
import org.bukkit.entity.Wolf;
|
||||||
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.DataWatcherObject;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityLiving;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityWolf;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class WolfController extends MobEntityController {
|
||||||
|
public WolfController() {
|
||||||
|
super(EntityWolfNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Wolf getBukkitEntity() {
|
||||||
|
return (Wolf) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityWolfNPC extends EntityWolf implements NPCHolder {
|
||||||
|
boolean calledNMSHeight = false;
|
||||||
|
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityWolfNPC(EntityTypes<? extends EntityWolf> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityWolfNPC(EntityTypes<? extends EntityWolf> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void a(DataWatcherObject<?> datawatcherobject) {
|
||||||
|
if (npc != null && !calledNMSHeight) {
|
||||||
|
calledNMSHeight = true;
|
||||||
|
NMSImpl.checkAndUpdateHeight(this, datawatcherobject);
|
||||||
|
calledNMSHeight = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.a(datawatcherobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new WolfNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setGoalTarget(EntityLiving entityliving, EntityTargetEvent.TargetReason reason, boolean fire) {
|
||||||
|
return npc == null || this.equals(entityliving) ? super.setGoalTarget(entityliving, reason, fire) : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WolfNPC extends CraftWolf implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public WolfNPC(EntityWolfNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSitting(boolean sitting) {
|
||||||
|
getHandle().setSitting(sitting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,203 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftZombie;
|
||||||
|
import org.bukkit.entity.Zombie;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityZombie;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class ZombieController extends MobEntityController {
|
||||||
|
public ZombieController() {
|
||||||
|
super(EntityZombieNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Zombie getBukkitEntity() {
|
||||||
|
return (Zombie) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityZombieNPC extends EntityZombie implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityZombieNPC(EntityTypes<? extends EntityZombie> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityZombieNPC(EntityTypes<? extends EntityZombie> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new ZombieNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ZombieNPC extends CraftZombie implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public ZombieNPC(EntityZombieNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,203 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHusk;
|
||||||
|
import org.bukkit.entity.Husk;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityZombieHusk;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class ZombieHuskController extends MobEntityController {
|
||||||
|
public ZombieHuskController() {
|
||||||
|
super(EntityZombieHuskNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Husk getBukkitEntity() {
|
||||||
|
return (Husk) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityZombieHuskNPC extends EntityZombieHusk implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityZombieHuskNPC(EntityTypes<? extends EntityZombieHusk> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityZombieHuskNPC(EntityTypes<? extends EntityZombieHusk> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new ZombieHuskNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ZombieHuskNPC extends CraftHusk implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public ZombieHuskNPC(EntityZombieHuskNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,203 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftVillagerZombie;
|
||||||
|
import org.bukkit.entity.ZombieVillager;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityZombieVillager;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class ZombieVillagerController extends MobEntityController {
|
||||||
|
public ZombieVillagerController() {
|
||||||
|
super(EntityZombieVillagerNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ZombieVillager getBukkitEntity() {
|
||||||
|
return (ZombieVillager) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityZombieVillagerNPC extends EntityZombieVillager implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityZombieVillagerNPC(EntityTypes<? extends EntityZombieVillager> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityZombieVillagerNPC(EntityTypes<? extends EntityZombieVillager> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
if (npc != null) {
|
||||||
|
NMSImpl.clearGoals(goalSelector, targetSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.a(d0, flag, block, blockposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void e(Vec3D vec3d) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.e(vec3d);
|
||||||
|
} else {
|
||||||
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void b(float f, float f1) {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
super.b(f, f1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkDespawn() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.checkDespawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null)
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
super.enderTeleportTo(d0, d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder))
|
||||||
|
bukkitEntity = new ZombieVillagerNPC(this);
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SoundEffect getSoundAmbient() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SoundEffect getSoundDeath() {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SoundEffect getSoundHurt(DamageSource damagesource) {
|
||||||
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLeashed() {
|
||||||
|
if (npc == null)
|
||||||
|
return super.isLeashed();
|
||||||
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||||
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||||
|
return super.isLeashed();
|
||||||
|
if (super.isLeashed()) {
|
||||||
|
unleash(true, false); // clearLeash with client update
|
||||||
|
}
|
||||||
|
return false; // shouldLeash
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mobTick() {
|
||||||
|
super.mobTick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClimbing() {
|
||||||
|
if (npc == null || !npc.isFlyable()) {
|
||||||
|
return super.isClimbing();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ZombieVillagerNPC extends CraftVillagerZombie implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public ZombieVillagerNPC(EntityZombieVillagerNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftAreaEffectCloud;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.AreaEffectCloud;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityAreaEffectCloud;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class AreaEffectCloudController extends MobEntityController {
|
||||||
|
public AreaEffectCloudController() {
|
||||||
|
super(EntityAreaEffectCloudNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AreaEffectCloud getBukkitEntity() {
|
||||||
|
return (AreaEffectCloud) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AreaEffectCloudNPC extends CraftAreaEffectCloud implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public AreaEffectCloudNPC(EntityAreaEffectCloudNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityAreaEffectCloudNPC extends EntityAreaEffectCloud implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityAreaEffectCloudNPC(EntityTypes<? extends EntityAreaEffectCloud> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityAreaEffectCloudNPC(EntityTypes<? extends EntityAreaEffectCloud> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new AreaEffectCloudNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,132 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftArmorStand;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityArmorStand;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumHand;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumInteractionResult;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class ArmorStandController extends MobEntityController {
|
||||||
|
public ArmorStandController() {
|
||||||
|
super(EntityArmorStandNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArmorStand getBukkitEntity() {
|
||||||
|
return (ArmorStand) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ArmorStandNPC extends CraftArmorStand implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public ArmorStandNPC(EntityArmorStandNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityArmorStandNPC extends EntityArmorStand implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityArmorStandNPC(EntityTypes<? extends EntityArmorStand> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityArmorStandNPC(EntityTypes<? extends EntityArmorStand> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumInteractionResult a(EntityHuman entityhuman, Vec3D vec3d, EnumHand enumhand) {
|
||||||
|
if (npc == null) {
|
||||||
|
return super.a(entityhuman, vec3d, enumhand);
|
||||||
|
}
|
||||||
|
PlayerInteractEntityEvent event = new PlayerInteractEntityEvent((Player) entityhuman.getBukkitEntity(),
|
||||||
|
getBukkitEntity());
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
return event.isCancelled() ? EnumInteractionResult.FAIL : EnumInteractionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new ArmorStandNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
super.tick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftBoat;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Boat;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityBoat;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class BoatController extends MobEntityController {
|
||||||
|
public BoatController() {
|
||||||
|
super(EntityBoatNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boat getBukkitEntity() {
|
||||||
|
return (Boat) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BoatNPC extends CraftBoat implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public BoatNPC(EntityBoatNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityBoatNPC extends EntityBoat implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityBoatNPC(EntityTypes<? extends EntityBoat> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityBoatNPC(EntityTypes<? extends EntityBoat> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new BoatNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftDragonFireball;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.DragonFireball;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityDragonFireball;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class DragonFireballController extends MobEntityController {
|
||||||
|
public DragonFireballController() {
|
||||||
|
super(EntityDragonFireballNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DragonFireball getBukkitEntity() {
|
||||||
|
return (DragonFireball) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DragonFireballNPC extends CraftDragonFireball implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public DragonFireballNPC(EntityDragonFireballNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityDragonFireballNPC extends EntityDragonFireball implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityDragonFireballNPC(EntityTypes<? extends EntityDragonFireball> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityDragonFireballNPC(EntityTypes<? extends EntityDragonFireball> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new DragonFireballNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,135 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEgg;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Egg;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.npc.AbstractEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityEgg;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||||
|
|
||||||
|
public class EggController extends AbstractEntityController {
|
||||||
|
public EggController() {
|
||||||
|
super(EntityEggNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Entity createEntity(Location at, NPC npc) {
|
||||||
|
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
|
||||||
|
final EntityEggNPC handle = new EntityEggNPC(ws, npc, at.getX(), at.getY(), at.getZ());
|
||||||
|
return handle.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Egg getBukkitEntity() {
|
||||||
|
return (Egg) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EggNPC extends CraftEgg implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EggNPC(EntityEggNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEggNPC extends EntityEgg implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityEggNPC(EntityTypes<? extends EntityEgg> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEggNPC(EntityTypes<? extends EntityEgg> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEggNPC(World world, NPC npc, double d0, double d1, double d2) {
|
||||||
|
super(world, d0, d1, d2);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new EggNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEnderCrystal;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.EnderCrystal;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityEnderCrystal;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class EnderCrystalController extends MobEntityController {
|
||||||
|
public EnderCrystalController() {
|
||||||
|
super(EntityEnderCrystalNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnderCrystal getBukkitEntity() {
|
||||||
|
return (EnderCrystal) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EnderCrystalNPC extends CraftEnderCrystal implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EnderCrystalNPC(EntityEnderCrystalNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEnderCrystalNPC extends EntityEnderCrystal implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityEnderCrystalNPC(EntityTypes<? extends EntityEnderCrystal> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEnderCrystalNPC(EntityTypes<? extends EntityEnderCrystal> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new EnderCrystalNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,119 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEnderPearl;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.EnderPearl;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityEnderPearl;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class EnderPearlController extends MobEntityController {
|
||||||
|
public EnderPearlController() {
|
||||||
|
super(EntityEnderPearlNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnderPearl getBukkitEntity() {
|
||||||
|
return (EnderPearl) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EnderPearlNPC extends CraftEnderPearl implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EnderPearlNPC(EntityEnderPearlNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEnderPearlNPC extends EntityEnderPearl implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityEnderPearlNPC(EntityTypes<? extends EntityEnderPearl> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEnderPearlNPC(EntityTypes<? extends EntityEnderPearl> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new EnderPearlNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEnderSignal;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.EnderSignal;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityEnderSignal;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class EnderSignalController extends MobEntityController {
|
||||||
|
public EnderSignalController() {
|
||||||
|
super(EntityEnderSignalNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnderSignal getBukkitEntity() {
|
||||||
|
return (EnderSignal) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EnderSignalNPC extends CraftEnderSignal implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EnderSignalNPC(EntityEnderSignalNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEnderSignalNPC extends EntityEnderSignal implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityEnderSignalNPC(EntityTypes<? extends EntityEnderSignal> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEnderSignalNPC(EntityTypes<? extends EntityEnderSignal> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new EnderSignalNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,132 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEvokerFangs;
|
||||||
|
import org.bukkit.entity.EvokerFangs;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityEvokerFangs;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumHand;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumInteractionResult;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class EvokerFangsController extends MobEntityController {
|
||||||
|
public EvokerFangsController() {
|
||||||
|
super(EntityEvokerFangsNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvokerFangs getBukkitEntity() {
|
||||||
|
return (EvokerFangs) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityEvokerFangsNPC extends EntityEvokerFangs implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityEvokerFangsNPC(EntityTypes<? extends EntityEvokerFangs> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEvokerFangsNPC(EntityTypes<? extends EntityEvokerFangs> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumInteractionResult a(EntityHuman entityhuman, Vec3D vec3d, EnumHand enumhand) {
|
||||||
|
if (npc == null) {
|
||||||
|
return super.a(entityhuman, vec3d, enumhand);
|
||||||
|
}
|
||||||
|
PlayerInteractEntityEvent event = new PlayerInteractEntityEvent((Player) entityhuman.getBukkitEntity(),
|
||||||
|
getBukkitEntity());
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
return event.isCancelled() ? EnumInteractionResult.FAIL : EnumInteractionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new EvokerFangsNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
super.tick();
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EvokerFangsNPC extends CraftEvokerFangs implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EvokerFangsNPC(EntityEvokerFangsNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftExperienceOrb;
|
||||||
|
import org.bukkit.entity.ExperienceOrb;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityExperienceOrb;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class ExperienceOrbController extends MobEntityController {
|
||||||
|
public ExperienceOrbController() {
|
||||||
|
super(EntityExperienceOrbNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExperienceOrb getBukkitEntity() {
|
||||||
|
return (ExperienceOrb) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityExperienceOrbNPC extends EntityExperienceOrb implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityExperienceOrbNPC(EntityTypes<? extends EntityExperienceOrb> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityExperienceOrbNPC(EntityTypes<? extends EntityExperienceOrb> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new ExperienceOrbNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ExperienceOrbNPC extends CraftExperienceOrb implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public ExperienceOrbNPC(EntityExperienceOrbNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,177 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftFallingBlock;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.FallingBlock;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.DespawnReason;
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.event.SpawnReason;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
||||||
|
import net.citizensnpcs.npc.AbstractEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.Block;
|
||||||
|
import net.minecraft.server.v1_14_R1.Blocks;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityFallingBlock;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.EnumMoveType;
|
||||||
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||||
|
|
||||||
|
public class FallingBlockController extends AbstractEntityController {
|
||||||
|
public FallingBlockController() {
|
||||||
|
super(EntityFallingBlockNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Entity createEntity(Location at, NPC npc) {
|
||||||
|
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
|
||||||
|
Block id = Blocks.STONE;
|
||||||
|
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||||
|
// TODO: how to incorporate this - probably delete?
|
||||||
|
if (npc.data().has("falling-block-id") || npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||||
|
id = CraftMagicNumbers.getBlock(Material.getMaterial(
|
||||||
|
npc.data().<String> get(NPC.ITEM_ID_METADATA, npc.data().<String> get("falling-block-id"))));
|
||||||
|
}
|
||||||
|
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||||
|
id.getBlockData());
|
||||||
|
return handle.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FallingBlock getBukkitEntity() {
|
||||||
|
return (FallingBlock) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityFallingBlockNPC extends EntityFallingBlock implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityFallingBlockNPC(EntityTypes<? extends EntityFallingBlock> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityFallingBlockNPC(EntityTypes<? extends EntityFallingBlock> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityFallingBlockNPC(World world, NPC npc, double d0, double d1, double d2, IBlockData data) {
|
||||||
|
super(world, d0, d1, d2, data);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new FallingBlockNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
Vec3D mot = getMot();
|
||||||
|
if (Math.abs(mot.getX()) > EPSILON || Math.abs(mot.getY()) > EPSILON
|
||||||
|
|| Math.abs(mot.getZ()) > EPSILON) {
|
||||||
|
mot = mot.d(0.98, 0.98, 0.98);
|
||||||
|
setMot(mot);
|
||||||
|
move(EnumMoveType.SELF, mot);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSize() {
|
||||||
|
if (npc == null) {
|
||||||
|
super.updateSize();
|
||||||
|
} else {
|
||||||
|
NMSImpl.setSize(this, justCreated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final double EPSILON = 0.001;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FallingBlockNPC extends CraftFallingBlock implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public FallingBlockNPC(EntityFallingBlockNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(Material material, int data) {
|
||||||
|
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
|
||||||
|
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
|
||||||
|
if (npc.isSpawned()) {
|
||||||
|
npc.despawn(DespawnReason.PENDING_RESPAWN);
|
||||||
|
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package net.citizensnpcs.nms.v1_14_R1.entity.nonliving;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftFirework;
|
||||||
|
import org.bukkit.entity.Firework;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.nms.v1_14_R1.entity.MobEntityController;
|
||||||
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityFireworks;
|
||||||
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_14_R1.World;
|
||||||
|
|
||||||
|
public class FireworkController extends MobEntityController {
|
||||||
|
public FireworkController() {
|
||||||
|
super(EntityFireworkNPC.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Firework getBukkitEntity() {
|
||||||
|
return (Firework) super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EntityFireworkNPC extends EntityFireworks implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public EntityFireworkNPC(EntityTypes<? extends EntityFireworks> types, World world) {
|
||||||
|
this(types, world, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityFireworkNPC(EntityTypes<? extends EntityFireworks> types, World world, NPC npc) {
|
||||||
|
super(types, world);
|
||||||
|
this.npc = (CitizensNPC) npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
||||||
|
// this method is called by both the entities involved - cancelling
|
||||||
|
// it will not stop the NPC from moving.
|
||||||
|
super.collide(entity);
|
||||||
|
if (npc != null) {
|
||||||
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean d(NBTTagCompound save) {
|
||||||
|
return npc == null ? super.d(save) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void f(double x, double y, double z) {
|
||||||
|
if (npc == null) {
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||||
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||||
|
super.f(x, y, z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector vector = new Vector(x, y, z);
|
||||||
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
vector = event.getCollisionVector();
|
||||||
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
||||||
|
}
|
||||||
|
// when another entity collides, this method is called to push the
|
||||||
|
// NPC so we prevent it from doing anything if the event is
|
||||||
|
// cancelled.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CraftEntity getBukkitEntity() {
|
||||||
|
if (npc != null && !(bukkitEntity instanceof NPCHolder)) {
|
||||||
|
bukkitEntity = new FireworkNPC(this);
|
||||||
|
}
|
||||||
|
return super.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (npc != null) {
|
||||||
|
npc.update();
|
||||||
|
} else {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FireworkNPC extends CraftFirework implements NPCHolder {
|
||||||
|
private final CitizensNPC npc;
|
||||||
|
|
||||||
|
public FireworkNPC(EntityFireworkNPC entity) {
|
||||||
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
|
this.npc = entity.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NPC getNPC() {
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user