diff --git a/src/main/java/hunternif/mc/impl/atlas/api/oldimpl/TileApiImpl.java b/src/main/java/hunternif/mc/impl/atlas/api/oldimpl/TileApiImpl.java index ec5843e19..74b9dcf70 100644 --- a/src/main/java/hunternif/mc/impl/atlas/api/oldimpl/TileApiImpl.java +++ b/src/main/java/hunternif/mc/impl/atlas/api/oldimpl/TileApiImpl.java @@ -5,6 +5,7 @@ import hunternif.mc.impl.atlas.client.BiomeTextureMap; import hunternif.mc.impl.atlas.client.TextureSet; import hunternif.mc.impl.atlas.client.TextureSetMap; +import hunternif.mc.impl.atlas.client.texture.TileTexture; import hunternif.mc.impl.atlas.core.AtlasData; import hunternif.mc.impl.atlas.ext.ExtTileTextureMap; import hunternif.mc.impl.atlas.ext.TileDataStorage; @@ -53,10 +54,20 @@ public TileApiImpl() { } + private static TileTexture[] convertToTileTexture(Identifier... textures) { + TileTexture[] iTextures = new TileTexture[textures.length]; + + for (int i = 0; i < textures.length; i++) { + iTextures[i] = new TileTexture(textures[i]); + } + + return iTextures; + } + @Override @Environment(EnvType.CLIENT) public TextureSet registerTextureSet(Identifier name, Identifier... textures) { - TextureSet textureSet = new TextureSet(name, textures); + TextureSet textureSet = new TextureSet(name, convertToTileTexture(textures)); TextureSetMap.instance().register(textureSet); return textureSet; } @@ -67,7 +78,7 @@ public TextureSet registerTextureSet(Identifier name, Identifier... textures) { @Override @Environment(EnvType.CLIENT) public void setBiomeTexture(Biome biome, Identifier textureSetName, Identifier... textures) { - TextureSet set = new TextureSet(textureSetName, textures); + TextureSet set = new TextureSet(textureSetName, convertToTileTexture(textures)); TextureSetMap.instance().register(set); BiomeTextureMap.instance().setTexture(biome, set); } @@ -84,7 +95,7 @@ public void setBiomeTexture(Biome biome, TextureSet textureSet) { @Override @Environment(EnvType.CLIENT) public void setCustomTileTexture(Identifier uniqueTileName, Identifier... textures) { - TextureSet set = new TextureSet(uniqueTileName, textures); + TextureSet set = new TextureSet(uniqueTileName, convertToTileTexture(textures)); TextureSetMap.instance().register(set); setCustomTileTexture(uniqueTileName, set); } diff --git a/src/main/java/hunternif/mc/impl/atlas/client/BiomeTextureMap.java b/src/main/java/hunternif/mc/impl/atlas/client/BiomeTextureMap.java index 147eef209..1201d2c22 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/BiomeTextureMap.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/BiomeTextureMap.java @@ -1,5 +1,6 @@ package hunternif.mc.impl.atlas.client; +import hunternif.mc.impl.atlas.client.texture.ITexture; import hunternif.mc.impl.atlas.util.Log; import hunternif.mc.impl.atlas.util.SaveData; import net.fabricmc.api.EnvType; @@ -13,6 +14,7 @@ import java.util.*; import java.util.Map.Entry; import java.util.function.Supplier; +import java.util.stream.Collectors; import static hunternif.mc.impl.atlas.client.TextureSet.*; @@ -185,16 +187,15 @@ public TextureSet getTextureSet(Identifier tile) { return textureMap.get(tile); } - public Identifier getTexture(int variationNumber, Identifier tile) { - TextureSet set = getTextureSet(tile); - return set.textures[variationNumber % set.textures.length]; + public ITexture getTexture(SubTile subTile) { + return getTextureSet(subTile.tile).getTexture(subTile.variationNumber); } public List getAllTextures() { List list = new ArrayList<>(); for (Entry entry : textureMap.entrySet()) { - list.addAll(Arrays.asList(entry.getValue().textures)); + Arrays.stream(entry.getValue().textures).map(iTexture -> list.add(iTexture.getTexture())); } return list; diff --git a/src/main/java/hunternif/mc/impl/atlas/client/TextureSet.java b/src/main/java/hunternif/mc/impl/atlas/client/TextureSet.java index 7f470eef9..9a31bc7a7 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/TextureSet.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/TextureSet.java @@ -1,11 +1,9 @@ package hunternif.mc.impl.atlas.client; +import hunternif.mc.impl.atlas.client.texture.ITexture; import net.minecraft.util.Identifier; -import java.util.Collections; -import java.util.HashSet; -import java.util.Locale; -import java.util.Set; +import java.util.*; import static hunternif.mc.impl.atlas.client.Textures.*; @@ -247,7 +245,7 @@ public class TextureSet implements Comparable { /** * The actual textures in this set. */ - public final Identifier[] textures; + public final ITexture[] textures; /** * Whether the texture set is part of the standard pack. Only true for * static constants in this class. @@ -263,7 +261,7 @@ public class TextureSet implements Comparable { private boolean stitchesToNull = false; private boolean anisotropicStitching = false; - private TextureSet(boolean isStandard, Identifier name, Identifier... textures) { + private TextureSet(boolean isStandard, Identifier name, ITexture... textures) { this.isStandard = isStandard; this.name = name; this.textures = textures; @@ -272,11 +270,11 @@ private TextureSet(boolean isStandard, Identifier name, Identifier... textures) /** * Name has to be unique, it is used for equals() tests. */ - public TextureSet(Identifier name, Identifier... textures) { + public TextureSet(Identifier name, ITexture... textures) { this(false, name, textures); } - private static TextureSet standard(String name, Identifier... textures) { + private static TextureSet standard(String name, ITexture... textures) { return new TextureSet(true, new Identifier("antiqueatlas", name.toLowerCase(Locale.ROOT)), textures); } @@ -383,13 +381,17 @@ public int compareTo(TextureSet textureSet) { return name.toString().compareTo(textureSet.name.toString()); } + public ITexture getTexture(int variationNumber) { + return textures[variationNumber % textures.length]; + } + /** * A special texture set that is stitched to everything except water. */ private static class TextureSetShore extends TextureSet { private final TextureSet water; - TextureSetShore(String name, TextureSet water, Identifier... textures) { + TextureSetShore(String name, TextureSet water, ITexture... textures) { super(true, new Identifier("antiqueatlas", name.toLowerCase(Locale.ROOT)), textures); this.water = water; } diff --git a/src/main/java/hunternif/mc/impl/atlas/client/TextureSetConfig.java b/src/main/java/hunternif/mc/impl/atlas/client/TextureSetConfig.java index a4a003fc4..7b91f6684 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/TextureSetConfig.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/TextureSetConfig.java @@ -2,6 +2,8 @@ import com.google.gson.*; import hunternif.mc.impl.atlas.AntiqueAtlasMod; +import hunternif.mc.impl.atlas.client.texture.ITexture; +import hunternif.mc.impl.atlas.client.texture.TileTexture; import hunternif.mc.impl.atlas.util.Log; import java.io.InputStream; @@ -51,10 +53,10 @@ public CompletableFuture> load(ResourceManager manager, P for (Entry entry : obj.get("data").getAsJsonObject().entrySet()) { String name = entry.getKey(); JsonArray array = entry.getValue().getAsJsonArray(); - Identifier[] textures = new Identifier[array.size()]; + ITexture[] textures = new ITexture[array.size()]; for (int i = 0; i < array.size(); i++) { String path = array.get(i).getAsString(); - textures[i] = new Identifier(path); + textures[i] = new TileTexture(new Identifier(path)); } sets.add(new TextureSet(AntiqueAtlasMod.id(name), textures)); } diff --git a/src/main/java/hunternif/mc/impl/atlas/client/Textures.java b/src/main/java/hunternif/mc/impl/atlas/client/Textures.java index 890797a21..4504c0ba4 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/Textures.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/Textures.java @@ -1,6 +1,10 @@ package hunternif.mc.impl.atlas.client; import hunternif.mc.impl.atlas.AntiqueAtlasMod; +import hunternif.mc.impl.atlas.client.texture.ITexture; +import hunternif.mc.impl.atlas.client.texture.IconTexture; +import hunternif.mc.impl.atlas.client.texture.Texture; +import hunternif.mc.impl.atlas.client.texture.TileTexture; import net.minecraft.util.Identifier; public class Textures { @@ -11,21 +15,20 @@ public class Textures { private static final String GUI_MARKERS = GUI + "markers/"; private static final String GUI_SCALEBAR = GUI + "scalebar/"; - public static final Identifier - BOOK = gui("book.png"), - EXPORTED_BG = gui("exported_bg.png"), - BOOK_FRAME = gui("book_frame.png"), - BTN_ARROWS = gui("navigate_arrows.png"), - BTN_POSITION = gui("position.png"), - BOOKMARKS = gui("bookmarks.png"), - PLAYER = gui("player.png"), - SCROLLBAR_HOR = gui("scrollbar_hor.png"), - SCROLLBAR_VER = gui("scrollbar_ver.png"), - MARKER_FRAME_ON = gui("marker_frame_on.png"), - MARKER_FRAME_OFF = gui("marker_frame_off.png"), - ERASER = gui("eraser.png"), + public static final ITexture + BOOK = gui("book.png", 310, 218), + BOOK_FRAME = gui("book_frame.png", 310, 218), + BTN_ARROWS = gui("navigate_arrows.png", 24, 24), + BTN_POSITION = gui("position.png", 24, 24), + BOOKMARKS = gui("bookmarks.png", 84, 36), + PLAYER = gui("player.png", 7, 8), + SCROLLBAR_HOR = gui("scrollbar_hor.png", 8, 7), + SCROLLBAR_VER = gui("scrollbar_ver.png", 7,8), + MARKER_FRAME_ON = gui("marker_frame_on.png", 34, 34), + MARKER_FRAME_OFF = gui("marker_frame_off.png", 34, 34), + ERASER = gui("eraser.png", 24, 24), - SCALEBAR_4 = scaleBar("scalebar_4.png"), + SCALEBAR_4 = scaleBar("scalebar_4.png"), SCALEBAR_8 = scaleBar("scalebar_8.png"), SCALEBAR_16 = scaleBar("scalebar_16.png"), SCALEBAR_32 = scaleBar("scalebar_32.png"), @@ -34,31 +37,13 @@ public class Textures { SCALEBAR_256 = scaleBar("scalebar_256.png"), SCALEBAR_512 = scaleBar("scalebar_512.png"), - ICON_ADD_MARKER = icon("add_marker.png"), + ICON_ADD_MARKER = icon("add_marker.png"), ICON_DELETE_MARKER = icon("del_marker.png"), ICON_SHOW_MARKERS = icon("show_markers.png"), ICON_HIDE_MARKERS = icon("hide_markers.png"), ICON_EXPORT = icon("export.png"), - MARKER_GOOGLE_MARKER = marker("google_marker.png"), - MARKER_RED_X_LARGE = marker("red_x_large.png"), - MARKER_RED_X_SMALL = marker("red_x_small.png"), - MARKER_VILLAGE = marker("village.png"), - MARKER_END_CITY_FAR = marker("end_city_far.png"), - MARKER_END_CITY = marker("end_city.png"), - MARKER_END_CITY_MIP_32 = marker("end_city_mipped_32.png"), - MARKER_END_CITY_MIP_16 = marker("end_city_mipped_16.png"), - MARKER_DIAMOND = marker("diamond.png"), - MARKER_BED = marker("bed.png"), - MARKER_PICKAXE = marker("pickaxe.png"), - MARKER_SWORD = marker("sword.png"), - MARKER_NETHER_PORTAL = marker("nether_portal.png"), - MARKER_SKULL = marker("skull.png"), - MARKER_TOWER = marker("tower.png"), - MARKER_SCROLL = marker("scroll.png"), - MARKER_TOMB = marker("tomb.png"), - - TILE_TEST = tile("test.png"), + TILE_TEST = tile("test.png"), TILE_MOUNTAINS = tile("mountains.png"), TILE_MOUNTAINS2 = tile("mountains2.png"), TILE_MOUNTAINS3 = tile("mountains3.png"), @@ -212,14 +197,14 @@ public class Textures { TILE_LAVA_SHORE = tile("lava_shore.png"), TILE_LAVA_SHORE2 = tile("lava_shore2.png"), - TILE_END_VOID = tile("end_void.png"), + TILE_END_VOID = tile("end_void.png"), TILE_END_ISLAND = tile("end_island.png"), TILE_END_ISLAND2 = tile("end_island2.png"), TILE_END_ISLAND_PLANTS = tile("end_island_plants.png"), TILE_END_ISLAND_PLANTS2 = tile("end_island_plants2.png"), - // Village: - TILE_HOUSE = tile("house.png"), + // Village: + TILE_HOUSE = tile("house.png"), TILE_FENCE = tile("fence.png"), TILE_LIBRARY = tile("library.png"), TILE_SMITHY = tile("smithy.png"), @@ -235,8 +220,8 @@ public class Textures { TILE_BUTCHERS_SHOP = tile("butchers_shop.png"), TILE_CHURCH = tile("church.png"), - // Nether Fortress: - TILE_NETHER_BRIDGE = tile("nether_bridge.png"), + // Nether Fortress: + TILE_NETHER_BRIDGE = tile("nether_bridge.png"), TILE_NETHER_BRIDGE_X = tile("nether_bridge_x.png"), TILE_NETHER_BRIDGE_Z = tile("nether_bridge_z.png"), TILE_NETHER_BRIDGE_END_X = tile("nether_bridge_end_x.png"), @@ -248,24 +233,22 @@ public class Textures { TILE_NETHER_FORT_STAIRS = tile("nether_fort_stairs.png"), TILE_NETHER_THRONE = tile("nether_throne.png"); - // Constructor helpers: - private static Identifier gui(String fileName) { - return new Identifier(GUI + fileName); - } + public static final Identifier EXPORTED_BG = new Identifier(GUI + "exported_bg.png"); - private static Identifier scaleBar(String fileName) { - return new Identifier(GUI_SCALEBAR + fileName); + // Constructor helpers: + private static ITexture gui(String fileName, int width, int height) { + return new Texture(new Identifier(GUI + fileName), width, height); } - private static Identifier marker(String fileName) { - return new Identifier(GUI_MARKERS + fileName); + private static ITexture scaleBar(String fileName) { + return new Texture(new Identifier(GUI_SCALEBAR + fileName), 20, 8); } - private static Identifier tile(String fileName) { - return new Identifier(GUI_TILES + fileName); + private static ITexture tile(String fileName) { + return new TileTexture(new Identifier(GUI_TILES + fileName)); } - private static Identifier icon(String fileName) { - return new Identifier(GUI_ICONS + fileName); + private static ITexture icon(String fileName) { + return new IconTexture(new Identifier(GUI_ICONS + fileName)); } } diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiArrowButton.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiArrowButton.java index 3f7dc09f4..f1679e6d7 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiArrowButton.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiArrowButton.java @@ -3,15 +3,12 @@ import com.mojang.blaze3d.systems.RenderSystem; import hunternif.mc.impl.atlas.client.Textures; import hunternif.mc.impl.atlas.client.gui.core.GuiComponentButton; -import hunternif.mc.impl.atlas.util.AtlasRenderHelper; import net.minecraft.client.util.math.MatrixStack; import org.lwjgl.opengl.GL11; public class GuiArrowButton extends GuiComponentButton { private static final int WIDTH = 12; private static final int HEIGHT = 12; - private static final int IMAGE_WIDTH = 24; - private static final int IMAGE_HEIGHT = 24; public enum ArrowDirection { UP("Up"), DOWN("Down"), LEFT("Left"), RIGHT("Right"); @@ -82,7 +79,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTi v = 12; break; } - AtlasRenderHelper.drawTexturedRect(matrices, Textures.BTN_ARROWS, x, y, u, v, WIDTH, HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT); + Textures.BTN_ARROWS.draw(matrices, x, y, u, v, WIDTH, HEIGHT); RenderSystem.disableBlend(); } diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiAtlas.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiAtlas.java index 6066c04df..198ae18dd 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiAtlas.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiAtlas.java @@ -7,6 +7,8 @@ import hunternif.mc.impl.atlas.client.gui.core.*; import hunternif.mc.impl.atlas.client.gui.core.GuiStates.IState; import hunternif.mc.impl.atlas.client.gui.core.GuiStates.SimpleState; +import hunternif.mc.impl.atlas.client.texture.ITexture; +import hunternif.mc.impl.atlas.client.texture.TileTexture; import hunternif.mc.impl.atlas.core.WorldData; import hunternif.mc.impl.atlas.event.MarkerClickedCallback; import hunternif.mc.impl.atlas.event.MarkerHoveredCallback; @@ -19,10 +21,8 @@ import hunternif.mc.impl.atlas.registry.MarkerType; import hunternif.mc.impl.atlas.util.*; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.options.KeyBinding; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormats; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.util.math.MatrixStack; @@ -33,7 +33,6 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.text.TranslatableText; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Matrix4f; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; @@ -353,7 +352,7 @@ public boolean isEnabled() { (int) player.getX(), (int) player.getZ()); addChild(markerFinalizer); - blinkingIcon.setTexture(markerFinalizer.selectedType.getIcon(), + blinkingIcon.setTexture(markerFinalizer.selectedType.getTexture(), MARKER_SIZE, MARKER_SIZE); addChildBehind(markerFinalizer, blinkingIcon) .setRelativeCoords(worldXToScreenX((int) player.getX()) - getGuiX() - MARKER_SIZE / 2, @@ -453,8 +452,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int mouseState) { } // close atlas with right-click - if (mouseState == 1 && state.is(NORMAL)) - { + if (mouseState == 1 && state.is(NORMAL)) { onClose(); return true; } @@ -473,7 +471,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int mouseState) { screenXToWorldX((int) mouseX), screenYToWorldZ((int) mouseY)); addChild(markerFinalizer); - blinkingIcon.setTexture(markerFinalizer.selectedType.getIcon(), + blinkingIcon.setTexture(markerFinalizer.selectedType.getTexture(), MARKER_SIZE, MARKER_SIZE); addChildBehind(markerFinalizer, blinkingIcon) .setRelativeCoords((int) mouseX - getGuiX() - MARKER_SIZE / 2, @@ -776,7 +774,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float par3) { RenderSystem.color4f(1, 1, 1, 1); RenderSystem.enableAlphaTest(); RenderSystem.alphaFunc(GL11.GL_GREATER, 0); // So light detail on tiles is visible - AtlasRenderHelper.drawFullTexture(matrices, Textures.BOOK, getGuiX(), getGuiY(), WIDTH, HEIGHT); + Textures.BOOK.draw(matrices, getGuiX(), getGuiY()); if ((stack == null && AntiqueAtlasMod.CONFIG.itemNeeded) || biomeData == null) return; @@ -806,18 +804,24 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float par3) { set(mapStartX, mapStartZ, mapEndX, mapEndZ)); iter.setStep(tile2ChunkScale); + matrices.push(); + matrices.translate(mapStartScreenX, mapStartScreenY, 0); + while (iter.hasNext()) { SubTileQuartet subtiles = iter.next(); for (SubTile subtile : subtiles) { if (subtile == null || subtile.tile == null) continue; - AtlasRenderHelper.drawAutotileCorner( - BiomeTextureMap.instance().getTexture(subtile.variationNumber, subtile.tile), - mapStartScreenX + subtile.x * tileHalfSize, - mapStartScreenY + subtile.y * tileHalfSize, - subtile.getTextureU(), subtile.getTextureV(), tileHalfSize); + ITexture texture = BiomeTextureMap.instance().getTexture(subtile); + if (texture instanceof TileTexture) { + TileTexture tileTexture = (TileTexture) texture; + tileTexture.bind(); + tileTexture.drawSubTile(matrices, subtile, tileHalfSize); + } } } + matrices.pop(); + int markersStartX = MathUtil.roundToBase(mapStartX, MarkersData.CHUNK_STEP) / MarkersData.CHUNK_STEP - 1; int markersStartZ = MathUtil.roundToBase(mapStartZ, MarkersData.CHUNK_STEP) / MarkersData.CHUNK_STEP - 1; int markersEndX = MathUtil.roundToBase(mapEndX, MarkersData.CHUNK_STEP) / MarkersData.CHUNK_STEP + 1; @@ -831,7 +835,8 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float par3) { // Overlay the frame so that edges of the map are smooth: RenderSystem.color4f(1, 1, 1, 1); - AtlasRenderHelper.drawFullTexture(matrices, Textures.BOOK_FRAME, getGuiX(), getGuiY(), WIDTH, HEIGHT); + Textures.BOOK_FRAME.draw(matrices, getGuiX(), getGuiY()); + renderScaleOverlay(matrices, deltaMillis); double iconScale = getIconScale(); @@ -852,8 +857,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float par3) { float playerRotation = (float) Math.round(player.yaw / 360f * PLAYER_ROTATION_STEPS) / PLAYER_ROTATION_STEPS * 360f; matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(180 + playerRotation)); matrices.translate((float) (-PLAYER_ICON_WIDTH / 2 * iconScale), (float) (-PLAYER_ICON_HEIGHT / 2 * iconScale), 0f); - AtlasRenderHelper.drawFullTexture(matrices, Textures.PLAYER, 0, 0, - (int) Math.round(PLAYER_ICON_WIDTH * iconScale), (int) Math.round(PLAYER_ICON_HEIGHT * iconScale)); + Textures.PLAYER.draw(matrices, 0, 0, (int) Math.round(PLAYER_ICON_WIDTH * iconScale), (int) Math.round(PLAYER_ICON_HEIGHT * iconScale)); matrices.pop(); RenderSystem.color4f(1, 1, 1, 1); } @@ -869,10 +873,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float par3) { markerFinalizer.selectedType.calculateMip(iconScale, mapScale, screenScale); MarkerRenderInfo renderInfo = markerFinalizer.selectedType.getRenderInfo(iconScale, mapScale, screenScale); markerFinalizer.selectedType.resetMip(); - AtlasRenderHelper.drawFullTexture( - matrices, renderInfo.tex, - mouseX + renderInfo.x, mouseY + renderInfo.y, - renderInfo.width, renderInfo.height); + renderInfo.tex.draw(matrices, mouseX + renderInfo.x, mouseY + renderInfo.y); RenderSystem.color4f(1, 1, 1, 1); } RenderSystem.disableBlend(); @@ -921,21 +922,7 @@ private void renderScaleOverlay(MatrixStack matrices, long deltaMillis) { int centerXtranslate = Math.max(this.textRenderer.getWidth(parts[0]), this.textRenderer.getWidth(parts[1])) / 2; matrices.translate(-xWidth - centerXtranslate, (float) -this.textRenderer.fontHeight / 2, 0); - RenderSystem.color4f(0f, 0f, 0f, scaleAlpha / 255f); - RenderSystem.enableBlend(); - RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - RenderSystem.disableTexture(); - Tessellator t = Tessellator.getInstance(); - BufferBuilder vb = t.getBuffer(); - Matrix4f matrix = matrices.peek().getModel(); - vb.begin(GL11.GL_QUADS, VertexFormats.POSITION); - vb.vertex(matrix, centerXtranslate, this.textRenderer.fontHeight - 1, 0.0f).next(); - vb.vertex(matrix, -centerXtranslate - 1, this.textRenderer.fontHeight - 1, 0.0f).next(); - vb.vertex(matrix, -centerXtranslate - 1, this.textRenderer.fontHeight, 0.0f).next(); - vb.vertex(matrix, centerXtranslate, this.textRenderer.fontHeight, 0.0f).next(); - t.draw(); - RenderSystem.enableTexture(); - RenderSystem.disableBlend(); + DrawableHelper.fill(matrices, -centerXtranslate - 1, this.textRenderer.fontHeight - 1, centerXtranslate, this.textRenderer.fontHeight, color); textWidth = this.textRenderer.getWidth(parts[0]); this.textRenderer.draw(matrices, parts[0], (float) -textWidth / 2, 0, color); @@ -982,7 +969,7 @@ private void renderMarker(MatrixStack matrices, int mouseX, int mouseY, Marker m type.calculateMip(scale, mapScale, screenScale); MarkerRenderInfo info = type.getRenderInfo(scale, mapScale, screenScale); - boolean mouseIsOverMarker = type.shouldHover((getMouseX() - (markerX + info.x)) / info.width, (getMouseY() - (markerY + info.y)) / info.height); + boolean mouseIsOverMarker = type.shouldHover((getMouseX() - (markerX + info.x)) / info.tex.width(), (getMouseY() - (markerY + info.y)) / info.tex.height()); type.resetMip(); if (mouseIsOverMarker) { @@ -1008,7 +995,7 @@ private void renderMarker(MatrixStack matrices, int mouseX, int mouseY, Marker m System.out.println("Rendering Marker: " + info.tex); } - AtlasRenderHelper.drawFullTexture(matrices, info.tex, markerX + info.x, markerY + info.y, info.width, info.height); + info.tex.draw(matrices, markerX + info.x, markerY + info.y, info.width, info.height); if (isMouseOver && mouseIsOverMarker && marker.getLabel().getString().length() > 0) { drawTooltip(Collections.singletonList(marker.getLabel()), textRenderer); diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiBlinkingMarker.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiBlinkingMarker.java index b6b788ea3..12db7a24b 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiBlinkingMarker.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiBlinkingMarker.java @@ -5,6 +5,6 @@ public class GuiBlinkingMarker extends GuiBlinkingImage implements GuiMarkerFinalizer.IMarkerTypeSelectListener { public void onSelectMarkerType(MarkerType markerType) { - setTexture(markerType.getIcon(), GuiAtlas.MARKER_SIZE, GuiAtlas.MARKER_SIZE); + setTexture(markerType.getTexture(), GuiAtlas.MARKER_SIZE, GuiAtlas.MARKER_SIZE); } } diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiBookmarkButton.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiBookmarkButton.java index d5d0233a6..1fe8ce1e8 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiBookmarkButton.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiBookmarkButton.java @@ -3,11 +3,10 @@ import com.mojang.blaze3d.systems.RenderSystem; import hunternif.mc.impl.atlas.client.Textures; import hunternif.mc.impl.atlas.client.gui.core.GuiToggleButton; -import hunternif.mc.impl.atlas.util.AtlasRenderHelper; +import hunternif.mc.impl.atlas.client.texture.ITexture; import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; -import net.minecraft.util.Identifier; import java.util.Collections; @@ -25,7 +24,7 @@ public class GuiBookmarkButton extends GuiToggleButton { private static final int ICON_HEIGHT = 16; private final int colorIndex; - private Identifier iconTexture; + private ITexture iconTexture; private Text title; /** @@ -33,25 +32,25 @@ public class GuiBookmarkButton extends GuiToggleButton { * @param iconTexture the path to the 16x16 texture to be drawn on top of the bookmark. * @param title hovering text. */ - GuiBookmarkButton(int colorIndex, Identifier iconTexture, Text title) { + GuiBookmarkButton(int colorIndex, ITexture iconTexture, Text title) { this.colorIndex = colorIndex; setIconTexture(iconTexture); setTitle(title); setSize(WIDTH, HEIGHT); } - void setIconTexture(Identifier iconTexture) { + void setIconTexture(ITexture iconTexture) { this.iconTexture = iconTexture; } - void setTitle(Text title) { - this.title = title; - } - public Text getTitle() { return title; } + void setTitle(Text title) { + this.title = title; + } + @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTick) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); @@ -59,12 +58,14 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTi // Render background: int u = colorIndex * WIDTH; int v = isMouseOver || isSelected() ? 0 : HEIGHT; - AtlasRenderHelper.drawTexturedRect(matrices, Textures.BOOKMARKS, getGuiX(), getGuiY(), u, v, WIDTH, HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT); +// AtlasRenderHelper.drawTexturedRect(matrices, Textures.BOOKMARKS.getTexture(), getGuiX(), getGuiY(), u, v, WIDTH, HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT); + Textures.BOOKMARKS.draw(matrices, getGuiX(), getGuiY(), u, v, WIDTH, HEIGHT); // Render the icon: - AtlasRenderHelper.drawFullTexture(matrices, iconTexture, - getGuiX() + (isMouseOver || isSelected() ? 3 : 2), - getGuiY() + 1, ICON_WIDTH, ICON_HEIGHT); + iconTexture.draw(matrices, getGuiX() + (isMouseOver || isSelected() ? 3 : 2), getGuiY() + 1); +// AtlasRenderHelper.drawFullTexture(matrices, iconTexture, +// getGuiX() + (isMouseOver || isSelected() ? 3 : 2), +// getGuiY() + 1, ICON_WIDTH, ICON_HEIGHT); if (isMouseOver) { drawTooltip(Collections.singletonList(title), MinecraftClient.getInstance().textRenderer); diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiMarkerInList.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiMarkerInList.java index 370944608..96aa17470 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiMarkerInList.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiMarkerInList.java @@ -2,10 +2,9 @@ import hunternif.mc.impl.atlas.client.Textures; import hunternif.mc.impl.atlas.client.gui.core.GuiToggleButton; +import hunternif.mc.impl.atlas.client.texture.ITexture; import hunternif.mc.impl.atlas.registry.MarkerType; -import hunternif.mc.impl.atlas.util.AtlasRenderHelper; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; public class GuiMarkerInList extends GuiToggleButton { @@ -24,12 +23,12 @@ public MarkerType getMarkerType() { @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTick) { - AtlasRenderHelper.drawFullTexture(matrices, isSelected() ? Textures.MARKER_FRAME_ON : Textures.MARKER_FRAME_OFF, getGuiX() + 1, getGuiY() + 1, FRAME_SIZE); + ITexture frame_texture = isSelected() ? Textures.MARKER_FRAME_ON : Textures.MARKER_FRAME_OFF; + frame_texture.draw(matrices, getGuiX() + 1, getGuiY() + 1); - Identifier texture = markerType.getIcon(); + ITexture texture = markerType.getTexture(); if (texture != null) { - AtlasRenderHelper.drawFullTexture(matrices, texture, getGuiX() + 1, getGuiY() + 1, GuiAtlas.MARKER_SIZE); - + texture.draw(matrices, getGuiX() + 1, getGuiY() + 1); } super.render(matrices, mouseX, mouseY, partialTick); diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiPositionButton.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiPositionButton.java index cc70659a9..7a0eb2342 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiPositionButton.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiPositionButton.java @@ -3,7 +3,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import hunternif.mc.impl.atlas.client.Textures; import hunternif.mc.impl.atlas.client.gui.core.GuiComponentButton; -import hunternif.mc.impl.atlas.util.AtlasRenderHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.TranslatableText; @@ -32,7 +31,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTi RenderSystem.color4f(1.0F, 1.0F, 1.0F, 0.5F); } - AtlasRenderHelper.drawFullTexture(matrices, Textures.BTN_POSITION, x, y, WIDTH, HEIGHT); + Textures.BTN_POSITION.draw(matrices, x, y, WIDTH, HEIGHT); RenderSystem.disableBlend(); diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiScaleBar.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiScaleBar.java index abd7e2074..92d495255 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiScaleBar.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/GuiScaleBar.java @@ -4,11 +4,10 @@ import com.google.common.collect.ImmutableMap.Builder; import hunternif.mc.impl.atlas.client.Textures; import hunternif.mc.impl.atlas.client.gui.core.GuiComponent; -import hunternif.mc.impl.atlas.util.AtlasRenderHelper; +import hunternif.mc.impl.atlas.client.texture.ITexture; import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.TranslatableText; -import net.minecraft.util.Identifier; import java.util.Collections; import java.util.Map; @@ -22,10 +21,10 @@ public class GuiScaleBar extends GuiComponent { private static final int WIDTH = 20; private static final int HEIGHT = 8; - private static final Map textureMap; + private static final Map textureMap; static { - Builder builder = ImmutableMap.builder(); + Builder builder = ImmutableMap.builder(); builder.put(0.0625, Textures.SCALEBAR_512); builder.put(0.125, Textures.SCALEBAR_256); builder.put(0.25, Textures.SCALEBAR_128); @@ -53,16 +52,16 @@ void setMapScale(double scale) { /** * Returns the background texture depending on the scale. */ - private Identifier getTexture() { + private ITexture getTexture() { return textureMap.get(mapScale); } @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTick) { - Identifier texture = getTexture(); + ITexture texture = getTexture(); if (texture == null) return; - AtlasRenderHelper.drawFullTexture(matrices, texture, getGuiX(), getGuiY(), WIDTH, HEIGHT); + texture.draw(matrices, getGuiX(), getGuiY()); if (isMouseOver) { drawTooltip(Collections.singletonList(new TranslatableText("gui.antiqueatlas.scalebar")), MinecraftClient.getInstance().textRenderer); diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/AGuiScrollbar.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/AGuiScrollbar.java index 48fe0b6e2..4330ec4a1 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/AGuiScrollbar.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/AGuiScrollbar.java @@ -1,13 +1,14 @@ package hunternif.mc.impl.atlas.client.gui.core; import com.mojang.blaze3d.systems.RenderSystem; +import hunternif.mc.impl.atlas.client.texture.ITexture; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import org.lwjgl.opengl.GL11; public abstract class AGuiScrollbar extends GuiComponent { - Identifier texture; + ITexture texture; int textureWidth; int textureHeight; /** @@ -70,7 +71,7 @@ public abstract class AGuiScrollbar extends GuiComponent { * @param height height of the texture image * @param capLength length of the non-scaling caps at the beginning and end of the anchor */ - public void setTexture(Identifier texture, int width, int height, int capLength) { + public void setTexture(ITexture texture, int width, int height, int capLength) { this.texture = texture; this.textureWidth = width; this.textureHeight = height; diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiBlinkingImage.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiBlinkingImage.java index 27f231076..b5fcab4c5 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiBlinkingImage.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiBlinkingImage.java @@ -1,9 +1,8 @@ package hunternif.mc.impl.atlas.client.gui.core; import com.mojang.blaze3d.systems.RenderSystem; -import hunternif.mc.impl.atlas.util.AtlasRenderHelper; +import hunternif.mc.impl.atlas.client.texture.ITexture; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; import org.lwjgl.opengl.GL11; /** @@ -14,7 +13,7 @@ * @author Hunternif */ public class GuiBlinkingImage extends GuiComponent { - private Identifier texture; + private ITexture texture; /** * The number of milliseconds the icon spends visible or invisible. */ @@ -28,7 +27,7 @@ public class GuiBlinkingImage extends GuiComponent { */ private boolean isVisible; - public void setTexture(Identifier texture, int width, int height) { + public void setTexture(ITexture texture, int width, int height) { this.texture = texture; setSize(width, height); // Set up the timer so that the image appears visible at the first moment: @@ -68,6 +67,6 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTi } private void drawImage(MatrixStack matrices) { - AtlasRenderHelper.drawFullTexture(matrices, texture, getGuiX(), getGuiY(), getWidth(), getHeight()); + texture.draw(matrices, getGuiX(), getGuiY(), getWidth(), getHeight()); } } diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiCursor.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiCursor.java index c34e79a56..a3a0965d2 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiCursor.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiCursor.java @@ -1,8 +1,7 @@ package hunternif.mc.impl.atlas.client.gui.core; -import hunternif.mc.impl.atlas.util.AtlasRenderHelper; +import hunternif.mc.impl.atlas.client.texture.ITexture; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; /** @@ -12,7 +11,7 @@ */ public class GuiCursor extends GuiComponent { - private Identifier texture; + private ITexture texture; private int textureWidth, textureHeight; /** * Coordinates of the cursor point on the texture. @@ -21,12 +20,12 @@ public class GuiCursor extends GuiComponent { /** * @param texture texture image file - * @param width image width - * @param height image height + * @param width cursor width + * @param height cursor height * @param pointX X of the cursor point on the image * @param pointY Y of the cursor point on the image */ - public void setTexture(Identifier texture, int width, int height, int pointX, int pointY) { + public void setTexture(ITexture texture, int width, int height, int pointX, int pointY) { this.texture = texture; this.textureWidth = width; this.textureHeight = height; @@ -46,6 +45,6 @@ public int getHeight() { @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTick) { - AtlasRenderHelper.drawFullTexture(matrices, texture, mouseX - pointX, mouseY - pointY, textureWidth, textureHeight); + texture.draw(matrices, mouseX - pointX, mouseY - pointY, textureWidth, textureHeight); } } diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiHScrollbar.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiHScrollbar.java index 3bae527d8..47db2fc18 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiHScrollbar.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiHScrollbar.java @@ -1,6 +1,5 @@ package hunternif.mc.impl.atlas.client.gui.core; -import hunternif.mc.impl.atlas.util.AtlasRenderHelper; import net.minecraft.client.util.math.MatrixStack; public class GuiHScrollbar extends AGuiScrollbar { @@ -11,19 +10,14 @@ public GuiHScrollbar(GuiViewport viewport) { @Override protected void drawAnchor(MatrixStack matrices) { - // Draw top cap: - AtlasRenderHelper.drawTexturedRect(matrices, texture, getGuiX() + anchorPos, getGuiY(), 0, 0, - capLength, textureHeight, textureWidth, textureHeight); + // Draw left cap: + texture.draw(matrices, getGuiX() + anchorPos, getGuiY(), capLength, textureHeight, 0, 0, capLength, textureHeight); // Draw body: - AtlasRenderHelper.drawTexturedRect(matrices, texture, getGuiX() + anchorPos + capLength, getGuiY(), - capLength, 0, textureBodyLength, textureHeight, textureWidth, textureHeight, bodyTextureScale, 1); + texture.draw(matrices, getGuiX() + anchorPos + capLength, getGuiY(), anchorSize, textureHeight, capLength, 0, textureBodyLength, textureHeight); - // Draw bottom cap: - AtlasRenderHelper.drawTexturedRect(matrices, texture, - getGuiX() + anchorPos + anchorSize - capLength, getGuiY(), - textureWidth - capLength, 0, - capLength, textureHeight, textureWidth, textureHeight); + // Draw right cap: + texture.draw(matrices, getGuiX() + anchorPos + capLength + anchorSize, getGuiY(), textureWidth - capLength, 0, capLength, textureHeight); } @Override diff --git a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiVScrollbar.java b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiVScrollbar.java index d426f41c3..2b64ff766 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiVScrollbar.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/gui/core/GuiVScrollbar.java @@ -1,6 +1,5 @@ package hunternif.mc.impl.atlas.client.gui.core; -import hunternif.mc.impl.atlas.util.AtlasRenderHelper; import net.minecraft.client.util.math.MatrixStack; public class GuiVScrollbar extends AGuiScrollbar { @@ -12,18 +11,13 @@ public GuiVScrollbar(GuiViewport viewport) { @Override protected void drawAnchor(MatrixStack matrices) { // Draw top cap: - AtlasRenderHelper.drawTexturedRect(matrices, texture, getGuiX(), getGuiY() + anchorPos, 0, 0, - textureWidth, capLength, textureWidth, textureHeight); + texture.draw(matrices, getGuiX(), getGuiY() + anchorPos, textureWidth, capLength, 0, 0, textureWidth, capLength); // Draw body: - AtlasRenderHelper.drawTexturedRect(matrices, texture, getGuiX(), getGuiY() + anchorPos + capLength, - 0, capLength, textureWidth, textureBodyLength, textureWidth, textureHeight, 1, bodyTextureScale); + texture.draw(matrices, getGuiX(), getGuiY() + anchorPos + capLength, textureWidth, anchorSize, 0, capLength, textureWidth, textureBodyLength); // Draw bottom cap: - AtlasRenderHelper.drawTexturedRect(matrices, texture, - getGuiX(), getGuiY() + anchorPos + anchorSize - capLength, - 0, textureHeight - capLength, - textureWidth, capLength, textureWidth, textureHeight); + texture.draw(matrices, getGuiX(),getGuiY() + anchorPos + capLength + anchorSize, 0, textureHeight - capLength, textureWidth, capLength); } @Override diff --git a/src/main/java/hunternif/mc/impl/atlas/client/texture/ATexture.java b/src/main/java/hunternif/mc/impl/atlas/client/texture/ATexture.java new file mode 100644 index 000000000..fd342d487 --- /dev/null +++ b/src/main/java/hunternif/mc/impl/atlas/client/texture/ATexture.java @@ -0,0 +1,54 @@ +package hunternif.mc.impl.atlas.client.texture; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; + +/** + * An abstract base class, which implements the ITexture interface using + * the DrawHelper.drawTexture method provided by minecraft code. + */ +@Environment(EnvType.CLIENT) +public abstract class ATexture implements ITexture { + final Identifier texture; + final boolean autobind; + + public ATexture(Identifier texture) { + this(texture, true); + } + + public ATexture(Identifier texture, boolean autobind) { + this.texture = texture; + this.autobind = autobind; + } + + public Identifier getTexture() { + return texture; + } + + public void bind() { + MinecraftClient.getInstance().getTextureManager().bindTexture(this.texture); + } + + public void draw(MatrixStack matrices, int x, int y) { + draw(matrices, x, y, width(), height()); + } + + public void draw(MatrixStack matrices, int x, int y, int width, int height) { + draw(matrices, x, y, width, height, 0, 0, this.width(), this.height()); + } + + public void draw(MatrixStack matrices, int x, int y, int u, int v, int regionWidth, int regionHeight) { + draw(matrices, x, y, regionWidth, regionHeight, u, v, regionWidth, regionHeight); + } + + public void draw(MatrixStack matrices, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight) { + if (autobind) { + bind(); + } + DrawableHelper.drawTexture(matrices, x, y, width, height, u, v, regionWidth, regionHeight, this.width(), this.height()); + } +} diff --git a/src/main/java/hunternif/mc/impl/atlas/client/texture/ITexture.java b/src/main/java/hunternif/mc/impl/atlas/client/texture/ITexture.java new file mode 100644 index 000000000..c4f2b52d9 --- /dev/null +++ b/src/main/java/hunternif/mc/impl/atlas/client/texture/ITexture.java @@ -0,0 +1,30 @@ +package hunternif.mc.impl.atlas.client.texture; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; + +/** + * A generic interface for textures. The texture know their own width and height. + * All method parameters are provided in pixels. + */ +@Environment(EnvType.CLIENT) +public interface ITexture { + + Identifier getTexture(); + + int width(); + + int height(); + + void bind(); + + void draw(MatrixStack matrices, int x, int y); + + void draw(MatrixStack matrices, int x, int y, int width, int height); + + void draw(MatrixStack matrices, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight); + + void draw(MatrixStack matrices, int x, int y, int u, int v, int regionWidth, int regionHeight); +} diff --git a/src/main/java/hunternif/mc/impl/atlas/client/texture/IconTexture.java b/src/main/java/hunternif/mc/impl/atlas/client/texture/IconTexture.java new file mode 100644 index 000000000..18a546393 --- /dev/null +++ b/src/main/java/hunternif/mc/impl/atlas/client/texture/IconTexture.java @@ -0,0 +1,25 @@ +package hunternif.mc.impl.atlas.client.texture; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.util.Identifier; + +/** + * Represents an icon texture for the atlas gui, such as the arrows and center on player. + */ +@Environment(EnvType.CLIENT) +public class IconTexture extends ATexture { + public IconTexture(Identifier texture) { + super(texture); + } + + @Override + public int width() { + return 16; + } + + @Override + public int height() { + return 16; + } +} diff --git a/src/main/java/hunternif/mc/impl/atlas/client/texture/Texture.java b/src/main/java/hunternif/mc/impl/atlas/client/texture/Texture.java new file mode 100644 index 000000000..a3369f1a6 --- /dev/null +++ b/src/main/java/hunternif/mc/impl/atlas/client/texture/Texture.java @@ -0,0 +1,34 @@ +package hunternif.mc.impl.atlas.client.texture; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.util.Identifier; + +/** + * A generic texture, which needs the size of the texture at construction time. + */ +@Environment(EnvType.CLIENT) +public class Texture extends ATexture { + public final int width; + public final int height; + + public Texture(Identifier texture, int width, int height, boolean autobind) { + super(texture, autobind); + this.width = width; + this.height = height; + } + + public Texture(Identifier texture, int width, int height) { + this(texture, width, height, true); + } + + @Override + public int width() { + return width; + } + + @Override + public int height() { + return height; + } +} diff --git a/src/main/java/hunternif/mc/impl/atlas/client/texture/TileTexture.java b/src/main/java/hunternif/mc/impl/atlas/client/texture/TileTexture.java new file mode 100644 index 000000000..a7264a98d --- /dev/null +++ b/src/main/java/hunternif/mc/impl/atlas/client/texture/TileTexture.java @@ -0,0 +1,35 @@ +package hunternif.mc.impl.atlas.client.texture; + +import hunternif.mc.impl.atlas.client.SubTile; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; + +/** + * A specialized class for textures used as tiles in the atlas map. + * It has a special method to draw SubTile instances give a size of the map. + * By default, TileTextures DO NOT bind the texture. This is on purpose to allow + * the performance optimization shown in the SetTileRenderer. + */ +@Environment(EnvType.CLIENT) +public class TileTexture extends ATexture { + public TileTexture(Identifier texture) { + super(texture, false); + } + + @Override + public int width() { + return 32; + } + + @Override + public int height() { + return 48; + } + + public void drawSubTile(MatrixStack matrices, SubTile subtile, int tileHalfSize) { + draw(matrices, subtile.x * tileHalfSize, subtile.y * tileHalfSize, tileHalfSize, tileHalfSize, subtile.getTextureU() * 8, subtile.getTextureV() * 8, 8, 8); + } + +} diff --git a/src/main/java/hunternif/mc/impl/atlas/registry/MarkerRenderInfo.java b/src/main/java/hunternif/mc/impl/atlas/registry/MarkerRenderInfo.java index c603c9ba8..6b54d792e 100644 --- a/src/main/java/hunternif/mc/impl/atlas/registry/MarkerRenderInfo.java +++ b/src/main/java/hunternif/mc/impl/atlas/registry/MarkerRenderInfo.java @@ -1,14 +1,14 @@ package hunternif.mc.impl.atlas.registry; -import net.minecraft.util.Identifier; +import hunternif.mc.impl.atlas.client.texture.ITexture; public class MarkerRenderInfo { - public final Identifier tex; - public final double x, y; + public final ITexture tex; + public final int x, y; public final int width, height; - - public MarkerRenderInfo(Identifier tex, double x, double y, int width, int height) { + + public MarkerRenderInfo(ITexture tex, int x, int y, int width, int height) { this.tex = tex; this.x = x; this.y = y; this.width = width; this.height = height; diff --git a/src/main/java/hunternif/mc/impl/atlas/registry/MarkerType.java b/src/main/java/hunternif/mc/impl/atlas/registry/MarkerType.java index b9ab9d2b3..e7d6ca4cf 100644 --- a/src/main/java/hunternif/mc/impl/atlas/registry/MarkerType.java +++ b/src/main/java/hunternif/mc/impl/atlas/registry/MarkerType.java @@ -6,6 +6,8 @@ import com.google.gson.JsonPrimitive; import com.mojang.serialization.Lifecycle; import hunternif.mc.impl.atlas.AntiqueAtlasMod; +import hunternif.mc.impl.atlas.client.texture.ITexture; +import hunternif.mc.impl.atlas.client.texture.Texture; import hunternif.mc.impl.atlas.util.BitMatrix; import hunternif.mc.impl.atlas.util.Log; import net.fabricmc.api.EnvType; @@ -52,6 +54,7 @@ public MarkerType(Identifier... icons) { } public static void register(Identifier location, MarkerType type) { + type.initMips(); if (REGISTRY.containsId(location)) { int id = REGISTRY.getRawId(REGISTRY.get(location)); REGISTRY.set(id, RegistryKey.of(KEY, location), type, Lifecycle.stable()); @@ -134,6 +137,11 @@ public Identifier getIcon() { return icons.length == 0 || iconIndex < 0 ? TextureManager.MISSING_IDENTIFIER : icons[iconIndex]; } + public ITexture getTexture() { + if (icons.length == 0 || iconIndex < 0) return null; + return new Texture(getIcon(), iconSizes[iconIndex], iconSizes[iconIndex]); + } + public Identifier[] getAllIcons() { return icons; } @@ -177,9 +185,7 @@ public MarkerRenderInfo getRenderInfo(double scale, double mapScale, double scre int x = -(int) (size * getCenterX()); int y = -(int) (size * getCenterY()); - Identifier icon = getIcon(); - - return new MarkerRenderInfo(icon, x, y, size, size); + return new MarkerRenderInfo(getTexture(), x, y, size, size); } @Environment(EnvType.CLIENT) diff --git a/src/main/java/hunternif/mc/impl/atlas/util/AtlasRenderHelper.java b/src/main/java/hunternif/mc/impl/atlas/util/AtlasRenderHelper.java deleted file mode 100644 index 24fc8e2d1..000000000 --- a/src/main/java/hunternif/mc/impl/atlas/util/AtlasRenderHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -package hunternif.mc.impl.atlas.util; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; -import org.lwjgl.opengl.GL11; - -@Environment(EnvType.CLIENT) -public class AtlasRenderHelper { - public static void drawTexturedRect(MatrixStack matrices, Identifier texture, double x, double y, double u, double v, int width, int height, int imageWidth, int imageHeight, double scaleX, double scaleY) { - MinecraftClient.getInstance().getTextureManager().bindTexture(texture); - DrawableHelper.drawTexture(matrices, (int) x, (int) y, (int) (width * scaleX), (int) (height * scaleY), (int) u, (int) v, width, height, imageWidth, imageHeight); - } - - public static void drawTexturedRect(MatrixStack matrices, Identifier texture, double x, double y, int u, int v, int width, int height, int imageWidth, int imageHeight) { - drawTexturedRect(matrices, texture, x, y, u, v, width, height, imageWidth, imageHeight, 1, 1); - } - - public static void drawFullTexture(MatrixStack matrices, Identifier texture, double x, double y, int width, int height) { - drawTexturedRect(matrices, texture, x, y, 0, 0, width, height, width, height, 1, 1); - } - - public static void drawAutotileCorner(Identifier texture, int x, int y, double u, double v, int tileHalfSize) { - MinecraftClient.getInstance().getTextureManager().bindTexture(texture); - float minU = (float) u / 4; - float maxU = (float) (u + 1) / 4; - float minV = (float) v / 6; - float maxV = (float) (v + 1) / 6; - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder renderer = tessellator.getBuffer(); - renderer.begin(GL11.GL_QUADS, VertexFormats.POSITION_TEXTURE); - renderer.vertex((x + tileHalfSize), (y + tileHalfSize), 0).texture(maxU, maxV).next(); - renderer.vertex((x + tileHalfSize), y, 0).texture(maxU, minV).next(); - renderer.vertex(x, y, 0).texture(minU, minV).next(); - renderer.vertex(x, (y + tileHalfSize), 0).texture(minU, maxV).next(); - tessellator.draw(); - } - - public static void drawFullTexture(MatrixStack matrices, Identifier texture, int x, int y, int size) { - drawFullTexture(matrices, texture, x, y, size, size); - } -} diff --git a/src/main/java/hunternif/mc/impl/atlas/util/ExportImageUtil.java b/src/main/java/hunternif/mc/impl/atlas/util/ExportImageUtil.java index a2d38cc3d..c906bfdb4 100644 --- a/src/main/java/hunternif/mc/impl/atlas/util/ExportImageUtil.java +++ b/src/main/java/hunternif/mc/impl/atlas/util/ExportImageUtil.java @@ -356,7 +356,7 @@ private static void drawMapToGraphics(Graphics2D graphics, if (subtile == null || subtile.tile == null) continue; // Load tile texture - Identifier texture = BiomeTextureMap.instance().getTexture(subtile.variationNumber, subtile.tile); + Identifier texture = BiomeTextureMap.instance().getTexture(subtile).getTexture(); BufferedImage tileImage = textureImageMap.get(texture); if (tileImage == null) continue; @@ -423,7 +423,7 @@ private static void drawMapToGraphics(Graphics2D graphics, type.resetMip(); // Load marker texture - Identifier texture = info.tex; + Identifier texture = info.tex.getTexture(); BufferedImage markerImage = textureImageMap.get(texture); if (markerImage == null) continue; @@ -434,7 +434,7 @@ private static void drawMapToGraphics(Graphics2D graphics, graphics.drawImage( markerImage, (int) (markerX + info.x), (int) (markerY + info.y), - info.width, info.height, null); + info.tex.width(), info.tex.height(), null); } } } diff --git a/src/main/java/kenkron/antiqueatlasoverlay/OverlayRenderer.java b/src/main/java/kenkron/antiqueatlasoverlay/OverlayRenderer.java index 58f536474..3630a8d5a 100644 --- a/src/main/java/kenkron/antiqueatlasoverlay/OverlayRenderer.java +++ b/src/main/java/kenkron/antiqueatlasoverlay/OverlayRenderer.java @@ -35,6 +35,11 @@ public class OverlayRenderer extends DrawableHelper { * somewhere else, but I couldn't be bothered to find it. */ private static final int CHUNK_SIZE = 16; + private static final float INNER_ELEMENTS_SCALE_FACTOR = 1.9F; + private MinecraftClient client; + private PlayerEntity player; + private World world; + private Integer atlasID; /** * Convenience method that returns the first atlas ID for all atlas items @@ -61,13 +66,6 @@ private Integer getPlayerAtlas(PlayerEntity player) { return null; } - private static final float INNER_ELEMENTS_SCALE_FACTOR = 1.9F; - - private MinecraftClient client; - private PlayerEntity player; - private World world; - private Integer atlasID; - public void drawOverlay(MatrixStack matrices) { // Overlay must close if Atlas GUI is opened if (MinecraftClient.getInstance().currentScreen instanceof GuiAtlas) { @@ -103,46 +101,32 @@ public void drawOverlay(MatrixStack matrices) { } private void drawMinimap(MatrixStack matrices) { - this.client.getTextureManager().bindTexture(Textures.BOOK); - drawTexture(matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), - 0, - 0, - 310, - 218, - 310, - 218 - ); + RenderSystem.disableDepthTest(); + + RenderSystem.enableBlend(); + RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + Textures.BOOK.draw(matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5)); - matrices.push(); matrices.push(); matrices.scale(INNER_ELEMENTS_SCALE_FACTOR, INNER_ELEMENTS_SCALE_FACTOR, 1F); - RenderSystem.enableBlend(); - RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); +// RenderSystem.enableBlend(); +// RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); drawTiles(matrices); if (AntiqueAtlasMod.CONFIG.markerSize > 0) { drawMarkers(matrices); } - matrices.pop(); drawPlayer(matrices); - // Overlay the frame so that edges of the map are smooth: - matrices.pop(); - MinecraftClient.getInstance().getTextureManager().bindTexture(Textures.BOOK_FRAME); - drawTexture(matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), - 0, - 0, - 310, - 218, - 310, - 218 - ); + Textures.BOOK_FRAME.draw(matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5)); RenderSystem.disableBlend(); + RenderSystem.enableDepthTest(); } private void drawTiles(MatrixStack matrices) { @@ -171,7 +155,7 @@ private void drawTiles(MatrixStack matrices) { float relativeChunkPositionY = (float) (subtile.y / 2.0 + iteratorScope.minY - chunkPosition.z); renderer.addTileCorner( - BiomeTextureMap.instance().getTexture(subtile.variationNumber, subtile.tile), + BiomeTextureMap.instance().getTexture(subtile).getTexture(), shapeMiddleX + (int) Math.floor(relativeChunkPositionX * AntiqueAtlasMod.CONFIG.tileSize), @@ -207,16 +191,13 @@ private void drawMarkers(MatrixStack matrices) { } private void drawPlayer(MatrixStack matrices) { - // Draw player icon: - - MinecraftClient.getInstance().getTextureManager().bindTexture(Textures.PLAYER); matrices.push(); matrices.translate((int) ((GuiAtlas.WIDTH * 1.5F) / 2F), (int) ((GuiAtlas.HEIGHT * 1.5F) / 2F), 0); matrices.multiply(new Quaternion(Vector3f.POSITIVE_Z, this.player.getHeadYaw() + 180, true)); matrices.translate(-AntiqueAtlasMod.CONFIG.playerIconWidth / 2.0, -AntiqueAtlasMod.CONFIG.playerIconHeight / 2.0, 0); - drawTexture(matrices, 0, 0, AntiqueAtlasMod.CONFIG.playerIconWidth, AntiqueAtlasMod.CONFIG.playerIconHeight, 0, 0, 8, 7, 8, 7); + Textures.PLAYER.draw(matrices, 0,0, AntiqueAtlasMod.CONFIG.playerIconWidth, AntiqueAtlasMod.CONFIG.playerIconHeight); matrices.pop(); } @@ -268,19 +249,7 @@ private void renderMarker(MatrixStack matrices, Marker marker, int x, int y, Wor MarkerType type = MarkerType.REGISTRY.get(marker.getType()); // TODO Fabric - Scale factor? MarkerRenderInfo info = type.getRenderInfo(1, AntiqueAtlasMod.CONFIG.tileSize, 1); - MinecraftClient.getInstance().getTextureManager().bindTexture(info.tex); - drawTexture(matrices, - x - GuiAtlas.MARKER_SIZE / 4 + 1, - y - GuiAtlas.MARKER_SIZE / 4 + 4, - GuiAtlas.MARKER_SIZE / 2, - GuiAtlas.MARKER_SIZE / 2, - 0, - 0, - GuiAtlas.MARKER_SIZE, - GuiAtlas.MARKER_SIZE, - GuiAtlas.MARKER_SIZE, - GuiAtlas.MARKER_SIZE); -// AtlasRenderHelper.drawFullTexture(matrices, info.tex, x, y, AntiqueAtlasMod.CONFIG.markerSize, AntiqueAtlasMod.CONFIG.markerSize); + info.tex.draw(matrices, x - GuiAtlas.MARKER_SIZE / 4 + 1, y - GuiAtlas.MARKER_SIZE / 4 + 4, GuiAtlas.MARKER_SIZE / 2, GuiAtlas.MARKER_SIZE / 2); } private Rect getChunkCoverage(Vec3d position) {