void update(
      EntityRef localPlayer,
      float delta,
      EntityRef target,
      Vector3i targetBlockPos,
      Vector3f hitPosition,
      Vector3f hitNormal) {
    boolean posInput = positiveInput.getState() == ButtonState.DOWN;
    boolean negInput = negativeInput.getState() == ButtonState.DOWN;

    float targetValue = 0;
    if (!CoreRegistry.get(GUIManager.class).isConsumingInput()) {
      if (posInput) {
        targetValue += 1.0f;
      }
      if (negInput) {
        targetValue -= 1.0f;
      }
    }

    // TODO: Interpolate, based on some settings (immediate, linear, lerp?)

    float newValue = targetValue;

    if (sendEventMode.shouldSendEvent(value, newValue)) {
      event.prepare(id, newValue, delta);
      event.setTarget(target, targetBlockPos, hitPosition, hitNormal);
      localPlayer.send(event);
      sendEventToSubscribers(delta, target);
    }
    value = newValue;
  }
示例#2
0
 /**
  * triggered when a block was destroyed and dropped in the world used to intercept gathering by
  * minions and sending the block to their inventory the droppedblock in the world then gets
  * destroyed, possible duplication exploit
  */
 @ReceiveEvent(components = {MinionComponent.class})
 public void onBlockDropped(BlockDroppedEvent event, EntityRef entity) {
   if (entity.hasComponent(MinionComponent.class)) {
     EntityRef item;
     if (event.getOldBlock().getEntityMode() == BlockEntityMode.PERSISTENT) {
       item = blockItemFactory.newInstance(event.getOldBlock().getBlockFamily(), entity);
     } else {
       item = blockItemFactory.newInstance(event.getOldBlock().getBlockFamily());
     }
     entity.send(new ReceiveItemEvent(item));
     event.getDroppedBlock().destroy();
   }
 }
示例#3
0
  public EntityRef newInstance(Vector3f spawnPosition) {
    EntityRef player = entityManager.create("core:player");
    LocationComponent location = player.getComponent(LocationComponent.class);
    location.setWorldPosition(spawnPosition);
    player.saveComponent(location);
    PlayerComponent playerComponent = player.getComponent(PlayerComponent.class);
    playerComponent.spawnPosition.set(spawnPosition);
    player.saveComponent(playerComponent);
    player.addComponent(new LocalPlayerComponent());

    // Goodie chest
    EntityRef chest =
        blockFactory.newInstance(BlockManager.getInstance().getBlockFamily("core:chest"));
    BlockItemComponent blockItem = chest.getComponent(BlockItemComponent.class);
    EntityRef chestContents = blockItem.placedEntity;

    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("core:companion"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:brick:engine:stair"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(BlockManager.getInstance().getBlockFamily("core:Tnt"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("books:Bookcase"), 1)));

    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:clay:engine:slope"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:clay:engine:steepslope"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:StoneStair"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:marble:engine:stair"), 99)));

    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Marble"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:marble:engine:testsphere"),
                99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:marble:engine:slope"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:marble:engine:steepslope"),
                99)));

    chestContents.send(new ReceiveItemEvent(entityManager.create("potions:purplepotion")));
    chestContents.send(new ReceiveItemEvent(entityManager.create("potions:greenpotion")));
    chestContents.send(new ReceiveItemEvent(entityManager.create("potions:orangepotion")));
    chestContents.send(new ReceiveItemEvent(entityManager.create("potions:redpotion")));

    chestContents.send(new ReceiveItemEvent(entityManager.create("books:book")));
    chestContents.send(new ReceiveItemEvent(entityManager.create("books:bluebook")));
    chestContents.send(new ReceiveItemEvent(entityManager.create("books:redbook")));
    chestContents.send(new ReceiveItemEvent(entityManager.create("core:railgunTool")));

    chestContents.send(new ReceiveItemEvent(entityManager.create("core:mrbarsack")));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Cobaltite"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:NativeGoldOre"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Microcline"), 99)));

    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:Brick"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(BlockManager.getInstance().getBlockFamily("engine:Ice"), 99)));
    chestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:Plank"), 99)));

    EntityRef doorItem = entityManager.create("core:door");
    ItemComponent doorItemComp = doorItem.getComponent(ItemComponent.class);
    doorItemComp.stackCount = 20;
    doorItem.saveComponent(doorItemComp);
    chestContents.send(new ReceiveItemEvent(doorItem));

    // Inner goodie chest
    EntityRef innerChest =
        blockFactory.newInstance(BlockManager.getInstance().getBlockFamily("core:Chest"));
    BlockItemComponent innerBlockItem = innerChest.getComponent(BlockItemComponent.class);
    EntityRef innerChestContents = innerBlockItem.placedEntity;

    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Alabaster"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Basalt"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Gabbro"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Hornblende"), 99)));

    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:OrangeSandStone"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Phyllite"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Schist"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Cinnabar"), 99)));

    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:Lava"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:Water"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Rutile"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("minerals:Kaolinite"), 99)));

    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:Iris"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:Dandelion"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:Tulip"), 99)));
    innerChestContents.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:YellowFlower"), 99)));

    // Place inner chest into outer chest
    chestContents.send(new ReceiveItemEvent(innerChest));

    player.send(new ReceiveItemEvent(entityManager.create("core:pickaxe")));
    player.send(new ReceiveItemEvent(entityManager.create("core:axe")));
    player.send(
        new ReceiveItemEvent(
            blockFactory.newInstance(
                BlockManager.getInstance().getBlockFamily("engine:Torch"), 99)));
    player.send(new ReceiveItemEvent(entityManager.create("core:explodeTool")));
    player.send(new ReceiveItemEvent(entityManager.create("core:railgunTool")));
    player.send(new ReceiveItemEvent(entityManager.create("core:miniaturizer")));
    player.send(new ReceiveItemEvent(chest));

    return player;
  }
  private void checkForLootedBlocks() {
    LocalPlayer player = CoreRegistry.get(LocalPlayer.class);

    // to send blocks to minions, some needed classes
    EntityRef playerent = player.getEntity();
    LocalPlayerComponent localPlayerComp = playerent.getComponent(LocalPlayerComponent.class);
    MinionBarComponent inventory = null;
    EntityRef closestminion = null;
    if (localPlayerComp.minionMode) {
      inventory = playerent.getComponent(MinionBarComponent.class);
    }

    for (int i = _blocks.size() - 1; i >= 0; i--) {
      BlockRigidBody b = _blocks.get(i);

      if (b._temporary) continue;

      float closestDist = 99999;
      if (inventory != null) {
        // check for the closest minion
        Iterator<EntityRef> it = inventory.MinionSlots.iterator();
        while (it.hasNext()) {
          EntityRef minion = it.next();
          if (b.distanceToEntity(minion) < closestDist) {
            closestDist = b.distanceToEntity(minion);
            closestminion = minion;
          }
        }
      }

      if (localPlayerComp.minionMode) {
        if (closestDist < 8 && !b._picked) {
          b._picked = true;
        }
      } else {
        closestDist = b.distanceToPlayer();
        // Check if the block is close enough to the player
        if (b.distanceToPlayer() < 8.0f && !b._picked) {
          // Mark it as picked and remove it from the simulation
          b._picked = true;
        }
      }

      // Block was marked as being picked
      if (b._picked && closestDist < 32.0f) {
        // Animate the movement in direction of the player
        if (closestDist > 1.0) {
          Transform t = new Transform();
          b.getMotionState().getWorldTransform(t);

          Matrix4f tMatrix = new Matrix4f();
          t.getMatrix(tMatrix);

          Vector3f blockPlayer = new Vector3f();
          tMatrix.get(blockPlayer);
          if (localPlayerComp.minionMode && closestminion != null) {
            LocationComponent minionloc = closestminion.getComponent(LocationComponent.class);
            if (minionloc != null) blockPlayer.sub(minionloc.getWorldPosition());
            else blockPlayer.sub(new Vector3f());
          } else {
            blockPlayer.sub(new Vector3f(player.getPosition()));
          }
          blockPlayer.normalize();
          blockPlayer.scale(-16000f);

          b.applyCentralImpulse(blockPlayer);
        } else {
          // TODO: Handle full inventories
          // TODO: Loot blocks should be entities
          // Block was looted (and reached the player)
          Block block = BlockManager.getInstance().getBlock(b.getType());
          EntityRef blockItem = _blockItemFactory.newInstance(block.getBlockFamily());

          if (localPlayerComp.minionMode) {
            if (closestminion != null) {
              closestminion.send(new ReceiveItemEvent(blockItem));
            }
          } else {
            playerent.send(new ReceiveItemEvent(blockItem));
          }
          ItemComponent itemComp = blockItem.getComponent(ItemComponent.class);
          if (itemComp != null && !itemComp.container.exists()) {
            blockItem.destroy();
          }
          AudioManager.play(new AssetUri(AssetType.SOUND, "engine:Loot"));

          _blocks.remove(i);
          _discreteDynamicsWorld.removeRigidBody(b);
        }
      }
    }
  }