コード例 #1
0
  private void handlePressurePlateEvents() {
    Set<Vector3i> toRemoveSignal = Sets.newHashSet(activatedPressurePlates);

    Iterable<EntityRef> players =
        entityManager.getEntitiesWith(CharacterComponent.class, LocationComponent.class);
    for (EntityRef player : players) {
      Vector3f playerLocation = player.getComponent(LocationComponent.class).getWorldPosition();
      Vector3i locationBeneathPlayer =
          new Vector3i(playerLocation.x + 0.5f, playerLocation.y - 0.5f, playerLocation.z + 0.5f);
      Block blockBeneathPlayer = worldProvider.getBlock(locationBeneathPlayer);
      if (blockBeneathPlayer == signalPressurePlate) {
        EntityRef entityBeneathPlayer = blockEntityRegistry.getBlockEntityAt(locationBeneathPlayer);
        SignalProducerComponent signalProducer =
            entityBeneathPlayer.getComponent(SignalProducerComponent.class);
        if (signalProducer != null) {
          if (signalProducer.signalStrength == 0) {
            startProducingSignal(entityBeneathPlayer, -1);
            activatedPressurePlates.add(locationBeneathPlayer);
          } else {
            toRemoveSignal.remove(locationBeneathPlayer);
          }
        }
      }
    }

    for (Vector3i pressurePlateLocation : toRemoveSignal) {
      EntityRef pressurePlate = blockEntityRegistry.getBlockEntityAt(pressurePlateLocation);
      SignalProducerComponent signalProducer =
          pressurePlate.getComponent(SignalProducerComponent.class);
      if (signalProducer != null) {
        stopProducingSignal(pressurePlate);
        activatedPressurePlates.remove(pressurePlateLocation);
      }
    }
  }
コード例 #2
0
  @Override
  public boolean step() {
    EntityManager entityManager = context.get(EntityManager.class);
    WorldRenderer worldRenderer = context.get(WorldRenderer.class);

    Iterator<EntityRef> worldEntityIterator =
        entityManager.getEntitiesWith(WorldComponent.class).iterator();
    // TODO: Move the world renderer bits elsewhere
    if (worldEntityIterator.hasNext()) {
      EntityRef worldEntity = worldEntityIterator.next();
      worldRenderer.getChunkProvider().setWorldEntity(worldEntity);

      // get the world generator config from the world entity
      // replace the world generator values from the components in the world entity
      WorldGenerator worldGenerator = context.get(WorldGenerator.class);
      WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
      Map<String, Component> params = worldConfigurator.getProperties();
      for (Map.Entry<String, Component> entry : params.entrySet()) {
        Class<? extends Component> clazz = entry.getValue().getClass();
        Component comp = worldEntity.getComponent(clazz);
        if (comp != null) {
          worldConfigurator.setProperty(entry.getKey(), comp);
        }
      }
    } else {
      EntityRef worldEntity = entityManager.create();
      worldEntity.addComponent(new WorldComponent());
      worldRenderer.getChunkProvider().setWorldEntity(worldEntity);

      // transfer all world generation parameters from Config to WorldEntity
      WorldGenerator worldGenerator = context.get(WorldGenerator.class);
      SimpleUri generatorUri = worldGenerator.getUri();
      Config config = context.get(Config.class);

      // get the map of properties from the world generator.
      // Replace its values with values from the config set by the UI.
      // Also set all the components to the world entity.
      WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
      Map<String, Component> params = worldConfigurator.getProperties();
      for (Map.Entry<String, Component> entry : params.entrySet()) {
        Class<? extends Component> clazz = entry.getValue().getClass();
        Component comp = config.getModuleConfig(generatorUri, entry.getKey(), clazz);
        if (comp != null) {
          worldEntity.addComponent(comp);
          worldConfigurator.setProperty(entry.getKey(), comp);
        } else {
          worldEntity.addComponent(entry.getValue());
        }
      }
    }

    return true;
  }
コード例 #3
0
  @Override
  public void update(float delta) {
    for (EntityRef entity : entityManager.getEntitiesWith(HealthComponent.class)) {
      HealthComponent health = entity.getComponent(HealthComponent.class);
      if (health.currentHealth <= 0) {
        continue;
      }

      if (health.currentHealth == health.maxHealth || health.regenRate == 0) {
        continue;
      }

      int healAmount = 0;
      healAmount = regenerateHealth(health, healAmount);

      checkHealed(entity, health, healAmount);
    }
  }