public static SpawnEntityEvent callEntityJoinWorldEvent(Event event) {
    if (!(event instanceof SpawnEntityEvent)) {
      throw new IllegalArgumentException("Event is not a valiud SpawnEntityEvent.");
    }

    SpawnEntityEvent spongeEvent = (SpawnEntityEvent) event;
    Iterator<org.spongepowered.api.entity.Entity> iterator = spongeEvent.getEntities().iterator();
    while (iterator.hasNext()) {
      org.spongepowered.api.entity.Entity entity = iterator.next();
      EntityJoinWorldEvent forgeEvent =
          new EntityJoinWorldEvent(
              (net.minecraft.entity.Entity) entity,
              (net.minecraft.world.World) entity.getLocation().getExtent());

      ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
      if (forgeEvent.isCanceled()) {
        iterator.remove();
      }
    }
    return spongeEvent;
  }
예제 #2
0
 @SubscribeEvent
 public void onHorseSpawn(EntityJoinWorldEvent event) {
   if (event.entity instanceof EntityHorse) {
     if (event.entity.getClass() == EntityHorse.class) {
       event.setCanceled(true);
     } else {
       if (event.entity.getClass() == EntityBaseHorse.class) {
         System.out.println(
             event.entity.posX + ", " + event.entity.posY + ", " + event.entity.posZ);
       }
     }
   }
 }
예제 #3
0
  @SubscribeEvent
  public void PlayerJoinWorld(EntityJoinWorldEvent evt) {
    if (evt.entity instanceof IPokemob) {
      if (evt.entity.getEntityData().getBoolean("isPlayer")) {
        UUID uuid = UUID.fromString(evt.entity.getEntityData().getString("playerID"));
        EntityPlayer player = evt.world.getPlayerEntityByUUID(uuid);
        IPokemob evo = (IPokemob) evt.entity;
        proxy.setPokemob(player, evo);
        evt.setCanceled(true);
      }
    }

    if (!(evt.entity instanceof EntityPlayer)) return;
    EntityPlayer player = (EntityPlayer) evt.entity;
    if (!player.worldObj.isRemote) {
      new SendPacket(player);
      new SendExsistingPacket(player);
    }
  }