コード例 #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
 // Generates all non-temporary block entities
 private void generateBlockEntities(Chunk chunk) {
   ChunkBlockIterator i = chunk.getBlockIterator();
   while (i.next()) {
     if (i.getBlock().isKeepActive()) {
       registry.getBlockEntityAt(i.getBlockPos());
     }
   }
 }
コード例 #3
0
    @Override
    public boolean isConnectingTo(
        Vector3i blockLocation,
        Side connectSide,
        WorldProvider worldProvider,
        BlockEntityRegistry blockEntityRegistry) {
      Vector3i neighborLocation = new Vector3i(blockLocation);
      neighborLocation.add(connectSide.getVector3i());

      EntityRef neighborEntity = blockEntityRegistry.getBlockEntityAt(neighborLocation);
      return neighborEntity != null && connectsToNeighbor(neighborEntity);
    }
コード例 #4
0
  private void handleDelayedActionsEvents() {
    long worldTime = time.getGameTimeInMs();
    BlockAtLocationDelayedAction action;
    while ((action = delayedActions.peek()) != null && action.executeTime <= worldTime) {
      action = delayedActions.poll();

      final Vector3i actionLocation = action.blockLocation.toVector3i();
      if (worldProvider.isBlockRelevant(actionLocation)) {
        final Block block = worldProvider.getBlock(actionLocation);
        final BlockFamily blockFamily = block.getBlockFamily();

        final EntityRef blockEntity = blockEntityRegistry.getBlockEntityAt(actionLocation);

        if (blockFamily == signalOnDelayGate) {
          startProducingSignal(blockEntity, -1);
        } else if (blockFamily == signalOffDelayGate) {
          stopProducingSignal(blockEntity);
        } else if (blockFamily == signalOrGate
            || blockFamily == signalAndGate
            || blockFamily == signalXorGate) {
          if (processOutputForNormalGate(blockEntity)) {
            gateLastSignalChangeTime.put(new ImmutableBlockLocation(actionLocation), worldTime);
          }
        } else if (blockFamily == signalNandGate) {
          if (processOutputForRevertedGate(blockEntity)) {
            gateLastSignalChangeTime.put(new ImmutableBlockLocation(actionLocation), worldTime);
          }
        } else if (blockFamily == signalSetResetGate) {
          if (processOutputForSetResetGate(blockEntity)) {
            gateLastSignalChangeTime.put(new ImmutableBlockLocation(actionLocation), worldTime);
          }
        } else if (block == signalButton) {
          stopProducingSignal(blockEntity);
        }

        blockEntity.removeComponent(SignalDelayedActionComponent.class);
      } else {
        // TODO Remove this workaround when BlockEntities will be stored with the chunk they belong
        // to
        action.executeTime += NOT_LOADED_BLOCK_RETRY_DELAY;
        delayedActions.add(action);
      }
    }
  }
コード例 #5
0
 private void processEvent(NetData.EventMessage message) {
   try {
     Event event = eventSerializer.deserialize(message.getEvent());
     EntityRef target = EntityRef.NULL;
     if (message.hasTargetBlockPos()) {
       target =
           blockEntityRegistry.getBlockEntityAt(
               NetMessageUtil.convert(message.getTargetBlockPos()));
     } else if (message.hasTargetId()) {
       target = networkSystem.getEntity(message.getTargetId());
     }
     if (target.exists()) {
       target.send(event);
     } else {
       logger.info(
           "Dropping event {} for unavailable entity {}",
           event.getClass().getSimpleName(),
           target);
     }
   } catch (DeserializationException e) {
     logger.error("Failed to deserialize event", e);
   }
 }