Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.dorvak.ia.npc;
- import java.util.List;
- import java.util.UUID;
- import org.bukkit.Location;
- import org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage;
- import org.bukkit.inventory.ItemStack;
- import com.mojang.authlib.GameProfile;
- import com.mojang.authlib.properties.Property;
- import fr.dorvak.ia.utils.Reflections;
- import net.minecraft.server.v1_8_R3.DataWatcher;
- import net.minecraft.server.v1_8_R3.MathHelper;
- import net.minecraft.server.v1_8_R3.PacketPlayOutAnimation;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutEntityLook;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntityHeadRotation;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntityStatus;
- import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
- import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn;
- import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
- import net.minecraft.server.v1_8_R3.WorldSettings.EnumGamemode;
- public class NPC extends Reflections {
- private int entityID;
- private GameProfile gameProfile;
- private Location loc;
- public NPC(String name, Location loc) {
- entityID = (int)Math.ceil(Math.random() * 1000) + 2000;
- gameProfile = new GameProfile(UUID.randomUUID(), name);
- this.loc = loc.clone();
- }
- public void loadSkin(String value, String signature) {
- gameProfile.getProperties().put("textures", new Property("textures", value, signature));
- }
- public void animate(int animation) {
- PacketPlayOutAnimation packet = new PacketPlayOutAnimation();
- setValue(packet, "a", entityID);
- setValue(packet, "b", (byte)animation);
- sendPacket(packet);
- }
- public void status(int status) {
- PacketPlayOutEntityStatus packet = new PacketPlayOutEntityStatus();
- setValue(packet, "a", entityID);
- setValue(packet, "b", (byte)status);
- sendPacket(packet);
- }
- public void equip(int slot, ItemStack item) {
- PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
- setValue(packet, "a", entityID);
- setValue(packet, "b", slot);
- setValue(packet, "c", item);
- sendPacket(packet);
- }
- public void spawn() {
- PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
- setValue(packet, "a", entityID);
- setValue(packet, "b", gameProfile.getId());
- setValue(packet, "c", getFixLocation(loc.getX()));
- setValue(packet, "d", getFixLocation(loc.getY()));
- setValue(packet, "e", getFixLocation(loc.getZ()));
- setValue(packet, "f", getFixRotation(loc.getYaw()));
- setValue(packet, "g", getFixRotation(loc.getPitch()));
- setValue(packet, "h", 0);
- DataWatcher watcher = new DataWatcher(null);
- watcher.a(6, (float)20);
- watcher.a(10, (byte)127);
- setValue(packet, "i", watcher);
- addToTabList();
- sendPacket(packet);
- headRotation(loc.getYaw(), loc.getPitch());
- }
- public void teleport(Location loc) {
- PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport();
- setValue(packet, "a", entityID);
- setValue(packet, "b", getFixLocation(loc.getX()));
- setValue(packet, "c", getFixLocation(loc.getY()));
- setValue(packet, "d", getFixLocation(loc.getZ()));
- setValue(packet, "e", getFixRotation(loc.getYaw()));
- setValue(packet,"f", getFixRotation(loc.getPitch()));
- sendPacket(packet);
- headRotation(loc.getYaw(), loc.getPitch());
- this.loc = loc.clone();
- }
- public void headRotation(float yaw, float pitch) {
- PacketPlayOutEntityLook packet = new PacketPlayOutEntityLook(entityID, getFixRotation(yaw), getFixRotation(pitch), true);
- PacketPlayOutEntityHeadRotation headPacket = new PacketPlayOutEntityHeadRotation();
- setValue(headPacket, "a", entityID);
- setValue(headPacket, "b", getFixRotation(yaw));
- sendPacket(packet);
- sendPacket(headPacket);
- }
- public void kill() {
- PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] {entityID});
- removeFromTabList();
- sendPacket(packet);
- }
- public void addToTabList() {
- PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
- PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameProfile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameProfile.getName())[0]);
- @SuppressWarnings("unchecked")
- List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) getValue(packet, "b");
- players.add(data);
- setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
- setValue(packet, "b", players);
- sendPacket(packet);
- }
- public void removeFromTabList() {
- PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
- PacketPlayOutPlayerInfo.PlayerInfoData data = packet.new PlayerInfoData(gameProfile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameProfile.getName())[0]);
- @SuppressWarnings("unchecked")
- List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) getValue(packet, "b");
- players.add(data);
- setValue(packet, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
- setValue(packet, "b", players);
- sendPacket(packet);
- }
- public int getFixLocation(double pos) {
- return (int)MathHelper.floor(pos * 32.0D);
- }
- public byte getFixRotation(float yawPitch) {
- return (byte)((int) (yawPitch * 256.0F / 360.0F));
- }
- public int getEntityID() {
- return entityID;
- }
- public Location getLocation() {
- return loc;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement