Skip to content

Commit

Permalink
Brings back overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
tyra314 committed May 20, 2019
1 parent de581da commit 5da646f
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 65 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.4.7+build.147

# Mod Properties
mod_version = 5.0.1-fabric
mod_version = 5.0.2-fabric
maven_group = hunternif.mc.atlas
archives_base_name = antiqueatlas

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public static class Appearance {

// TODO - Remove when Forge fixes it's own syncing
//@SubscribeEvent
public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
if (event.getModID().equals(AntiqueAtlasOverlayMod.MODID))
ConfigManager.sync(AntiqueAtlasOverlayMod.MODID, Config.Type.INSTANCE);
}
// public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
// if (event.getModID().equals(AntiqueAtlasOverlayMod.MODID))
// ConfigManager.sync(AntiqueAtlasOverlayMod.MODID, Config.Type.INSTANCE);
// }
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package kenkron.antiqueatlasoverlay;

import net.minecraftforge.fml.common.Mod;
import net.fabricmc.api.ClientModInitializer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(modid = AntiqueAtlasOverlayMod.MODID, version = AntiqueAtlasOverlayMod.VERSION, name = AntiqueAtlasOverlayMod.MODID, clientSideOnly = true, dependencies = "required-after:antiqueatlas;after:forge@[13.20.0.2262,)")
public class AntiqueAtlasOverlayMod {

public class AntiqueAtlasOverlayMod implements ClientModInitializer
{
public static final String MODID = "antiqueatlasoverlay";
public static final String VERSION = "1.2";
public static final Logger LOGGER = LogManager.getLogger("AntiqueAtlasOverlay");


@Override
public void onInitializeClient()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import hunternif.mc.atlas.client.*;
import hunternif.mc.atlas.client.gui.GuiAtlas;
import hunternif.mc.atlas.core.DimensionData;
import hunternif.mc.atlas.item.ItemAtlas;
import hunternif.mc.atlas.marker.DimensionMarkersData;
import hunternif.mc.atlas.marker.Marker;
import hunternif.mc.atlas.marker.MarkersData;
Expand All @@ -20,41 +21,30 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import none.XX_1_12_2_none_bit_XX;
import net.minecraft.world.dimension.DimensionType;
import org.lwjgl.opengl.GL11;

import java.util.List;

@Mod.EventBusSubscriber(modid = AntiqueAtlasOverlayMod.MODID)
public class AAORenderEventReceiver {
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.
*/
private static final int CHUNK_SIZE = 16;

/**
* new ScaledResolution(mc).getScaleFactor();
*/
private static int screenScale = 1;

private static XX_1_12_2_none_bit_XX res;

/**
* Convenience method that returns the first atlas ID for all atlas items
* the player is currently carrying in the hotbar/offhand. Returns null if
* there are none. Offhand gets priority.
**/
private static Integer getPlayerAtlas(PlayerEntity player) {
if (!SettingsConfig.gameplay.itemNeeded) {
return player.getUniqueID().hashCode();
return player.getUuid().hashCode();
}

ItemStack stack = player.getHeldItemOffhand();
ItemStack stack = player.getOffHandStack();
if (!stack.isEmpty() && stack.getItem() == RegistrarAntiqueAtlas.ATLAS) {
return stack.getDamage();
}
Expand All @@ -69,40 +59,34 @@ private static Integer getPlayerAtlas(PlayerEntity player) {
return null;
}

@SubscribeEvent(priority = EventPriority.NORMAL)
public static void eventHandler(RenderGameOverlayEvent.Post event) {
if (event.getType() != RenderGameOverlayEvent.ElementType.ALL) {
return;
}
public static void drawOverlay(int gameWidth, int gameHeight) {

if (!AAOConfig.appearance.enabled) {
return;
}

// Overlay must close if Atlas GUI is opened
if (MinecraftClient.getInstance().XX_1_12_2_m_XX instanceof GuiAtlas) {
if (MinecraftClient.getInstance().currentScreen instanceof GuiAtlas) {
return;
}

ClientPlayerEntity player = MinecraftClient.getInstance().player;
Integer atlas = null;

if (AAOConfig.appearance.requiresHold) {
ItemStack stack = player.getHeldItemMainhand();
ItemStack stack2 = player.getHeldItemOffhand();
ItemStack stack = player.getMainHandStack();
ItemStack stack2 = player.getOffHandStack();

if (!stack.isEmpty() && stack.getItem() == RegistrarAntiqueAtlas.ATLAS) {
atlas = stack.getDamage();
atlas = ((ItemAtlas) stack.getItem()).getAtlasID(stack);
} else if (!stack2.isEmpty() && stack2.getItem() == RegistrarAntiqueAtlas.ATLAS) {
atlas = stack2.getDamage();
atlas = ((ItemAtlas) stack.getItem()).getAtlasID(stack2);
}
} else {
atlas = getPlayerAtlas(player);
}

if (atlas != null) {
int gameWidth = event.getResolution().a();
int gameHeight = event.getResolution().b();
// remember, y=0 is at the top
Rect bounds = new Rect().setOrigin(AAOConfig.position.xPosition, AAOConfig.position.yPosition);
if (AAOConfig.position.alignRight) {
Expand All @@ -113,17 +97,15 @@ public static void eventHandler(RenderGameOverlayEvent.Post event) {
}

bounds.setSize(AAOConfig.position.width, AAOConfig.position.height);
res = event.getResolution();
drawMinimap(bounds, atlas, player.getPositionVector(), player.getRotationYawHead(), player.dimension);
drawMinimap(bounds, atlas, player.getPos(), player.getHeadYaw(), player.dimension);
}
}

private static void drawMinimap(Rect shape, int atlasID, Vec3d position, float rotation,
int dimension) {
screenScale = new XX_1_12_2_none_bit_XX(MinecraftClient.getInstance()).e();
DimensionType dimension) {
GlStateManager.texCoordPointer(1, 1, 1, 1);
GlStateManager.enableBlend();
GlStateManager.texGenMode(GL11.GL_GREATER, 0); // So light detail on tiles is
GlStateManager.alphaFunc(GL11.GL_GREATER, 0); // So light detail on tiles is
// visible
AtlasRenderHelper.drawFullTexture(Textures.BOOK, shape.minX,
shape.minY, shape.getWidth(), shape.getHeight());
Expand All @@ -150,16 +132,17 @@ private static void drawMinimap(Rect shape, int atlasID, Vec3d position, float r
}

private static void drawTiles(Rect shape, int atlasID, Vec3d position,
int dimension) {
DimensionType dimension) {
GL11.glEnable(GL11.GL_SCISSOR_TEST);
// glScissor uses the default window coordinates,
// the display window does not. We need to fix this
glScissorGUI(shape);

GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

DimensionData biomeData = AntiqueAtlasMod.atlasData.getAtlasData(
atlasID, MinecraftClient.getInstance().XX_1_12_2_f_XX).getDimensionData(dimension);
atlasID, MinecraftClient.getInstance().world).getDimensionData(dimension);

TileRenderIterator iter = new TileRenderIterator(biomeData);
Rect iteratorScope = getChunkCoverage(position, shape);
Expand All @@ -186,7 +169,7 @@ private static void drawTiles(Rect shape, int atlasID, Vec3d position,
float relativeChunkPositionY = (float) (subtile.y / 2.0
+ iteratorScope.minY - chunkPosition.z);
renderer.addTileCorner(
BiomeTextureMap.instance().getTexture(subtile.tile),
BiomeTextureMap.instance().getTexture(subtile.variationNumber, subtile.tile),
shapeMiddleX
+ (int) Math.floor(relativeChunkPositionX
* AAOConfig.appearance.tileSize),
Expand All @@ -203,7 +186,7 @@ private static void drawTiles(Rect shape, int atlasID, Vec3d position,
}

private static void drawMarkers(Rect shape, int atlasID, Vec3d position,
int dimension) {
DimensionType dimension) {

GL11.glEnable(GL11.GL_SCISSOR_TEST);
// glScissor uses the default window coordinates,
Expand All @@ -212,7 +195,7 @@ private static void drawMarkers(Rect shape, int atlasID, Vec3d position,

// biomeData needed to prevent undiscovered markers from appearing
DimensionData biomeData = AntiqueAtlasMod.atlasData.getAtlasData(
atlasID, MinecraftClient.getInstance().XX_1_12_2_f_XX).getDimensionData(
atlasID, MinecraftClient.getInstance().world).getDimensionData(
dimension);
DimensionMarkersData globalMarkersData = AntiqueAtlasMod.globalMarkersData
.getData().getMarkersDataInDimension(dimension);
Expand All @@ -221,7 +204,7 @@ private static void drawMarkers(Rect shape, int atlasID, Vec3d position,
drawMarkersData(globalMarkersData, shape, biomeData, position);

MarkersData markersData = AntiqueAtlasMod.markersData.getMarkersData(
atlasID, MinecraftClient.getInstance().XX_1_12_2_f_XX);
atlasID, MinecraftClient.getInstance().world);
DimensionMarkersData localMarkersData = null;
if (markersData != null) {
localMarkersData = markersData.getMarkersDataInDimension(dimension);
Expand All @@ -241,7 +224,7 @@ private static void drawPlayer(float x, float y, float rotation) {
GlStateManager.pushMatrix();
GlStateManager.translatef(x, y, 0);
GlStateManager.rotatef(180 + rotation, 0, 0, 1);
GlStateManager.getTexLevelParameter(-AAOConfig.appearance.playerIconWidth / 2, -AAOConfig.appearance.playerIconHeight / 2, 0);
GlStateManager.translatef(-AAOConfig.appearance.playerIconWidth / 2, -AAOConfig.appearance.playerIconHeight / 2, 0);
AtlasRenderHelper.drawFullTexture(Textures.PLAYER, 0, 0, AAOConfig.appearance.playerIconWidth, AAOConfig.appearance.playerIconHeight);
GlStateManager.popMatrix();
GlStateManager.texCoordPointer(1, 1, 1, 1);
Expand Down Expand Up @@ -298,7 +281,8 @@ private static void renderMarker(Marker marker, int x, int y,
AntiqueAtlasOverlayMod.LOGGER.warn("Could not find marker type for {}", marker.getId());
return;
}
MarkerRenderInfo info = m.getRenderInfo(1, AAOConfig.appearance.tileSize, screenScale);
// TODO Fabric - Scale factor?
MarkerRenderInfo info = m.getRenderInfo(1, AAOConfig.appearance.tileSize, 1);
AtlasRenderHelper.drawFullTexture(info.tex, x, y, AAOConfig.appearance.markerSize, AAOConfig.appearance.markerSize);
}

Expand All @@ -324,10 +308,12 @@ private static Rect getChunkCoverage(Vec3d position, Rect windowShape) {
private static void glScissorGUI(Rect shape) {
// glScissor uses the default window coordinates,
// the display window does not. We need to fix this
int mcHeight = MinecraftClient.getInstance().XX_1_12_2_e_XX;
float scissorScaleX = MinecraftClient.getInstance().XX_1_12_2_d_XX * 1.0f
/ res.a();
float scissorScaleY = mcHeight * 1.0f / res.b();
float scissorScaleX = MinecraftClient.getInstance().window.getWidth() * 1.0f
/ MinecraftClient.getInstance().window.getScaledWidth();

int mcHeight = MinecraftClient.getInstance().window.getHeight();
float scissorScaleY = mcHeight * 1.0f / MinecraftClient.getInstance().window.getScaledHeight();

GL11.glScissor((int) (shape.minX * scissorScaleX),
(int) (mcHeight - shape.maxY * scissorScaleY),
(int) (shape.getWidth() * scissorScaleX),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package kenkron.antiqueatlasoverlay;

import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.util.Identifier;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.HashMap;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.server.network.packet.ResourcePackStatusC2SPacket;

/**
* The minimap render is a bit slow. The function that really takes time is
Expand All @@ -17,27 +19,27 @@
*/
class SetTileRenderer {

private final HashMap<ResourcePackStatusC2SPacket, ArrayList<TileCorner>> subjects = new HashMap<>();
private final HashMap<Identifier, ArrayList<TileCorner>> subjects = new HashMap<>();
private int tileHalfSize = 8;

public SetTileRenderer(int tileHalfSize) {
this.tileHalfSize = tileHalfSize;
}

public void addTileCorner(ResourcePackStatusC2SPacket texture, int x, int y, int u, int v) {
public void addTileCorner(Identifier texture, int x, int y, int u, int v) {
ArrayList<TileCorner> set = subjects.computeIfAbsent(texture, k -> new ArrayList<>());
set.add(new TileCorner(x, y, u, v));
}

public void draw() {
for (ResourcePackStatusC2SPacket key : subjects.keySet()) {
for (Identifier key : subjects.keySet()) {
ArrayList<TileCorner> tca = subjects.get(key);
//Effectively a call to GL11.glBindTexture(GL11.GL_TEXTURE_2D, p_94277_0_);
MinecraftClient.getInstance().textureManager.XX_1_12_2_a_XX(key);
MinecraftClient.getInstance().getTextureManager().bindTexture(key);

Tessellator tessellator = Tessellator.getInstance();
BufferBuilder renderer = tessellator.getBufferBuilder();
renderer.begin(GL11.GL_QUADS, ddk.XX_1_12_2_g_XX);
renderer.begin(GL11.GL_QUADS, VertexFormats.POSITION_UV);
for (TileCorner tc : tca) {
drawInlineAutotileCorner(tc.x, tc.y, tc.u, tc.v);
}
Expand All @@ -52,10 +54,10 @@ private void drawInlineAutotileCorner(int x, int y, int u, int v) {
float maxV = (v + 1) / 6f;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder renderer = tessellator.getBufferBuilder();
renderer.postNormal(x + tileHalfSize, y + tileHalfSize, 0).a(maxU, maxV).d();
renderer.postNormal(x + tileHalfSize, y, 0).a(maxU, minV).d();
renderer.postNormal(x, y, 0).a(minU, minV).d();
renderer.postNormal(x, y + tileHalfSize, 0).a(minU, maxV).d();
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();
}

public class TileCorner {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kenkron.antiqueatlasoverlay.mixin;

import kenkron.antiqueatlasoverlay.OverlayRenderer;
import net.minecraft.client.gui.hud.InGameHud;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(InGameHud.class)
public class MixinInGameHud {
@Shadow
private int scaledWidth;
@Shadow
private int scaledHeight;

@Inject(at = @At("TAIL"), method = "draw")
public void draw(float partial, CallbackInfo info) {
OverlayRenderer.drawOverlay(scaledWidth, scaledHeight);
}
}
13 changes: 13 additions & 0 deletions src/main/resources/antiqueatlasoverlay.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"required": true,
"package": "kenkron.antiqueatlasoverlay.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
"MixinInGameHud"
],
"injectors": {
"defaultRequire": 1
}
}
6 changes: 4 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"hunternif.mc.atlas.AntiqueAtlasMod"
],
"client": [
"hunternif.mc.atlas.AntiqueAtlasModClient"
"hunternif.mc.atlas.AntiqueAtlasModClient",
"kenkron.antiqueatlasoverlay.AntiqueAtlasOverlayMod"
]
},
"environment": "*",
Expand All @@ -21,6 +22,7 @@
"fabric": ">=0.2.6"
},
"mixins": [
"antiqueatlas.mixins.json"
"antiqueatlas.mixins.json",
"antiqueatlasoverlay.mixins.json"
]
}

0 comments on commit 5da646f

Please sign in to comment.