示例#1
0
 /**
  * Ugly way to retrieve a name from a prefab
  *
  * @return a ":" seperated string, with name and flavor text.
  */
 public static String getName() {
   PrefabManager prefMan = CoreRegistry.get(PrefabManager.class);
   Prefab prefab = prefMan.getPrefab("miniion:nameslist");
   EntityRef namelist = CoreRegistry.get(EntityManager.class).create(prefab);
   namelist.hasComponent(namesComponent.class);
   namesComponent namecomp = namelist.getComponent(namesComponent.class);
   Random rand = new Random();
   return namecomp.namelist.get(rand.nextInt(namecomp.namelist.size()));
 }
示例#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();
   }
 }