Search in sources :

Example 11 with World

use of net.minecraft.server.v1_16_R3.World in project MyPet by xXKeyleXx.

the class RangedAttack method shootProjectile.

public void shootProjectile(EntityLiving target, float damage, Projectiles projectile) {
    World world = target.world;
    if (projectile == Projectiles.Arrow) {
        EntityArrow arrow = new MyPetArrow(world, entityMyPet, target, 1.6F, 1);
        arrow.b(damage);
        arrow.setCritical(false);
        double distanceX = target.locX - entityMyPet.locX;
        double distanceY = target.locY + target.getHeadHeight() - 1.100000023841858D - arrow.locY;
        double distanceZ = target.locZ - entityMyPet.locZ;
        float distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F;
        arrow.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
        entityMyPet.makeSound("random.bow", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
        world.addEntity(arrow);
    } else if (projectile == Projectiles.Snowball) {
        MyPetSnowball snowball = new MyPetSnowball(world, entityMyPet);
        double distanceX = target.locX - entityMyPet.locX;
        double distanceY = target.locY + target.getHeadHeight() - 1.100000023841858D - snowball.locY;
        double distanceZ = target.locZ - entityMyPet.locZ;
        float distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F;
        snowball.setDamage(damage);
        snowball.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
        entityMyPet.makeSound("random.bow", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
        world.addEntity(snowball);
    } else if (projectile == Projectiles.Egg) {
        MyPetEgg egg = new MyPetEgg(world, entityMyPet);
        double distanceX = target.locX - entityMyPet.locX;
        double distanceY = target.locY + target.getHeadHeight() - 1.100000023841858D - egg.locY;
        double distanceZ = target.locZ - entityMyPet.locZ;
        float distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F;
        egg.setDamage(damage);
        egg.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
        entityMyPet.makeSound("random.bow", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
        world.addEntity(egg);
    } else if (projectile == Projectiles.LargeFireball) {
        double distanceX = this.target.locX - entityMyPet.locX;
        double distanceY = this.target.boundingBox.b + (double) (this.target.length / 2.0F) - (0.5D + entityMyPet.locY + (double) (entityMyPet.length / 2.0F));
        double distanceZ = this.target.locZ - entityMyPet.locZ;
        MyPetLargeFireball largeFireball = new MyPetLargeFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
        largeFireball.locY = (entityMyPet.locY + entityMyPet.length / 2.0F + 0.5D);
        largeFireball.setDamage(damage);
        world.addEntity(largeFireball);
        world.makeSound(entityMyPet.locX + 0.5D, entityMyPet.locY + 0.5D, entityMyPet.locZ + 0.5D, "mob.ghast.fireball", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
    } else if (projectile == Projectiles.SmallFireball) {
        double distanceX = this.target.locX - entityMyPet.locX;
        double distanceY = this.target.boundingBox.b + (this.target.length / 2.0F) - (0.5D + entityMyPet.locY + (entityMyPet.length / 2.0F));
        double distanceZ = this.target.locZ - entityMyPet.locZ;
        MyPetSmallFireball smallFireball = new MyPetSmallFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
        smallFireball.locY = (entityMyPet.locY + entityMyPet.length / 2.0F + 0.5D);
        smallFireball.setDamage(damage);
        world.addEntity(smallFireball);
        world.makeSound(entityMyPet.locX + 0.5D, entityMyPet.locY + 0.5D, entityMyPet.locZ + 0.5D, "mob.ghast.fireball", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
    } else if (projectile == Projectiles.WitherSkull) {
        double distanceX = this.target.locX - entityMyPet.locX;
        double distanceY = this.target.boundingBox.b + (double) (this.target.length / 2.0F) - (0.5D + entityMyPet.locY + (double) (entityMyPet.length / 2.0F));
        double distanceZ = this.target.locZ - entityMyPet.locZ;
        MyPetWitherSkull witherSkull = new MyPetWitherSkull(world, entityMyPet, distanceX, distanceY, distanceZ);
        witherSkull.locY = (entityMyPet.locY + entityMyPet.length / 2.0F + 0.5D);
        witherSkull.setDamage(damage);
        world.addEntity(witherSkull);
        world.makeSound(entityMyPet.locX + 0.5D, entityMyPet.locY + 0.5D, entityMyPet.locZ + 0.5D, "mob.wither.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
    }
}
Also used : EntityArrow(net.minecraft.server.v1_7_R4.EntityArrow) World(net.minecraft.server.v1_7_R4.World)

Example 12 with World

use of net.minecraft.server.v1_16_R3.World in project MyPet by xXKeyleXx.

the class EntityRegistry method createMinecraftEntity.

@Override
public MyPetMinecraftEntity createMinecraftEntity(MyPet pet, org.bukkit.World bukkitWorld) {
    EntityMyPet petEntity = null;
    Class<? extends MyPetMinecraftEntity> entityClass = entityClasses.get(pet.getPetType());
    World world = ((CraftWorld) bukkitWorld).getHandle();
    try {
        Constructor<?> ctor = entityClass.getConstructor(World.class, MyPet.class);
        Object obj = ctor.newInstance(world, pet);
        if (obj instanceof EntityMyPet) {
            petEntity = (EntityMyPet) obj;
        }
    } catch (Exception e) {
        MyPetApi.getLogger().info(ChatColor.RED + Util.getClassName(entityClass) + "(" + pet.getPetType() + ") is no valid MyPet(Entity)!");
        e.printStackTrace();
    }
    return petEntity;
}
Also used : World(net.minecraft.server.v1_8_R3.World) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld)

Example 13 with World

use of net.minecraft.server.v1_16_R3.World in project MyPet by xXKeyleXx.

the class EntityRegistry method createMinecraftEntity.

@Override
public MyPetMinecraftEntity createMinecraftEntity(MyPet pet, org.bukkit.World bukkitWorld) {
    EntityMyPet petEntity = null;
    Class<? extends MyPetMinecraftEntity> entityClass = entityClasses.get(pet.getPetType());
    World world = ((CraftWorld) bukkitWorld).getHandle();
    try {
        Constructor<?> ctor = entityClass.getConstructor(World.class, MyPet.class);
        Object obj = ctor.newInstance(world, pet);
        if (obj instanceof EntityMyPet) {
            petEntity = (EntityMyPet) obj;
        }
    } catch (Exception e) {
        MyPetApi.getLogger().info(ChatColor.RED + Util.getClassName(entityClass) + "(" + pet.getPetType() + ") is no valid MyPet(Entity)!");
        e.printStackTrace();
    }
    return petEntity;
}
Also used : World(net.minecraft.server.v1_12_R1.World) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 14 with World

use of net.minecraft.server.v1_16_R3.World in project Denizen-For-Bukkit by DenizenScript.

the class CustomEntityHelperImpl method spawnFakePlayer.

public static FakePlayer spawnFakePlayer(Location location, String name, String skin, boolean doAdd) throws IllegalArgumentException {
    String fullName = name;
    String prefix = null;
    String suffix = null;
    if (name == null) {
        return null;
    } else if (fullName.length() > 16) {
        prefix = fullName.substring(0, 16);
        if (fullName.length() > 30) {
            int len = 30;
            name = fullName.substring(16, 30);
            if (name.matches(".*[^A-Za-z0-9_].*")) {
                if (fullName.length() >= 32) {
                    len = 32;
                    name = fullName.substring(16, 32);
                } else if (fullName.length() == 31) {
                    len = 31;
                    name = fullName.substring(16, 31);
                }
            } else if (name.length() > 46) {
                throw new IllegalArgumentException("You must specify a name with no more than 46 characters for FAKE_PLAYER entities!");
            } else {
                name = ChatColor.RESET + name;
            }
            suffix = fullName.substring(len);
        } else {
            name = fullName.substring(16);
            if (!name.matches(".*[^A-Za-z0-9_].*")) {
                name = ChatColor.RESET + name;
            }
            if (name.length() > 16) {
                suffix = name.substring(16);
                name = name.substring(0, 16);
            }
        }
    }
    if (skin != null && skin.length() > 16) {
        throw new IllegalArgumentException("You must specify a name with no more than 16 characters for FAKE_PLAYER entity skins!");
    }
    CraftWorld world = (CraftWorld) location.getWorld();
    WorldServer worldServer = world.getHandle();
    PlayerProfile playerProfile = new PlayerProfile(name, null);
    if (skin == null && !name.matches(".*[^A-Za-z0-9_].*")) {
        playerProfile = NMSHandler.getInstance().fillPlayerProfile(playerProfile);
    }
    if (skin != null) {
        PlayerProfile skinProfile = new PlayerProfile(skin, null);
        skinProfile = NMSHandler.getInstance().fillPlayerProfile(skinProfile);
        playerProfile.setTexture(skinProfile.getTexture());
        playerProfile.setTextureSignature(skinProfile.getTextureSignature());
    }
    UUID uuid = UUID.randomUUID();
    if (uuid.version() == 4) {
        long msb = uuid.getMostSignificantBits();
        msb &= ~0x0000000000004000L;
        msb |= 0x0000000000002000L;
        uuid = new UUID(msb, uuid.getLeastSignificantBits());
    }
    playerProfile.setUniqueId(uuid);
    GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
    gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
    final EntityFakePlayerImpl fakePlayer = new EntityFakePlayerImpl(worldServer.getMinecraftServer(), worldServer, gameProfile, new PlayerInteractManager(worldServer), doAdd);
    fakePlayer.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    CraftFakePlayerImpl craftFakePlayer = fakePlayer.getBukkitEntity();
    craftFakePlayer.fullName = fullName;
    if (prefix != null) {
        Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
        String teamName = "FAKE_PLAYER_TEAM_" + fullName;
        String hash = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] bytes = teamName.getBytes(StandardCharsets.UTF_8);
            md.update(bytes, 0, bytes.length);
            hash = new BigInteger(1, md.digest()).toString(16).substring(0, 16);
        } catch (Exception e) {
            Debug.echoError(e);
        }
        if (hash != null) {
            Team team = scoreboard.getTeam(hash);
            if (team == null) {
                team = scoreboard.registerNewTeam(hash);
                team.setPrefix(prefix);
                if (suffix != null) {
                    team.setSuffix(suffix);
                }
            }
            team.addPlayer(craftFakePlayer);
        }
    }
    return craftFakePlayer;
}
Also used : CraftFakePlayerImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.CraftFakePlayerImpl) PlayerProfile(com.denizenscript.denizen.nms.util.PlayerProfile) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) GameProfile(com.mojang.authlib.GameProfile) Scoreboard(org.bukkit.scoreboard.Scoreboard) PlayerInteractManager(net.minecraft.server.v1_16_R3.PlayerInteractManager) BigInteger(java.math.BigInteger) Team(org.bukkit.scoreboard.Team) UUID(java.util.UUID) MessageDigest(java.security.MessageDigest) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Property(com.mojang.authlib.properties.Property) EntityFakePlayerImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.EntityFakePlayerImpl)

Aggregations

CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)3 CraftFakePlayerImpl (com.denizenscript.denizen.nms.v1_16.impl.entities.CraftFakePlayerImpl)2 WorldServer (net.minecraft.server.v1_16_R3.WorldServer)2 World (net.minecraft.server.v1_7_R4.World)2 PlayerProfile (com.denizenscript.denizen.nms.util.PlayerProfile)1 EntityFakePlayerImpl (com.denizenscript.denizen.nms.v1_16.impl.entities.EntityFakePlayerImpl)1 EntityItemProjectileImpl (com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl)1 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)1 Mechanism (com.denizenscript.denizencore.objects.Mechanism)1 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 BigInteger (java.math.BigInteger)1 MessageDigest (java.security.MessageDigest)1 UUID (java.util.UUID)1 World (net.minecraft.server.v1_10_R1.World)1 World (net.minecraft.server.v1_11_R1.World)1 World (net.minecraft.server.v1_12_R1.World)1