Skip to content

Commit 8b7c474

Browse files
fix: most of the main render components are back... Most. Masking looks to need a shader 😢
1 parent c4f552c commit 8b7c474

File tree

6 files changed

+207
-118
lines changed

6 files changed

+207
-118
lines changed

common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunks.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class FTBChunks {
7070
public static final int TILE_SIZE = 16;
7171
public static final int TILE_OFFSET = TILES / 2;
7272
public static final int MINIMAP_SIZE = TILE_SIZE * TILES;
73+
7374
public static final XZ[] RELATIVE_SPIRAL_POSITIONS = new XZ[TILES * TILES];
7475

7576
public static final Registrar<Block> BLOCK_REGISTRY = RegistrarManager.get(MOD_ID).get(Registries.BLOCK);

common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClient.java

Lines changed: 93 additions & 111 deletions
Large diffs are not rendered by default.

common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/EntityIconSettingsScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public RowPanel(Panel panel, EntityType<?> entityType) {
6969

7070
@Override
7171
public void addWidgets() {
72-
boolean hiddenState = FTBChunksClientConfig.ENTITY_ICON.get().getOrDefault(resourceKey.toString(), true);
72+
boolean hiddenState = FTBChunksClientConfig.ENTITY_ICON.get().getOrDefault(resourceKey.identifier().toString(), true);
7373
add(hideButton = new ToggleableButton(this, hiddenState, Icons.ACCEPT, Icons.ACCEPT_GRAY, (hideButton, hidden) -> {
74-
FTBChunksClientConfig.ENTITY_ICON.get().put(resourceKey.toString(), hidden);
74+
FTBChunksClientConfig.ENTITY_ICON.get().put(resourceKey.identifier().toString(), hidden);
7575
FTBChunksClientConfig.saveConfig();
7676
}));
7777

common/src/main/java/dev/ftb/mods/ftbchunks/client/map/MapRegionTexture.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@ public void requestBake() {
5252
}
5353

5454
private void upload(NativeImage image) {
55-
this.texture = new DynamicTexture(identifier::toString, image);
56-
Minecraft.getInstance().getTextureManager().register(identifier, this.texture);
55+
if (this.texture == null) {
56+
// First time - create texture
57+
this.texture = new DynamicTexture(identifier::toString, image);
58+
Minecraft.getInstance().getTextureManager().register(identifier, this.texture);
59+
} else {
60+
// Subsequent times - just update pixels and upload
61+
this.texture.setPixels(image);
62+
this.texture.upload();
63+
}
5764
}
5865

5966
public void close() {
@@ -77,4 +84,8 @@ public boolean isBaking() {
7784
public boolean isOpen() {
7885
return texture != null;
7986
}
87+
88+
public @Nullable DynamicTexture bakedTexture() {
89+
return texture;
90+
}
8091
}

common/src/main/java/dev/ftb/mods/ftbchunks/client/mapicon/EntityIconUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public static boolean shouldEntityRender(Entity entity, Player player) {
2525
}
2626

2727
private static boolean isIconEnabled(ResourceKey<EntityType<?>> key, EntityType<?> type) {
28-
if (!FTBChunksClientConfig.ENTITY_ICON.get().containsKey(key.toString())) {
28+
if (!FTBChunksClientConfig.ENTITY_ICON.get().containsKey(key.identifier().toString())) {
2929
// entity not listed in the config (most likely a new mod was added) - get its defaults if possible
3030
EntityIconSettings settings = EntityIconLoader.getSettings(type).orElse(EntityIconSettings.legacy());
31-
FTBChunksClientConfig.ENTITY_ICON.get().put(key.toString(), settings.defaultEnabled());
31+
FTBChunksClientConfig.ENTITY_ICON.get().put(key.identifier().toString(), settings.defaultEnabled());
3232
FTBChunksClientConfig.saveConfig();
3333
return settings.defaultEnabled();
3434
} else {
35-
return FTBChunksClientConfig.ENTITY_ICON.get().get(key.toString());
35+
return FTBChunksClientConfig.ENTITY_ICON.get().get(key.identifier().toString());
3636
}
3737
}
3838
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package dev.ftb.mods.ftbchunks.client.minimap;
2+
3+
import dev.ftb.mods.ftbchunks.FTBChunks;
4+
import dev.ftb.mods.ftbchunks.api.FTBChunksAPI;
5+
import dev.ftb.mods.ftbchunks.client.map.MapDimension;
6+
import dev.ftb.mods.ftbchunks.client.map.MapRegion;
7+
import dev.ftb.mods.ftblibrary.math.XZ;
8+
import com.mojang.blaze3d.platform.NativeImage;
9+
import net.minecraft.client.Minecraft;
10+
import net.minecraft.client.renderer.texture.DynamicTexture;
11+
import net.minecraft.resources.Identifier;
12+
import net.minecraft.resources.ResourceKey;
13+
import net.minecraft.world.level.Level;
14+
15+
import java.util.function.Supplier;
16+
17+
public class MinimapRegionCutoutTexture {
18+
private final Identifier identifier = FTBChunksAPI.id("minimap_region_cutout_texture");
19+
private final NativeImage image;
20+
21+
private final DynamicTexture texture;
22+
23+
private int lastChunkX;
24+
private int lastChunkZ;
25+
26+
public MinimapRegionCutoutTexture() {
27+
var size = FTBChunks.MINIMAP_SIZE;
28+
29+
// Reserve the texture.
30+
image = new NativeImage(NativeImage.Format.RGBA, size, size, true);
31+
image.fillRect(0, 0, size, size, 0);
32+
33+
texture = new DynamicTexture(identifier::toString, image);
34+
Minecraft.getInstance().getTextureManager().register(identifier, texture);
35+
}
36+
37+
public void update(ResourceKey<Level> key, int chunkX, int chunkZ) {
38+
if (chunkX == lastChunkX && chunkZ == lastChunkZ) {
39+
return;
40+
}
41+
42+
// Update the last chunk positions.
43+
lastChunkX = chunkX;
44+
lastChunkZ = chunkZ;
45+
46+
MapDimension dim = MapDimension.getCurrent().get();
47+
if (dim.dimension != key) {
48+
return;
49+
}
50+
51+
var size = FTBChunks.MINIMAP_SIZE;
52+
53+
image.fillRect(0, 0, size, size, 0);
54+
55+
// Time to update.
56+
for (int mz = 0; mz < FTBChunks.TILES; mz++) {
57+
for (int mx = 0; mx < FTBChunks.TILES; mx++) {
58+
int ox = chunkX + mx - FTBChunks.TILE_OFFSET;
59+
int oz = chunkZ + mz - FTBChunks.TILE_OFFSET;
60+
61+
MapRegion region = dim.getRegion(XZ.regionFromChunk(ox, oz));
62+
DynamicTexture dynamicTexture = region.regionTexture().bakedTexture();
63+
if (dynamicTexture == null) {
64+
continue;
65+
}
66+
67+
NativeImage regionImage = dynamicTexture.getPixels();
68+
if (regionImage == null) {
69+
continue;
70+
}
71+
72+
int imgSize = regionImage.getWidth();
73+
int chunksPerRegion = imgSize / 16;
74+
75+
int srcX = (ox & (chunksPerRegion - 1)) * 16;
76+
int srcZ = (oz & (chunksPerRegion - 1)) * 16;
77+
78+
int dstX = mx * 16;
79+
int dstZ = mz * 16;
80+
81+
regionImage.copyRect(image, srcX, srcZ, dstX, dstZ, 16, 16, false, false);
82+
}
83+
}
84+
85+
texture.upload();
86+
}
87+
88+
public DynamicTexture getTexture() {
89+
return texture;
90+
}
91+
92+
public Identifier identifier() {
93+
return identifier;
94+
}
95+
}

0 commit comments

Comments
 (0)