@ReceiveEvent(components = {BlockComponent.class})
 public void onActivateBlock(OnActivatedComponent event, EntityRef entity) {
   BlockComponent block = entity.getComponent(BlockComponent.class);
   EntityRef oldEntity = blockEntityLookup.put(new Vector3i(block.getPosition()), entity);
   // If this is a client, then an existing block entity may exist. Destroy it.
   if (oldEntity != null && !Objects.equal(oldEntity, entity)) {
     oldEntity.destroy();
   }
 }
Example #2
0
 private void processRemoveEntities(NetData.NetMessage message) {
   for (NetData.RemoveEntityMessage removeEntity : message.getRemoveEntityList()) {
     int netId = removeEntity.getNetId();
     EntityRef entity = networkSystem.getEntity(netId);
     if (entity.exists()) {
       logger.info("Destroying entity: {}", entity);
       entity.destroy();
       networkSystem.unregisterClientNetworkEntity(netId);
     }
   }
 }
 private boolean canOutputResult(EntityRef workstation, String resultObject) {
   EntityRef resultItem = createResultItem(resultObject);
   try {
     for (int outputSlot : WorkstationInventoryUtils.getAssignedSlots(workstation, "OUTPUT")) {
       if (InventoryUtils.canStackInto(
           resultItem, InventoryUtils.getItemAt(workstation, outputSlot))) {
         return true;
       }
     }
   } finally {
     resultItem.destroy();
   }
   return false;
 }
  @Override
  public void executeEnd(EntityRef instigator, EntityRef workstation, EntityRef processEntity) {
    OutputTypeComponent output = processEntity.getComponent(OutputTypeComponent.class);
    EntityRef toGive = createResultItem(output.type);

    if (CoreRegistry.get(InventoryManager.class)
        .giveItem(
            workstation,
            instigator,
            toGive,
            WorkstationInventoryUtils.getAssignedSlots(workstation, "OUTPUT"))) {
      return;
    }
    toGive.destroy();
  }