Package org.spout.api.entity

Examples of org.spout.api.entity.Entity


  public static Entity mockEntity() {
    // TODO: this is broken, please fix.
    Engine engine = EngineFaker.setupEngine();

    final Entity entity = Mockito.mock(Entity.class);
    final EntityComponentAnswer componentHolder = new EntityComponentAnswer(entity);

    //Set up component holder methods
    Mockito.when(entity.add(Matchers.argThat(new ClassOrSubclassMatcher<EntityComponent>(EntityComponent.class)))).thenAnswer(componentHolder);
    Mockito.when(entity.get(Matchers.argThat(new ClassOrSubclassMatcher<EntityComponent>(EntityComponent.class)))).thenAnswer(componentHolder);
    Mockito.when(entity.getExact(Matchers.argThat(new ClassOrSubclassMatcher<EntityComponent>(EntityComponent.class)))).thenAnswer(componentHolder);
    Mockito.when(entity.detach(Matchers.argThat(new ClassOrSubclassMatcher<EntityComponent>(EntityComponent.class)))).thenAnswer(componentHolder);
    Mockito.when(entity.getData()).thenReturn(componentHolder.getData());
    Mockito.when(entity.getEngine()).thenAnswer(new EntityEngineAnswer(engine));

    //Set up entity tick
    Mockito.doAnswer(new EntityTickAnswer(entity)).when(entity).onTick(Mockito.anyFloat());

    //Set up event manager
View Full Code Here


*/
public class Human extends Living {
  @Override
  public void onAttached() {
    super.onAttached();
    Entity holder = getOwner();
    holder.add(PlayerItemCollector.class);
    holder.add(Digging.class);
    setEntityProtocol(new HumanEntityProtocol());
    if (getAttachedCount() == 1) {
      holder.add(Health.class).setSpawnHealth(20);
    }
    TextModelComponent textModel = getOwner().get(TextModelComponent.class);
    if (textModel != null) {
      textModel.setSize(0.5f);
      textModel.setTranslation(new Vector3f(0, 3f, 0));
    }
    //holder.getPhysics().activate(1, new BoxShape(1f, 2.3f, 1f), false, true);

    // Add metadata associated with the amount of arrows attached to the body
    holder.add(MetadataComponent.class).addMeta(Metadata.TYPE_BYTE, 10, VanillaData.ARROWS_IN_BODY);
  }
View Full Code Here

    setCreativeMode(creative, true);
  }

  public void setGamemode(GameMode mode, boolean updateClient) {
    boolean changeToFromCreative = getGameMode() == GameMode.CREATIVE;
    Entity holder = getOwner();
    if (holder instanceof Player) {
      PlayerGameModeChangedEvent event = holder.getEngine().getEventManager().callEvent(new PlayerGameModeChangedEvent((Player) getOwner(), mode));
      if (event.isCancelled()) {
        return;
      }
      changeToFromCreative ^= event.getMode() == GameMode.CREATIVE;
      GameMode old = getGameMode();
      mode = event.getMode();

      //In Survival we shoudn't be able to fly.
      setCanFly(mode == GameMode.CREATIVE, updateClient);
      if (changeToFromCreative) {
        if (callAbilityChangeEvent().isCancelled()) {
          mode = old;
        }
      }
      if (updateClient) {
        holder.getNetwork().callProtocolEvent(new PlayerGameStateEvent((Player) holder, PlayerGameStateMessage.CHANGE_GAME_MODE, mode), (Player) getOwner());
      }
    }
    getData().put(VanillaData.GAMEMODE, mode);
  }
View Full Code Here

    if (potentialToFollow.size() == 0) {
      return null;
    }
    Random random = GenericMath.getRandom();
    final int choice = random.nextInt(potentialToFollow.size());
    final Entity chosenEntity = (Entity) potentialToFollow.get(choice);
    follow(chosenEntity);
    return chosenEntity;
  }
View Full Code Here

    if (human == null) {
      direction = player.getPhysics().getRotation().getDirection();
    } else {
      direction = human.getHead().getLookingAt();
    }
    Entity nearest = null;
    for (double d = 0.0; d <= 50.0; d += 0.25) {
      Point pos = point.add(direction.mul(d));
      Entity near = point.getWorld().getNearestEntity(pos, player, (int) lastDistanceToEntity);
      if (near == null) {
        continue;
      }
      double distance = pos.distance(near.getPhysics().getPosition());
      if (distance < lastDistanceToEntity) {
        lastDistanceToEntity = distance;
        nearest = near;
        if (distance < 0.5) {
          break;
View Full Code Here

    //if (!player.hasPermission("vanilla.command.spawn." + clazz.getName().toLowerCase())) {
    //  throw new CommandException("You do not have permission to spawn a(n) " + clazz.getSimpleName().toLowerCase());
    //}
    //TODO ServerEntityPrefab!
    //How about some client support?
    final Entity entity;
    if (getEngine() instanceof Client) {
      final EntityPrefab prefab = getEngine().getFileSystem().getResource("entity://Vanilla/entities/" + clazz.getSimpleName().toLowerCase() + "/" + clazz.getSimpleName().toLowerCase() + ".sep");
      entity = prefab.createEntity(player.getPhysics().getPosition());
    } else {
      entity = player.getWorld().createEntity(player.getPhysics().getPosition(), clazz);
    }
    //Optional param was provided (ie the block material for a falling block).
    if (args.length() == 2) {
      //Now we know its either a living or substance. Lets figure out which.
      if (Living.class.isAssignableFrom(clazz)) {
        final Living living = entity.get(Living.class);
        if (name.equalsIgnoreCase("human")) {
          ((Human) living).setName(args.popString("disp_name"));
        }
      } else if (Substance.class.isAssignableFrom(clazz)) {
        final Substance substance = entity.get(Substance.class);
        switch (ObjectType.valueOf(name.toUpperCase())) {
          case ITEM:
            Material item = VanillaArgumentTypes.popMaterial("item", args);
            ((Item) substance).setItemStack(new ItemStack(item, 1));
            break;
          case FALLING_OBJECT:
            Material block = VanillaArgumentTypes.popMaterial("block", args);
            if (!(block instanceof BlockMaterial)) {
              throw new CommandException("Material " + block.getDisplayName() + " is not a block!");
            }
            ((FallingBlock) substance).setMaterial((BlockMaterial) block);
            break;
        }
      }
    }
    args.assertCompletelyParsed();
    player.getWorld().spawnEntity(entity);
    if (child) {
      entity.get(Ageable.class).setAge(Ageable.MIN_AGE);
    }
  }
View Full Code Here

        // Load or generate spawn area
        int effectiveRadius = newWorld ? (2 * radius) : radius;

        // Add observer to spawn to keep loaded if desired
        if (worldConfig.LOADED_SPAWN.getBoolean()) {
          @SuppressWarnings ("unchecked")
          Entity e = world.createAndSpawnEntity(spawn, LoadOption.LOAD_GEN, NetworkComponent.class);
          e.get(NetworkComponent.class).setObserver(new FlatIterator(cx, 0, cz, 16, effectiveRadius));
        }
      }

      // Set the appropriate sky for the world type
      if (generator instanceof NetherGenerator) {
View Full Code Here

  private GoapAIComponent ai;

  @Override
  public void onAttached() {
    super.onAttached();
    Entity holder = getOwner();
    head = holder.add(EntityHead.class);
    health = holder.add(Health.class);
    drowning = holder.add(Drowning.class);
    navigation = holder.add(NavigationComponent.class);
    navigation.setDefaultExaminers(new VanillaBlockExaminer());
    ai = holder.add(GoapAIComponent.class);
    holder.add(Burn.class);
    if (!(holder instanceof Player)) {
      holder.add(VanillaNetworkComponent.class);
    }

    // Description (use Class name as default)
    holder.add(Descriptor.class).setName(getClass().getSimpleName());

    // Add metadata associated with general living Entity properties
    getOwner().add(MetadataComponent.class).addMeta(new Metadata<Byte>(Metadata.TYPE_BYTE, 0) {
      @Override
      public Byte getValue() {
View Full Code Here

   *
   * @param animal to breed with
   */
  @SuppressWarnings ("unchecked")
  public void breed(Animal animal) {
    Entity owner = getOwner();
    if (canBreedWith(animal)) {
      Animal child = owner.getWorld().createAndSpawnEntity(owner.getPhysics().getPosition(), LoadOption.LOAD_ONLY, animal.getClass()).get(Animal.class);
      setAge(MAX_AGE);
      animal.setAge(MAX_AGE);
      setInLove(false);
      animal.setInLove(false);
      child.setAge(MIN_AGE);
View Full Code Here

   */
  public static Item drop(Point position, ItemStack itemStack, Vector3f velocity) {
    if (itemStack == null || itemStack.getMaterial() == VanillaMaterials.AIR) {
      throw new IllegalArgumentException("The dropped item can not be null or air!");
    }
    Entity entity = position.getWorld().createEntity(position, Item.class);
    Item item = entity.get(Item.class);
    item.setUncollectableDelay(DROP_PICKUP_DELAY);
    item.setItemStack(itemStack);
    if (position.getChunk(LoadOption.NO_LOAD) != null) {
      position.getWorld().spawnEntity(entity);
      entity.getPhysics().force(velocity);
    }
    return item;
  }
View Full Code Here

TOP

Related Classes of org.spout.api.entity.Entity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.