Search in sources :

Example 11 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class ItemSpawn method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
    Location location = against.getLocation().add(face.getModX(), face.getModY(), face.getModZ());
    // TODO: change mob spawner when clicked by monster egg
    if (holding.hasItemMeta() && holding.getItemMeta() instanceof GlowMetaSpawn) {
        GlowMetaSpawn meta = (GlowMetaSpawn) holding.getItemMeta();
        EntityType type = meta.getSpawnedType();
        CompoundTag tag = meta.getEntityTag();
        if (type != null) {
            GlowEntity entity = against.getWorld().spawn(location.add(0.5, 0, 0.5), EntityRegistry.getEntity(type), SpawnReason.SPAWNER_EGG);
            if (tag != null) {
                EntityStorage.load(entity, tag);
            }
            if (player.getGameMode() != GameMode.CREATIVE) {
                holding.setAmount(holding.getAmount() - 1);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) GlowEntity(net.glowstone.entity.GlowEntity) GlowMetaSpawn(net.glowstone.inventory.GlowMetaSpawn) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location)

Example 12 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class SummonCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages commandMessages) {
    if (!testPermission(sender, commandMessages.getPermissionMessage())) {
        return true;
    }
    if (sender instanceof ConsoleCommandSender) {
        commandMessages.getGeneric(GenericMessage.NOT_PHYSICAL).send(sender);
        return true;
    }
    Location location = CommandUtils.getLocation(sender);
    if (args.length == 0) {
        sendUsageMessage(sender, commandMessages);
        return false;
    }
    if (args.length >= 4) {
        location = CommandUtils.getLocation(location, args[1], args[2], args[3]);
    }
    location.setYaw(0.0f);
    location.setPitch(0.0f);
    CompoundTag tag = null;
    if (args.length >= 5) {
        String data = String.join(" ", new ArrayList<>(Arrays.asList(args)).subList(4, args.length));
        try {
            tag = Mojangson.parseCompound(data);
        } catch (MojangsonParseException e) {
            commandMessages.getGeneric(GenericMessage.INVALID_JSON).sendInColor(ChatColor.RED, sender, e.getMessage());
        }
    }
    String entityName = args[0];
    if (!checkSummon(sender, entityName, commandMessages)) {
        return true;
    }
    GlowEntity entity;
    if (EntityType.fromName(entityName) != null) {
        entity = (GlowEntity) location.getWorld().spawnEntity(location, EntityType.fromName(entityName));
    } else {
        Class<? extends GlowEntity> clazz = EntityRegistry.getCustomEntityDescriptor(entityName).getEntityClass();
        entity = ((GlowWorld) location.getWorld()).spawn(location, clazz, CreatureSpawnEvent.SpawnReason.CUSTOM);
    }
    if (tag != null) {
        EntityStorage.load(entity, tag);
    }
    new LocalizedStringImpl("summon.done", commandMessages.getResourceBundle()).send(sender);
    return true;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) ArrayList(java.util.ArrayList) MojangsonParseException(net.glowstone.util.mojangson.ex.MojangsonParseException) GlowEntity(net.glowstone.entity.GlowEntity) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location)

Example 13 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class GlowGuardian method setElder.

@Override
public void setElder(boolean elder) {
    if (elder == isElder()) {
        return;
    }
    Class<? extends GlowEntity> clazz = elder ? GlowElderGuardian.class : GlowGuardian.class;
    GlowEntity copy = world.spawn(location, clazz);
    CompoundTag tag = new CompoundTag();
    // Copy attributes
    EntityStorage.save(this, tag);
    EntityStorage.load(copy, tag);
    remove();
}
Also used : GlowEntity(net.glowstone.entity.GlowEntity) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 14 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class GlowFirework method pulsePhysics.

@Override
protected void pulsePhysics() {
    // TODO: proper physics
    if (this.boostedEntity == null) {
        // Fireworks velocity is not affected by airdrag or gravity
        // These values are static
        velocity.setX(velocity.getX() * 1.15);
        velocity.setY(velocity.getY() + 0.04);
        velocity.setZ(velocity.getZ() * 1.15);
        setVelocity(velocity);
    } else {
        Vector direction = boostedEntity.getLocation().getDirection();
        Vector velocity = boostedEntity.getVelocity();
        // close enough approximation of vanillas velocity for boosted entity
        double dx = direction.getX() * 0.1 + (direction.getX() * 1.5 - velocity.getX()) * 0.5;
        double dy = direction.getY() * 0.1 + (direction.getY() * 1.5 - velocity.getY()) * 0.5;
        double dz = direction.getZ() * 0.1 + (direction.getZ() * 1.5 - velocity.getZ()) * 0.5;
        velocity.setX(velocity.getX() + dx);
        velocity.setY(velocity.getY() + dy);
        velocity.setZ(velocity.getZ() + dz);
        boostedEntity.setVelocity(velocity);
        this.setVelocity(velocity);
        Location location = boostedEntity.getLocation().add(velocity);
        if (boostedEntity instanceof GlowEntity) {
            ((GlowEntity) boostedEntity).setRawLocation(location, false);
        } else {
            boostedEntity.teleport(location);
        }
    }
    setRawLocation(this.location.add(velocity), false);
}
Also used : GlowEntity(net.glowstone.entity.GlowEntity) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 15 with GlowEntity

use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.

the class GlowEgg method randomHatchSpawning.

/**
 * Handle spawning entities when the egg breaks.
 *
 * @param location The location the egg breaks
 */
private void randomHatchSpawning(Location location) {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    // There is a 1/8 chance for egg to hatch and spawn at least 1 entity
    boolean hatching = random.nextInt(8) == 0;
    // ...and if the egg is hatching, there is now
    // 1/32 chance to spawn 3 more entities.
    byte amount;
    if (hatching) {
        amount = (byte) ((random.nextInt(32) == 0) ? 4 : 1);
    } else {
        amount = 0;
    }
    EntityType hatchingType = EntityType.CHICKEN;
    final ProjectileSource shooter = getShooter();
    if (shooter instanceof GlowPlayer) {
        PlayerEggThrowEvent event = EventFactory.getInstance().callEvent(new PlayerEggThrowEvent((GlowPlayer) shooter, this, hatching, amount, hatchingType));
        amount = event.getNumHatches();
        hatching = event.isHatching();
        hatchingType = event.getHatchingType();
    }
    if (hatching) {
        for (int i = 0; i < amount; i++) {
            GlowEntity entity = (GlowEntity) location.getWorld().spawnEntity(location.clone().add(0, 0.3, 0), hatchingType);
            if (entity instanceof GlowAgeable) {
                ((GlowAgeable) entity).setBaby();
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) GlowPlayer(net.glowstone.entity.GlowPlayer) PlayerEggThrowEvent(org.bukkit.event.player.PlayerEggThrowEvent) GlowEntity(net.glowstone.entity.GlowEntity) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GlowAgeable(net.glowstone.entity.GlowAgeable) ProjectileSource(org.bukkit.projectiles.ProjectileSource)

Aggregations

GlowEntity (net.glowstone.entity.GlowEntity)19 Location (org.bukkit.Location)9 GlowPlayer (net.glowstone.entity.GlowPlayer)8 CompoundTag (net.glowstone.util.nbt.CompoundTag)8 Vector (org.bukkit.util.Vector)7 ArrayList (java.util.ArrayList)6 Entity (org.bukkit.entity.Entity)4 EntityType (org.bukkit.entity.EntityType)4 LivingEntity (org.bukkit.entity.LivingEntity)3 Message (com.flowpowered.network.Message)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 EventFactory (net.glowstone.EventFactory)2 BoundingBox (net.glowstone.entity.physics.BoundingBox)2 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)2 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)2 ItemStack (org.bukkit.inventory.ItemStack)2