Exemplo n.º 1
0
  // When a chunk unloads, remove its monsters, excluding Withers
  // EnderDragon is NOT a monster, it is a ComplexLivingEntity (LEAVE ENDER ALONE)
  // Hoping this cuts down on lag?
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    for (Entity entity : chunk.getEntities()) {
      if (!entity.isDead() && entity instanceof Monster) {
        Monster monster = (Monster) entity;

        Boolean remove = true;

        if (monster.getCustomName() != null) {
          remove = false;
        }
        if (monster.getType() == EntityType.WITHER) {
          remove = false;
        }
        for (ItemStack item : monster.getEquipment().getArmorContents()) {
          if (item != null) {
            remove = false;
            break;
          }
        }
        if ((monster.getEquipment().getItemInHand() != null)
            || (monster.getType() == EntityType.SKELETON
                && monster.getEquipment().getItemInHand().getType() != Material.BOW)) {
          remove = false;
        }
        if (remove) {
          if (monster.getVehicle() instanceof Chicken) {
            monster.getVehicle().remove();
          }
          monster.remove();
        }
      }
    }
  }
Exemplo n.º 2
0
 public void update(Vector2f loc, int dt) {
   for (Entity alien : entities) {
     if (!alien.isDead()) {
       alien.update(loc, dt);
     }
   }
   if (spawnsEnabled) updateSpawns(dt);
 }
Exemplo n.º 3
0
 @Override
 public void update(int dt) {
   for (Entity alien : entities) {
     if (!alien.isDead()) {
       alien.update(dt);
     } else {
       remove(alien);
     }
   }
   if (spawnsEnabled) updateSpawns(dt);
 }
Exemplo n.º 4
0
  public Client() throws IOException {

    Global.tiles =
        new Tile[] {
          new Tile("wall.png"),
          new Tile("floor.jpg"),
          new Tile("warrior.png"),
          new Tile("fireball.png"),
          new Tile("mage.png")
        };

    Global.cameraPosition = new Point(0, 0);
    Global.visibleFrame = new Rectangle(0, 0, 640, 480);

    Renderer rend = new Renderer();
    rend.setVisible(true);

    rend.addKeyListener(keyProcessor);
    rend.addComponentListener(eventsProcessor);
    rend.getComponent(0).addMouseListener(mouseProcessor);

    Socket socket = null;
    try {
      socket = new Socket("localhost", 8080);
      //			socket = new Socket("192.168.77.1", 8080);
      // socket = new Socket("192.168.77.1", 8080);

      Global.socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      Global.socketWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    {
      int ysize = Integer.parseInt(Global.socketReader.readLine());
      int xsize = Integer.parseInt(Global.socketReader.readLine());

      ArrayList<Entity> list = new ArrayList<Entity>();

      for (int y = 0; y < ysize; y++) {
        for (int x = 0; x < xsize; x++) {
          int globalId = Integer.parseInt(Global.socketReader.readLine());

          Entity en = new Entity(globalId);

          int N = Integer.parseInt(Global.socketReader.readLine());

          for (int i = 0; i < N; i++) {
            String key = Global.socketReader.readLine();
            String value = Global.socketReader.readLine();

            en.setParametr(key, value);
          }
          en.setParametr(Constants.PARAM_TICK, Global.tickCounter + "");
          en.setExplored(false);

          list.add(en);
        }
      }

      Global.map = new Map(ysize, xsize, list);

      Global.tickCounter++;
    }

    while (true) {
      String message = Global.socketReader.readLine();
      if (message.equals("RENDER")) {
        Global.tickCounter++;
        keyProcessor.informServer();
        if (Global.map.player != null && Global.map.player.playerEntity.isDead()) System.exit(0);
        rend.repaint();
      } else {
        int globalId = Integer.parseInt(message);

        synchronized (Global.map) {
          Entity en = Global.map.getEntity(globalId);

          int N = Integer.parseInt(Global.socketReader.readLine());

          for (int i = 0; i < N; i++) {
            String key = Global.socketReader.readLine();
            String value = Global.socketReader.readLine();

            en.setParametr(key, value);

            if (key.equals(Constants.PARAM_MINE) && value.equals("true")) {
              Global.map.player = new Player(en);
            }
          }
          en.setParametr(Constants.PARAM_TICK, Global.tickCounter + "");

          Global.map.moveEntity(en, en.getPosition().y, en.getPosition().x);

          if (en.isDead()) {
            //						System.out.println(en.globalId);
            Global.map.removeEntity(en);
          }
        }
      }
    }
  }