Skip to content

Commit

Permalink
Add conquered mark into the magic map (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhehedream authored Dec 8, 2024
1 parent ef53f25 commit 42c1539
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 27 deletions.
15 changes: 12 additions & 3 deletions src/main/java/twilightforest/TFMagicMapData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import net.minecraft.world.World;
import net.minecraft.world.storage.MapData;

import twilightforest.world.ChunkProviderTwilightForest;
import twilightforest.world.TFWorldChunkManager;
import twilightforest.world.WorldProviderTwilightForest;

public class TFMagicMapData extends MapData {

private static final int FEATURE_DATA_BYTE = 18;
public List<MapCoord> featuresVisibleOnMap = new ArrayList<>();
public static final byte CONQ_OFFSET = 80;

public TFMagicMapData(String par1Str) {
super(par1Str);
Expand Down Expand Up @@ -51,14 +54,15 @@ public void writeToNBT(NBTTagCompound par1NBTTagCompound) {
/**
* Adds a twilight forest feature to the map.
*/
public void addFeatureToMap(TFFeature feature, int x, int z) {
public void addFeatureToMap(TFFeature feature, int x, int z, boolean conq) {
byte relativeX = (byte) ((x - this.xCenter) >> this.scale);
byte relativeZ = (byte) ((z - this.zCenter) >> this.scale);
byte rangeX = 64;
byte rangeY = 64;

if (relativeX >= (-rangeX) && relativeZ >= (-rangeY) && relativeX <= rangeX && relativeZ <= rangeY) {
byte markerIcon = (byte) feature.featureID;
markerIcon += conq ? CONQ_OFFSET : 0;
byte mapX = (byte) (relativeX << 1);
byte mapZ = (byte) (relativeZ << 1);
byte mapRotation = 8;
Expand Down Expand Up @@ -93,13 +97,18 @@ public void checkExistingFeatures(World world) {
int worldZ = (coord.centerZ << this.scale - 1) + this.zCenter;

if (world != null && world.getWorldChunkManager() instanceof TFWorldChunkManager tfManager) {
coord.iconSize = (byte) tfManager.getFeatureID(worldX, worldZ, world);

if (coord.iconSize == 0) {
if (toRemove == null) {
toRemove = new ArrayList<>();
}
toRemove.add(coord);
} else if (coord.iconSize < CONQ_OFFSET) {
ChunkProviderTwilightForest chunkProvider = ((WorldProviderTwilightForest) world.provider)
.getChunkProvider();
coord.iconSize = (byte) tfManager.getFeatureID(worldX, worldZ, world);
if (chunkProvider.isStructureConquered(worldX, 0, worldZ)) {
coord.iconSize += CONQ_OFFSET;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public void renderMap(EntityPlayer par1EntityPlayer, TextureManager par2TextureM
par2TextureManager.bindTexture(twilightMapIcons);

for (MapCoord mapCoord : magicMapData.featuresVisibleOnMap) {
int size = mapCoord.iconSize > 80 ? mapCoord.iconSize - 80 : mapCoord.iconSize;
GL11.glPushMatrix();
GL11.glTranslatef(
(float) var15 + (float) mapCoord.centerX / 2.0F + 64.0F,
Expand All @@ -189,10 +190,10 @@ public void renderMap(EntityPlayer par1EntityPlayer, TextureManager par2TextureM
GL11.glRotatef((float) (mapCoord.iconRotation * 360) / 16.0F, 0.0F, 0.0F, 1.0F);
GL11.glScalef(4.0F, 4.0F, 3.0F);
GL11.glTranslatef(-0.125F, 0.125F, 0.0F);
float var21 = (float) (mapCoord.iconSize % 8 + 0) / 8.0F;
float var23 = (float) (mapCoord.iconSize / 8 + 0) / 8.0F;
float var22 = (float) (mapCoord.iconSize % 8 + 1) / 8.0F;
float var24 = (float) (mapCoord.iconSize / 8 + 1) / 8.0F;
float var21 = (float) (size % 8 + 0) / 8.0F;
float var23 = (float) (size / 8 + 0) / 8.0F;
float var22 = (float) (size % 8 + 1) / 8.0F;
float var24 = (float) (size / 8 + 1) / 8.0F;
tesselator.startDrawingQuads();
tesselator.addVertexWithUV(-1.0D, 1.0D, 0.0D, var21, var23);
tesselator.addVertexWithUV(1.0D, 1.0D, 0.0D, var22, var23);
Expand All @@ -202,11 +203,30 @@ public void renderMap(EntityPlayer par1EntityPlayer, TextureManager par2TextureM
GL11.glPopMatrix();
}

// GL11.glPushMatrix();
// GL11.glTranslatef(0.0F, 0.0F, -0.04F);
// GL11.glScalef(1.0F, 1.0F, 1.0F);
// this.fontRenderer.drawString(par3MapData.mapName, var15, var16, -16777216);
// GL11.glPopMatrix();
par2TextureManager.bindTexture(vanillaMapIcons);
for (MapCoord mapCoord : magicMapData.featuresVisibleOnMap) {
if (mapCoord.iconSize > 80) {
GL11.glPushMatrix();
GL11.glTranslatef(
(float) var15 + (float) mapCoord.centerX / 2.0F + 64.0F,
(float) var16 + (float) mapCoord.centerZ / 2.0F + 64.0F,
-0.02F);
GL11.glRotatef((float) (mapCoord.iconRotation * 360) / 16.0F, 0.0F, 0.0F, 1.0F);
GL11.glScalef(4.0F, 4.0F, 3.0F);
GL11.glTranslatef(-0.125F, 0.125F, 0.0F);
float var21 = (float) (4 % 4 + 0) / 4.0F;
float var23 = (float) (4 / 4 + 0) / 4.0F;
float var22 = (float) (4 % 4 + 1) / 4.0F;
float var24 = (float) (4 / 4 + 1) / 4.0F;
tesselator.startDrawingQuads();
tesselator.addVertexWithUV(-1.0D, 0D, 0.0D, var21, var23);
tesselator.addVertexWithUV(0D, 0D, 0.0D, var22, var23);
tesselator.addVertexWithUV(0D, -1.0D, 0.0D, var22, var24);
tesselator.addVertexWithUV(-1.0D, -1.0D, 0.0D, var21, var24);
tesselator.draw();
GL11.glPopMatrix();
}
}
}

private void renderMapInFrame(ItemStack item, RenderManager renderManager, TFMagicMapData mapData) {
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/twilightforest/item/ItemTFMagicMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import twilightforest.TFMapPacketHandler;
import twilightforest.TwilightForestMod;
import twilightforest.biomes.TFBiomeBase;
import twilightforest.world.ChunkProviderTwilightForest;
import twilightforest.world.TFWorldChunkManager;
import twilightforest.world.WorldProviderTwilightForest;

public class ItemTFMagicMap extends ItemMap {

Expand Down Expand Up @@ -65,6 +67,8 @@ public TFMagicMapData getMapData(ItemStack itemStack, World world) {

public void updateMapData(World world, Entity entity, TFMagicMapData mapData) {
if (world.provider.dimensionId == mapData.dimension && entity instanceof EntityPlayer) {
ChunkProviderTwilightForest chunkProvider = ((WorldProviderTwilightForest) world.provider)
.getChunkProvider();
short xSize = 128;
short zSize = 128;
int scaleFactor = 1 << mapData.scale;
Expand Down Expand Up @@ -119,26 +123,16 @@ public void updateMapData(World world, Entity entity, TFMagicMapData mapData) {
(zDraw2 + zStep2) >> 4,
world),
xDraw2,
zDraw2);
zDraw2,
chunkProvider
.isStructureConquered(xDraw2 + xStep2, 0, zDraw2 + zStep2));
}
}

// // mark features we find into the mapdata, provided they are within our draw area
// if (biomeID == TFBiomeBase.majorFeature.biomeID && zStep >= 0 && xOffset *
// xOffset + zOffset * zOffset < drawSize * drawSize) {
// par3MapData.addFeatureToMap(TFFeature.getNearestFeature((xDraw2 + xStep2) >> 4,
// (zDraw2 + zStep2) >> 4, par1World), xDraw2, zDraw2);
//// biomeFrequencies[biomeID] += 4096; // don't bother, now the icon will show
// }

// // mark features we find into the mapdata, provided they are within our draw area
// if (biomeID == TFBiomeBase.minorFeature.biomeID) {
// biomeFrequencies[biomeID] += 4096; // don't bother, now the icon will show
// }
}
}

// figure out which color is the most prominent and make that one appear on the map
// figure out which color is the most prominent and make that one appear on the
// map
byte biomeIDToShow = 0;
int highestFrequency = 0;

Expand Down

0 comments on commit 42c1539

Please sign in to comment.