if (!hasTilesetImage || tile.getId() >= set.getMaxTileId()) {
if (!hasTilesetImage || tile.getId() > set.getMaxTileId()) {
    private TileSet unmarshalTileset(Node t) throws Exception {        String source = getAttributeValue(t, "source");        String basedir = getAttributeValue(t, "basedir");        int firstGid = getAttribute(t, "firstgid", 1);        String tilesetBaseDir = xmlPath;        if (basedir != null) {            tilesetBaseDir = basedir; //makeUrl(basedir);        }        if (source != null) {            String filename = tilesetBaseDir + source;            //if (Util.checkRoot(source)) {            //    filename = makeUrl(source);            //}            TileSet ext = null;            try {                //just a little check for tricky people...                String extention = source.substring(source.lastIndexOf('.') + 1);                if (!"tsx".equals(extention.toLowerCase())) {                    logger.warn("tileset files should end in .tsx! ("+source+")");                }                InputStream in = new URL(makeUrl(filename)).openStream();                ext = unmarshalTilesetFile(in, filename);            } catch (FileNotFoundException fnf) {                logger.error("Could not find external tileset file " +                        filename);            }            if (ext == null) {                logger.error("tileset "+source+" was not loaded correctly!");                ext = new TileSet();            }            ext.setFirstGid(firstGid);            return ext;        }        else {            int tileWidth = getAttribute(t, "tilewidth", map != null ? map.getTileWidth() : 0);            int tileHeight = getAttribute(t, "tileheight", map != null ? map.getTileHeight() : 0);            int tileSpacing = getAttribute(t, "spacing", 0);            TileSet set = new TileSet();            set.setName(getAttributeValue(t, "name"));            set.setBaseDir(basedir);            set.setFirstGid(firstGid);            boolean hasTilesetImage = false;            NodeList children = t.getChildNodes();            for (int i = 0; i < children.getLength(); i++) {                Node child = children.item(i);                if (child.getNodeName().equalsIgnoreCase("image")) {                    if (hasTilesetImage) {                        logger.warn("Ignoring illegal image element after tileset image.");                        continue;                    }                    String imgSource = getAttributeValue(child, "source");                    String id = getAttributeValue(child, "id");                    String transStr = getAttributeValue(child, "trans");                    if (imgSource != null && id == null) {                        // Not a shared image, but an entire set in one image                        // file. There should be only one image element in this                        // case.                        hasTilesetImage = true;                        // FIXME: importTileBitmap does not fully support URLs                        String sourcePath = imgSource;                        if (!Util.checkRoot(imgSource)) {                            sourcePath = tilesetBaseDir + imgSource;                        }                        logger.info("Importing " + sourcePath + "...");                        if (transStr != null) {                            int colorInt = Integer.parseInt(transStr, 16);                            Color color = new Color(colorInt);                            set.setTransparentColor(color);                        }                        set.importTileBitmap(sourcePath, new BasicTileCutter(                                tileWidth, tileHeight, tileSpacing, 0));                    } else {                        Image image = unmarshalImage(child, tilesetBaseDir);                        String idValue = getAttributeValue(child, "id");                        int imageId = Integer.parseInt(idValue);                        set.addImage(image, imageId);                    }                }                else if (child.getNodeName().equalsIgnoreCase("tile")) {                    Tile tile = unmarshalTile(set, child, tilesetBaseDir);                    if (!hasTilesetImage || tile.getId() >= set.getMaxTileId()) {                        set.addTile(tile);                    } else {                        Tile myTile = set.getTile(tile.getId());                        myTile.setProperties(tile.getProperties());                        //TODO: there is the possibility here of overlaying images,                        //      which some people may want                    }                }            }            return set;        }    }