Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabric & Forge port to 1.20.1 #471

Open
wants to merge 6 commits into
base: 1.18
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Antique Atlas ![Minecraft 1.16.5](https://img.shields.io/badge/minecraft-1.16.5-blue.svg) [![Build Status](https://github.com/AntiqueAtlasTeam/AntiqueAtlas/workflows/Build%20Status/badge.svg)](https://github.com/AntiqueAtlasTeam/AntiqueAtlas/actions)
# Antique Atlas ![Minecraft 1.30.2](https://img.shields.io/badge/minecraft-1.20.1-blue.svg) [![Build Status](https://github.com/AntiqueAtlasTeam/AntiqueAtlas/workflows/Build%20Status/badge.svg)](https://github.com/AntiqueAtlasTeam/AntiqueAtlas/actions)
Antique Atlas is a book that acts like a map featuring infinite scrolling, zoom and custom labeled markers. The map is generated around the player by calculating the average biome in each 16x16 chunk.

Navigate the map by dragging it with the mouse, clicking arrow buttons or pressing arrow keys on the keyboard. Use the +/- keys or mouse wheel to zoom in and out.
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/hunternif/mc/api/AtlasAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -33,7 +33,7 @@ public static int getVersion() {
}

public static Item getAtlasItem() {
return Registry.ITEM.get(new Identifier("antiqueatlas:antique_atlas"));
return Registries.ITEM.get(new Identifier("antiqueatlas:antique_atlas"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class AntiqueAtlasConfig implements ConfigData {

@ConfigEntry.Category("performance")
@Comment("If true, all resource pack loading information will be logged during start and reload.")
public boolean resourcePackLogging = true;
public boolean resourcePackLogging = false;

@ConfigEntry.Category("appearance")
@Comment("The size (in GUI pixels) of a map's tile.\nNote that this will change with Minecraft's GUI scale configuration.\nWhen using a small gui scale, the map may look better with a TILE_SIZE of 16 or more.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import hunternif.mc.impl.atlas.core.GlobalTileDataHandler;
import hunternif.mc.impl.atlas.core.PlayerEventHandler;
import hunternif.mc.impl.atlas.core.TileDataHandler;
import hunternif.mc.impl.atlas.core.scaning.TileDetectorBase;
import hunternif.mc.impl.atlas.core.scaning.WorldScanner;
import hunternif.mc.impl.atlas.event.RecipeCraftedCallback;
import hunternif.mc.impl.atlas.event.RecipeCraftedHandler;
Expand Down Expand Up @@ -55,7 +54,8 @@ public static AtlasIdData getAtlasIdData(World world) {
}

public static void init() {
TileDetectorBase.scanBiomeTypes();
//We just check for tags now
//TileDetectorBase.scanBiomeTypes();

AutoConfig.register(AntiqueAtlasConfig.class, JanksonConfigSerializer::new);
CONFIG = AutoConfig.getConfigHolder(AntiqueAtlasConfig.class).getConfig();
Expand Down
15 changes: 7 additions & 8 deletions common/src/main/java/hunternif/mc/impl/atlas/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceReloader;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;

import java.util.Map;
Expand Down Expand Up @@ -63,19 +62,19 @@ public void initClient() {
* we need the ClientWorld loaded here.
*/
public static void assignCustomBiomeTextures(ClientWorld world) {
for (Map.Entry<RegistryKey<Biome>, Biome> biome : BuiltinRegistries.BIOME.getEntrySet()) {
Identifier id = BuiltinRegistries.BIOME.getId(biome.getValue());
for (Map.Entry<RegistryKey<Biome>, Biome> biome : world.getRegistryManager().get(RegistryKeys.BIOME).getEntrySet()) {
Identifier id = world.getRegistryManager().get(RegistryKeys.BIOME).getId(biome.getValue());
if (!TileTextureMap.instance().isRegistered(id)) {
TileTextureMap.instance().autoRegister(id, biome.getKey());
}
}

for (Map.Entry<RegistryKey<Biome>, Biome> entry : world.getRegistryManager().get(Registry.BIOME_KEY).getEntrySet()) {
Identifier id = world.getRegistryManager().get(Registry.BIOME_KEY).getId(entry.getValue());
/*for (Map.Entry<RegistryKey<Biome>, Biome> entry : world.getRegistryManager().get(RegistryKeys.BIOME).getEntrySet()) {
Identifier id = world.getRegistryManager().get(RegistryKeys.BIOME).getId(entry.getValue());
if (!TileTextureMap.instance().isRegistered(id)) {
TileTextureMap.instance().autoRegister(id, entry.getKey());
}
}
}*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package hunternif.mc.impl.atlas.api.impl;

import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.api.TileAPI;
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.core.AtlasData;
import hunternif.mc.impl.atlas.core.TileDataStorage;
import hunternif.mc.impl.atlas.network.packet.c2s.play.PutTileC2SPacket;
import hunternif.mc.impl.atlas.network.packet.s2c.play.PutGlobalTileS2CPacket;
import hunternif.mc.impl.atlas.network.packet.s2c.play.DeleteGlobalTileS2CPacket;
import hunternif.mc.impl.atlas.network.packet.s2c.play.PutGlobalTileS2CPacket;
import hunternif.mc.impl.atlas.network.packet.s2c.play.PutTileS2CPacket;
import hunternif.mc.impl.atlas.util.Log;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.mojang.blaze3d.systems.RenderSystem;
import hunternif.mc.api.client.AtlasClientAPI;
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.item.AntiqueAtlasItems;
import hunternif.mc.impl.atlas.client.gui.GuiAtlas;
import hunternif.mc.impl.atlas.core.WorldData;
import hunternif.mc.impl.atlas.item.AntiqueAtlasItems;
import hunternif.mc.impl.atlas.item.AtlasItem;
import hunternif.mc.impl.atlas.marker.DimensionMarkersData;
import hunternif.mc.impl.atlas.marker.Marker;
Expand All @@ -16,21 +16,20 @@
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.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Quaternion;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3f;
import net.minecraft.world.World;
import org.joml.Quaternionf;
import org.lwjgl.opengl.GL11;

import java.util.List;

@Environment(EnvType.CLIENT)
public class OverlayRenderer extends DrawableHelper {
public class OverlayRenderer {
/**
* Number of blocks per chunk in minecraft. This is certianly stored
* somewhere else, but I couldn't be bothered to find it.
Expand All @@ -40,7 +39,7 @@ public class OverlayRenderer extends DrawableHelper {
private PlayerEntity player;
private World world;

public void drawOverlay(MatrixStack matrices, VertexConsumerProvider vertexConsumer, int light, ItemStack atlas) {
public void drawOverlay(MatrixStack matrixStack, VertexConsumerProvider vertexConsumer, int light, ItemStack atlas) {
// Overlay must close if Atlas GUI is opened
if (MinecraftClient.getInstance().currentScreen instanceof GuiAtlas) {
return;
Expand All @@ -55,48 +54,48 @@ public void drawOverlay(MatrixStack matrices, VertexConsumerProvider vertexConsu

if (!atlas.isEmpty() && atlas.getItem() == AntiqueAtlasItems.ATLAS.getOrNull()) {
int atlasID = AtlasItem.getAtlasID(atlas);
drawMinimap(matrices, atlasID, vertexConsumer, light);
drawMinimap(matrixStack, atlasID, vertexConsumer, light);
}
}

private void drawMinimap(MatrixStack matrices, int atlasID, VertexConsumerProvider buffer, int light) {
private void drawMinimap(MatrixStack matrixStack, int atlasID, VertexConsumerProvider buffer, int light) {
RenderSystem.enableBlend();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

matrices.push();
matrices.translate(0, 0, 0.01);
Textures.BOOK.drawWithLight(buffer, matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), light);
matrices.pop();
matrixStack.push();
matrixStack.translate(0, 0, 0.01);
Textures.BOOK.drawWithLight(buffer, matrixStack, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), light);
matrixStack.pop();

matrices.push();
matrices.scale(INNER_ELEMENTS_SCALE_FACTOR, INNER_ELEMENTS_SCALE_FACTOR, 1F);
matrixStack.push();
matrixStack.scale(INNER_ELEMENTS_SCALE_FACTOR, INNER_ELEMENTS_SCALE_FACTOR, 1F);


drawTiles(buffer, matrices, atlasID, light);
matrices.translate(0, 0, -0.01);
drawTiles(buffer, matrixStack, atlasID, light);
matrixStack.translate(0, 0, -0.01);
if (AntiqueAtlasMod.CONFIG.markerSize > 0) {
drawMarkers(buffer, matrices, atlasID, light);
drawMarkers(buffer, matrixStack, atlasID, light);
}
matrices.pop();
matrixStack.pop();

matrices.translate(0, 0, -0.02);
drawPlayer(buffer, matrices, light);
matrixStack.translate(0, 0, -0.02);
drawPlayer(buffer, matrixStack, light);

// Overlay the frame so that edges of the map are smooth:
matrices.translate(0, 0, -0.01);
Textures.BOOK_FRAME.drawWithLight(buffer, matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), light);
matrixStack.translate(0, 0, -0.01);
Textures.BOOK_FRAME.drawWithLight(buffer, matrixStack, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), light);

RenderSystem.disableBlend();
}

private void drawTiles(VertexConsumerProvider buffer, MatrixStack matrices, int atlasID, int light) {
private void drawTiles(VertexConsumerProvider buffer, MatrixStack matrixStack, int atlasID, int light) {
Rect iteratorScope = getChunkCoverage(player.getPos());
TileRenderIterator iter = AtlasClientAPI.getTileAPI().getTiles(world, atlasID, iteratorScope, 1);

Vec3d chunkPosition = player.getPos().multiply(1D / CHUNK_SIZE, 1D / CHUNK_SIZE, 1D / CHUNK_SIZE);
int shapeMiddleX = (int) ((GuiAtlas.WIDTH * 1.5F) / (INNER_ELEMENTS_SCALE_FACTOR * 2));
int shapeMiddleY = (int) ((GuiAtlas.HEIGHT * 1.5F) / (INNER_ELEMENTS_SCALE_FACTOR * 2));
SetTileRenderer renderer = new SetTileRenderer(buffer, matrices, AntiqueAtlasMod.CONFIG.tileSize / 2, light);
SetTileRenderer renderer = new SetTileRenderer(buffer, matrixStack, AntiqueAtlasMod.CONFIG.tileSize / 2, light);

while (iter.hasNext()) {
SubTileQuartet subtiles = iter.next();
Expand All @@ -123,7 +122,7 @@ private void drawTiles(VertexConsumerProvider buffer, MatrixStack matrices, int
renderer.draw();
}

private void drawMarkers(VertexConsumerProvider buffer, MatrixStack matrices, int atlasID, int light) {
private void drawMarkers(VertexConsumerProvider buffer, MatrixStack matrixStack, int atlasID, int light) {
// biomeData needed to prevent undiscovered markers from appearing
WorldData biomeData = AntiqueAtlasMod.tileData.getData(
atlasID, this.world).getWorldData(
Expand All @@ -132,27 +131,27 @@ private void drawMarkers(VertexConsumerProvider buffer, MatrixStack matrices, in
.getData().getMarkersDataInWorld(this.world.getRegistryKey());

// Draw global markers:
drawMarkersData(buffer, matrices, globalMarkersData, biomeData, light);
drawMarkersData(buffer, matrixStack, globalMarkersData, biomeData, light);

MarkersData markersData = AntiqueAtlasMod.markersData.getMarkersData(
atlasID, MinecraftClient.getInstance().world);
if (markersData != null) {
DimensionMarkersData localMarkersData = markersData.getMarkersDataInWorld(world.getRegistryKey());

// Draw local markers:
drawMarkersData(buffer, matrices, localMarkersData, biomeData, light);
drawMarkersData(buffer, matrixStack, localMarkersData, biomeData, light);
}
}

private void drawPlayer(VertexConsumerProvider buffer, MatrixStack matrices, int light) {
matrices.push();
private void drawPlayer(VertexConsumerProvider buffer, MatrixStack matrixStack, int light) {
matrixStack.push();

matrices.translate((int) ((GuiAtlas.WIDTH * 1.5F) / 2F), (int) ((GuiAtlas.HEIGHT * 1.5F) / 2F), 0);
matrices.multiply(new Quaternion(Vec3f.POSITIVE_Z, this.player.getHeadYaw() + 180, true));
matrices.translate(-AntiqueAtlasMod.CONFIG.playerIconWidth / 2.0, -AntiqueAtlasMod.CONFIG.playerIconHeight / 2.0, 0);
matrixStack.translate((int) ((GuiAtlas.WIDTH * 1.5F) / 2F), (int) ((GuiAtlas.HEIGHT * 1.5F) / 2F), 0);
matrixStack.multiply(new Quaternionf(RotationAxis.POSITIVE_Z.rotationDegrees(this.player.getHeadYaw() + 180)));
matrixStack.translate(-AntiqueAtlasMod.CONFIG.playerIconWidth / 2.0, -AntiqueAtlasMod.CONFIG.playerIconHeight / 2.0, 0);

Textures.PLAYER.drawWithLight(buffer, matrices, 0, 0, AntiqueAtlasMod.CONFIG.playerIconWidth, AntiqueAtlasMod.CONFIG.playerIconHeight, light);
matrices.pop();
Textures.PLAYER.drawWithLight(buffer, matrixStack, 0, 0, AntiqueAtlasMod.CONFIG.playerIconWidth, AntiqueAtlasMod.CONFIG.playerIconHeight, light);
matrixStack.pop();
}

private void drawMarkersData(VertexConsumerProvider buffer, MatrixStack matrices, DimensionMarkersData markersData, WorldData biomeData, int light) {
Expand Down Expand Up @@ -189,7 +188,7 @@ private void drawMarkersData(VertexConsumerProvider buffer, MatrixStack matrices
}
}

private void renderMarker(VertexConsumerProvider buffer, MatrixStack matrices, Marker marker, int x, int y, WorldData biomeData, int light) {
private void renderMarker(VertexConsumerProvider buffer, MatrixStack matrixStack, Marker marker, int x, int y, WorldData biomeData, int light) {
int tileHalfSize = GuiAtlas.MARKER_SIZE / 16;
if (!((x + tileHalfSize) <= 240 && (x - tileHalfSize >= 3) && (y + tileHalfSize) < 166 && (y - tileHalfSize) >= 0))
return;
Expand All @@ -201,7 +200,7 @@ private void renderMarker(VertexConsumerProvider buffer, MatrixStack matrices, M
MarkerType type = MarkerType.REGISTRY.get(marker.getType());
// TODO Fabric - Scale factor?
MarkerRenderInfo info = type.getRenderInfo(1, AntiqueAtlasMod.CONFIG.tileSize, 1);
info.tex.drawWithLight(buffer, matrices, x - GuiAtlas.MARKER_SIZE / 4 + 4, y - GuiAtlas.MARKER_SIZE / 4 + 4, GuiAtlas.MARKER_SIZE / 2, GuiAtlas.MARKER_SIZE / 2, light);
info.tex.drawWithLight(buffer, matrixStack, x - GuiAtlas.MARKER_SIZE / 4 + 4, y - GuiAtlas.MARKER_SIZE / 4 + 4, GuiAtlas.MARKER_SIZE / 2, GuiAtlas.MARKER_SIZE / 2, light);
}

private Rect getChunkCoverage(Vec3d position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
class SetTileRenderer {

private final HashMap<Identifier, ArrayList<TileCorner>> subjects = new HashMap<>();
private final MatrixStack matrices;
private final MatrixStack matrixStack;
private final int tileHalfSize;
private final int light;
private final VertexConsumerProvider buffer;

public SetTileRenderer(VertexConsumerProvider buffer, MatrixStack matrices, int tileHalfSize, int light) {
this.matrices = matrices;
public SetTileRenderer(VertexConsumerProvider buffer, MatrixStack matrixStack, int tileHalfSize, int light) {
this.matrixStack = matrixStack;
this.tileHalfSize = tileHalfSize;
this.light = light;
this.buffer = buffer;
Expand All @@ -53,7 +53,7 @@ public void draw() {
private void drawInlineAutotileCorner(ITexture texture, int x, int y, int u, int v) {
// This is dumb. But because there are drawn four at a time, these chunks prevent rendering outside of our map
if ((x + tileHalfSize) <= 240 && (x - tileHalfSize >= 0) && (y + tileHalfSize) < 166 && (y - tileHalfSize) >= 0) {
texture.drawWithLight(this.buffer, this.matrices, x, y, tileHalfSize, tileHalfSize, u, v, 1, 1, this.light);
texture.drawWithLight(this.buffer, matrixStack, x, y, tileHalfSize, tileHalfSize, u, v, 1, 1, this.light);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public CompletableFuture<Map<Identifier, ITexture>> load(ResourceManager manager
return CompletableFuture.supplyAsync(() -> {
Map<Identifier, ITexture> textures = new HashMap<>();

for (Identifier id : manager.findResources("textures/gui/tiles", (s) -> s.endsWith(".png"))) {
for (Identifier id : manager.findResources("textures/gui/tiles", (s) -> s.getPath().endsWith(".png")).keySet()) {
// id now contains the physical file path of the texture
try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public CompletableFuture<Collection<TextureSet>> load(ResourceManager manager, P
Map<Identifier, TextureSet> sets = new HashMap<>();

try {
for (Identifier id : manager.findResources("atlas/texture_sets", (s) -> s.endsWith(".json"))) {
for (Identifier id : manager.findResources("atlas/texture_sets", (s) -> s.getPath().endsWith(".json")).keySet()) {
Identifier texture_id = new Identifier(
id.getNamespace(),
id.getPath().replace("atlas/texture_sets/", "").replace(".json", "")
);

try {
Resource resource = manager.getResource(id);
Resource resource = manager.getResource(id).get();
try (
InputStream stream = resource.getInputStream();
InputStreamReader reader = new InputStreamReader(stream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public CompletableFuture<Map<Identifier, Identifier>> load(ResourceManager manag
Map<Identifier, Identifier> map = new HashMap<>();

try {
for (Identifier id : manager.findResources("atlas/tiles", (s) -> s.endsWith(".json"))) {
for (Identifier id : manager.findResources("atlas/tiles", (s) -> s.getPath().endsWith(".json")).keySet()) {
Identifier tile_id = new Identifier(id.getNamespace(), id.getPath().replace("atlas/tiles/", "").replace(".json", ""));

try {
Resource resource = manager.getResource(id);
Resource resource = manager.getResource(id).get();
try (InputStream stream = resource.getInputStream(); InputStreamReader reader = new InputStreamReader(stream)) {
JsonObject object = JsonParser.parseReader(reader).getAsJsonObject();

Expand Down
Loading