diff --git a/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapWidget.java b/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapWidget.java index 8f111545..e77641ab 100644 --- a/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapWidget.java +++ b/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapWidget.java @@ -202,8 +202,9 @@ public void init() { * @throws IllegalArgumentException if there is no such layer type id */ public MapLayer createLayer(String layerTypeId) throws IllegalArgumentException { - Supplier constructor = MapLayerRegistry.INSTANCE.getRegistrations(layerTypeId).getConstructor(); - if (constructor == null) throw new IllegalArgumentException("No such layer type registered: " + layerTypeId); + MapLayerRegistry.LayerRegistration registration = MapLayerRegistry.INSTANCE.getRegistrations(layerTypeId); + if (registration == null) throw new IllegalArgumentException("No such layer type registered: " + layerTypeId); + Supplier constructor = registration.getConstructor(); MapLayer layer = constructor.get(); layer.setMap(this); layer.setType(layerTypeId); diff --git a/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java b/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java index 61c788e0..a1f09a3c 100644 --- a/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java +++ b/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java @@ -9,7 +9,6 @@ import fr.thesmyler.terramap.gui.widgets.map.MapWidget; import fr.thesmyler.terramap.maps.raster.RasterTile; import fr.thesmyler.terramap.maps.raster.RasterTiledMap; -import fr.thesmyler.terramap.maps.raster.imp.UrlRasterTile; import fr.thesmyler.terramap.util.geo.*; import fr.thesmyler.terramap.util.geo.TilePos.InvalidTilePositionException; import fr.thesmyler.terramap.util.math.Mat2d; @@ -51,6 +50,7 @@ protected void initialize() { public void draw(float x, float y, float mouseX, float mouseY, boolean hovered, boolean focused, WidgetContainer parent) { final RasterTiledMap tiledMap = this.getTiledMap(); + final ResourceLocation defaultTexture = tiledMap.getDefaultTileTexture(); Font smallFont = Util.getSmallestFont(); Minecraft mc = Minecraft.getMinecraft(); @@ -207,7 +207,7 @@ public void draw(float x, float y, float mouseX, float mouseY, boolean hovered, } whiteWithAlpha.applyGL(); - ResourceLocation texture = UrlRasterTile.errorTileTexture; + ResourceLocation texture = defaultTexture; try { if(tile.isTextureAvailable()) texture = tile.getTexture(); else perfectDraw = false; @@ -215,18 +215,20 @@ public void draw(float x, float y, float mouseX, float mouseY, boolean hovered, perfectDraw = false; parentMap.reportError(this, e.toString()); } - textureManager.bindTexture(texture); - RenderUtil.drawModalRectWithCustomSizedTexture( - dispX, - dispY, - dX, dY, - displayWidth, - displayHeight, - renderSizedSize, - renderSizedSize - ); + if (texture != null) { + textureManager.bindTexture(texture); + RenderUtil.drawModalRectWithCustomSizedTexture( + dispX, + dispY, + dX, dY, + displayWidth, + displayHeight, + renderSizedSize, + renderSizedSize + ); + } if(debug) { - Color lineColor = lowerResRender? unlockedZoomRender? Color.BLUE: Color.RED : Color.WHITE; + Color lineColor = texture == null? Color.GREEN: lowerResRender? unlockedZoomRender? Color.BLUE: Color.RED : Color.WHITE; RenderUtil.drawClosedStrokeLine(lineColor, 1f, dispX, dispY, dispX, dispY + displayHeight - 1, diff --git a/src/main/java/fr/thesmyler/terramap/maps/raster/RasterTiledMap.java b/src/main/java/fr/thesmyler/terramap/maps/raster/RasterTiledMap.java index 083d226c..087e505c 100644 --- a/src/main/java/fr/thesmyler/terramap/maps/raster/RasterTiledMap.java +++ b/src/main/java/fr/thesmyler/terramap/maps/raster/RasterTiledMap.java @@ -3,7 +3,13 @@ import fr.thesmyler.terramap.util.geo.TilePos; import fr.thesmyler.terramap.util.geo.TilePosImmutable; import fr.thesmyler.terramap.util.geo.WebMercatorBounds; +import net.minecraft.util.ResourceLocation; +/** + * A raster map made of individual tiles. + * + * @author Smyler + */ public interface RasterTiledMap extends Comparable { /** @@ -43,7 +49,7 @@ default RasterTile getTile(int zoom, int x, int y) { /** * Gets a name for this map, translated in the appropriate language, * or English if it isn't available. - * + * * @param localeKey the language key to get the copyright for * @return the name of this map, translated to the appropriate language. */ @@ -78,7 +84,7 @@ default RasterTile getTile(int zoom, int x, int y) { * @return true if this map should be considered a debug map */ boolean isDebug(); - + /** * @param zoom the zoom level to consider * @@ -88,5 +94,11 @@ default WebMercatorBounds getBounds(int zoom) { return null; } + /** + * @return the default tile texture to show when no other is available + * (e.g. because the right tile is still loading). + * Return null to not render anything. + */ + ResourceLocation getDefaultTileTexture(); } diff --git a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/ColorTiledMap.java b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/ColorTiledMap.java index d9c5339d..366eb567 100644 --- a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/ColorTiledMap.java +++ b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/ColorTiledMap.java @@ -87,6 +87,11 @@ public boolean isDebug() { return true; } + @Override + public ResourceLocation getDefaultTileTexture() { + return this.textureLocation; + } + public Color getColor() { return this.color; } diff --git a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/TerrainPreviewMap.java b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/TerrainPreviewMap.java index b3e6d77b..69cff66f 100644 --- a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/TerrainPreviewMap.java +++ b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/TerrainPreviewMap.java @@ -4,6 +4,7 @@ import fr.thesmyler.terramap.maps.raster.CachingRasterTiledMap; import fr.thesmyler.terramap.maps.raster.TiledMapProvider; import fr.thesmyler.terramap.util.geo.TilePosImmutable; +import net.minecraft.util.ResourceLocation; public class TerrainPreviewMap extends CachingRasterTiledMap { @@ -30,7 +31,7 @@ public String getLocalizedName(String localeKey) { @Override public String getComment() { - return "Terra++ terrain perview debug map"; + return "Terra++ terrain preview debug map"; } @Override @@ -58,6 +59,11 @@ public boolean isDebug() { return true; } + @Override + public ResourceLocation getDefaultTileTexture() { + return null; + } + @Override public int getMinZoom() { return BASE_ZOOM_LEVEL; diff --git a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/TerrainPreviewTile.java b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/TerrainPreviewTile.java index 0069df88..4c0833a3 100644 --- a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/TerrainPreviewTile.java +++ b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/TerrainPreviewTile.java @@ -37,7 +37,7 @@ public boolean isTextureAvailable() { public ResourceLocation getTexture() throws Throwable { if(this.getPosition().getZoom() < TerrainPreviewMap.BASE_ZOOM_LEVEL) - throw new IllegalArgumentException("Trying to request a terrain preview with a zoom that's to low (" + this.position.getZoom() + ")"); + throw new IllegalArgumentException("Trying to request a terrain preview with a zoom that's too low (" + this.position.getZoom() + ")"); if(this.getPosition().getZoom() != TerrainPreviewMap.BASE_ZOOM_LEVEL) return null; diff --git a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlRasterTile.java b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlRasterTile.java index 1c85836a..300e285e 100644 --- a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlRasterTile.java +++ b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlRasterTile.java @@ -32,7 +32,6 @@ public class UrlRasterTile implements RasterTile { private ResourceLocation texture = null; private CompletableFuture textureTask; - public static ResourceLocation errorTileTexture = null; public UrlRasterTile(String urlPattern, TilePosImmutable pos) { this.pos = pos; @@ -136,11 +135,4 @@ public int hashCode() { return this.url.hashCode(); } - public static void registerErrorTexture() { - TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); - int[] color = {170, 211, 223}; - DynamicTexture texture = new DynamicTexture(ImageUtil.imageFromColor(256, 256, color)); - UrlRasterTile.errorTileTexture = textureManager.getDynamicTextureLocation(TerramapMod.MODID + ":error_tile_texture", texture); - } - } diff --git a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlTiledMap.java b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlTiledMap.java index 2fe89ca8..36fba23b 100644 --- a/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlTiledMap.java +++ b/src/main/java/fr/thesmyler/terramap/maps/raster/imp/UrlTiledMap.java @@ -14,15 +14,20 @@ import fr.thesmyler.terramap.maps.raster.TiledMapProvider; import fr.thesmyler.terramap.network.SP2CMapStylePacket; import fr.thesmyler.terramap.util.CopyrightHolder; +import fr.thesmyler.terramap.util.ImageUtil; import fr.thesmyler.terramap.util.geo.TilePosImmutable; import fr.thesmyler.terramap.util.geo.WebMercatorBounds; import net.buildtheearth.terraplusplus.util.http.Http; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; /** * Instances are usually created in {@link MapStylesLibrary} and {@link SP2CMapStylePacket}. * - * @author SmylerMC + * @author Smyler * */ public class UrlTiledMap extends CachingRasterTiledMap implements CopyrightHolder { @@ -44,6 +49,7 @@ public class UrlTiledMap extends CachingRasterTiledMap implements private final Map bounds; private static final ITextComponent FALLBACK_COPYRIGHT = ITextComponent.Serializer.jsonToComponent("{\"text\":\"The text component for this copyright notice was malformatted!\",\"color\":\"dark_red\"}"); + private ResourceLocation errorTileTexture = null; public UrlTiledMap( String[] urlPatterns, @@ -100,6 +106,7 @@ public UrlTiledMap( */ @Override public void setup() { + this.registerErrorTexture(); for(String urlPattern: this.getUrlPatterns()) { String url = urlPattern.replace("{z}", "0").replace("{x}", "0").replace("{y}", "0"); try { @@ -259,7 +266,7 @@ public int getMaxConcurrentRequests() { } /** - * @return Whether or not this map can be used on the minimap + * @return Whether this map can be used on the minimap */ @Override public boolean isAllowedOnMinimap() { @@ -271,4 +278,16 @@ public WebMercatorBounds getBounds(int zoom) { return this.bounds.get(zoom); } + @Override + public ResourceLocation getDefaultTileTexture() { + return this.errorTileTexture; + } + + public void registerErrorTexture() { + TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); + int[] color = {170, 211, 223}; + DynamicTexture texture = new DynamicTexture(ImageUtil.imageFromColor(256, 256, color)); + this.errorTileTexture = textureManager.getDynamicTextureLocation(TerramapMod.MODID + ":error_tile_texture", texture); + } + } \ No newline at end of file diff --git a/src/main/java/fr/thesmyler/terramap/proxy/TerramapClientProxy.java b/src/main/java/fr/thesmyler/terramap/proxy/TerramapClientProxy.java index 81e9997d..b1c696e2 100644 --- a/src/main/java/fr/thesmyler/terramap/proxy/TerramapClientProxy.java +++ b/src/main/java/fr/thesmyler/terramap/proxy/TerramapClientProxy.java @@ -62,7 +62,6 @@ public void init(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new ClientTerramapEventHandler()); KeyBindings.registerBindings(); - UrlRasterTile.registerErrorTexture(); MarkerControllerManager.registerBuiltInControllers(); MapStylesLibrary.reload(); ClientCommandHandler.instance.registerCommand(new OpenMapCommand());