Skip to content

Commit b21c35b

Browse files
feat: it compiles but there is a long way until correct map rendering
1 parent 6a50a69 commit b21c35b

File tree

9 files changed

+239
-193
lines changed

9 files changed

+239
-193
lines changed

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -381,31 +381,31 @@ public EventResult checkSpawn(LivingEntity entity, LevelAccessor levelAccessor,
381381
return EventResult.pass();
382382
}
383383

384-
private boolean ignoreExplosion(Level level, Explosion explosion) {
385-
if (level.isClientSide() || explosion.getToBlow().isEmpty()) {
386-
return true;
387-
}
388-
389-
return explosion.source == null && !FTBChunksWorldConfig.PROTECT_UNKNOWN_EXPLOSIONS.get();
390-
}
384+
// private boolean ignoreExplosion(Level level, Explosion explosion) {
385+
// if (level.isClientSide() || explosion.getToBlow().isEmpty()) {
386+
// return true;
387+
// }
388+
//
389+
// return explosion.source == null && !FTBChunksWorldConfig.PROTECT_UNKNOWN_EXPLOSIONS.get();
390+
// }
391391

392392
public void explosionDetonate(Level level, Explosion explosion, List<Entity> affectedEntities) {
393-
if (FTBChunksWorldConfig.DISABLE_PROTECTION.get() || ignoreExplosion(level, explosion)) {
394-
return;
395-
}
396-
397-
List<BlockPos> list = new ArrayList<>(explosion.getToBlow());
398-
explosion.clearToBlow();
399-
Map<ChunkDimPos, Boolean> map = new HashMap<>();
400-
401-
for (BlockPos pos : list) {
402-
if (map.computeIfAbsent(new ChunkDimPos(level, pos), cpos -> {
403-
ClaimedChunkImpl chunk = ClaimedChunkManagerImpl.getInstance().getChunk(cpos);
404-
return chunk == null || chunk.allowExplosions();
405-
})) {
406-
explosion.getToBlow().add(pos);
407-
}
408-
}
393+
// if (FTBChunksWorldConfig.DISABLE_PROTECTION.get() || ignoreExplosion(level, explosion)) {
394+
// return;
395+
// }
396+
//
397+
// List<BlockPos> list = new ArrayList<>(explosion.getToBlow());
398+
// explosion.clearToBlow();
399+
// Map<ChunkDimPos, Boolean> map = new HashMap<>();
400+
//
401+
// for (BlockPos pos : list) {
402+
// if (map.computeIfAbsent(new ChunkDimPos(level, pos), cpos -> {
403+
// ClaimedChunkImpl chunk = ClaimedChunkManagerImpl.getInstance().getChunk(cpos);
404+
// return chunk == null || chunk.allowExplosions();
405+
// })) {
406+
// explosion.getToBlow().add(pos);
407+
// }
408+
// }
409409
}
410410

411411
private void playerCloned(ServerPlayer oldPlayer, ServerPlayer newPlayer, boolean wonGame) {

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

Lines changed: 159 additions & 119 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import net.minecraft.client.gui.GuiGraphics;
3737
import net.minecraft.client.gui.screens.Screen;
3838
import net.minecraft.client.player.LocalPlayer;
39+
import net.minecraft.client.renderer.RenderPipelines;
3940
import net.minecraft.commands.Commands;
4041
import net.minecraft.network.chat.Component;
4142
import net.minecraft.world.entity.player.Player;
@@ -181,7 +182,9 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int
181182

182183
// TODO: [21.8] Validate this still works
183184
// - Blocked by dynamic image generation.
184-
graphics.blit(FTBChunksClient.INSTANCE.getMinimapTextureId(), sx, sy, 0, 0, maxWidth, maxHeight, maxWidth, maxHeight);
185+
graphics.submitBlit(RenderPipelines.GUI_TEXTURED, FTBChunksClient.INSTANCE.dynamicTexture().getTextureView(),
186+
sx, sy, 0, 0, maxWidth, maxHeight, maxWidth, maxHeight, 0xFFFFFFFF);
187+
// graphics.blit(FTBChunksClient.INSTANCE.getMinimapTextureId(), sx, sy, 0, 0, maxWidth, maxHeight, maxWidth, maxHeight);
185188
// RenderSystem.setShaderTexture(0, FTBChunksClient.INSTANCE.getMinimapTextureId());
186189
// GuiHelper.drawTexturedRect(graphics, sx, sy, maxWidth, maxHeight, Color4I.WHITE, 0F, 0F, 1F, 1F);
187190

common/src/main/java/dev/ftb/mods/ftbchunks/data/ClaimedChunkManagerImpl.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,21 @@ public void initForceLoadedChunks(ServerLevel level) {
107107
FTBChunks.LOGGER.info("Force-loaded %d chunks in %s".formatted(map.size(), level.dimension().location()));
108108
}
109109

110-
private ChunkTeamDataImpl loadTeamData(Team team) throws IOException {
110+
private ChunkTeamDataImpl loadTeamData(Team team) {
111111
Path path = dataDirectory.resolve(team.getId() + ".snbt");
112112
ChunkTeamDataImpl data = new ChunkTeamDataImpl(this, path, team);
113-
CompoundTag dataFile = SNBT.tryRead(path);
114113

115-
if (dataFile != null) {
116-
data.deserializeNBT(dataFile);
117-
teamData.put(team.getId(), data);
118-
return data;
119-
}
114+
try {
115+
CompoundTag dataFile = SNBT.tryRead(path);
116+
117+
if (dataFile != null) {
118+
data.deserializeNBT(dataFile);
119+
teamData.put(team.getId(), data);
120+
return data;
121+
}
122+
} catch (Exception ex) {
123+
FTBChunks.LOGGER.error("Failed to load data for team {}: {}", team.getId(), ex.getMessage());
124+
}
120125

121126
return data;
122127
}
@@ -129,12 +134,8 @@ public MinecraftServer getMinecraftServer() {
129134
public ChunkTeamDataImpl getOrCreateData(@NotNull Team team) {
130135
ChunkTeamDataImpl data = teamData.get(team.getId());
131136
if (data == null) {
132-
try {
133-
data = loadTeamData(team);
134-
teamData.put(team.getId(), data);
135-
} catch (IOException ex) {
136-
FTBChunks.LOGGER.error("Failed to load data for team {}: {}", team.getId(), ex.getMessage());
137-
}
137+
data = loadTeamData(team);
138+
teamData.put(team.getId(), data);
138139
}
139140

140141
return data;

common/src/main/resources/ftbchunks.accesswidener

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ accessible field net/minecraft/network/protocol/game/ClientboundSectionBlocksUpd
1010
accessible field net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket positions [S
1111
accessible field net/minecraft/world/level/Explosion source Lnet/minecraft/world/entity/Entity;
1212

13-
accessible class net/minecraft/client/renderer/texture/SimpleTexture$TextureImage
13+
accessible method net/minecraft/client/gui/GuiGraphics submitBlit (Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lcom/mojang/blaze3d/textures/GpuTextureView;IIIIFFFFI)V
14+
extendable class net/minecraft/nbt/CompoundTag

fabric/src/generated/resources/ftbchunks.accesswidener

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ accessible field net/minecraft/network/protocol/game/ClientboundSectionBlocksUpd
1010
accessible field net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket positions [S
1111
accessible field net/minecraft/world/level/Explosion source Lnet/minecraft/world/entity/Entity;
1212

13-
accessible class net/minecraft/client/renderer/texture/SimpleTexture$TextureImage
13+
accessible method net/minecraft/client/gui/GuiGraphics submitBlit (Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lcom/mojang/blaze3d/textures/GpuTextureView;IIIIFFFFI)V
14+
extendable class net/minecraft/nbt/CompoundTag

fabric/src/main/java/dev/ftb/mods/ftbchunks/fabric/FTBChunksExpectedImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ public static void addChunkToForceLoaded(ServerLevel level, String modId, UUID o
1515
ChunkPos chunkPos = new ChunkPos(chunkX, chunkY);
1616
level.setChunkForced(chunkX, chunkY, add);
1717
FTBChunks.LOGGER.debug("set force-loading for chunk ({},{}) = {}", chunkX, chunkY, add);
18-
if (add) {
19-
level.getChunkSource().addRegionTicket(TicketType.FORCED, chunkPos, 2, chunkPos);
20-
} else {
21-
level.getChunkSource().removeRegionTicket(TicketType.FORCED, chunkPos, 2, chunkPos);
22-
}
18+
// TODO: [21.8] Re-add this
19+
// if (add) {
20+
// level.getChunkSource().addRegionTicket(TicketType.FORCED, chunkPos, 2, chunkPos);
21+
// } else {
22+
// level.getChunkSource().removeRegionTicket(TicketType.FORCED, chunkPos, 2, chunkPos);
23+
// }
2324
}
2425

2526
public static void getPlatformSpecificProperties(TeamCollectPropertiesEvent event) {

neoforge/src/main/java/dev/ftb/mods/ftbchunks/client/neoforge/FTBChunksClientImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ public static void registerPlatform() {
1313
}
1414

1515
@SubscribeEvent
16-
public static void renderLevelStageForge(RenderLevelStageEvent event) {
17-
if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_PARTICLES) {
18-
FTBChunksClient.INSTANCE.renderWorldLast(event.getPoseStack(), event.getProjectionMatrix(),
19-
event.getModelViewMatrix(), event.getCamera(), event.getPartialTick());
20-
}
16+
public static void renderLevelStageForge(RenderLevelStageEvent.AfterParticles event) {
17+
FTBChunksClient.INSTANCE.renderWorldLast(event.getPoseStack(), event.getModelViewMatrix(),
18+
event.getModelViewMatrix(), event.getCamera(), event.getPartialTick());
2119
}
2220

2321
public static boolean doesKeybindMatch(KeyMapping keyMapping, int keyCode, int scanCode, int modifiers) {

neoforge/src/main/java/dev/ftb/mods/ftbchunks/neoforge/ForceLoading.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,31 @@ private static void registerTicketController(RegisterTicketControllersEvent even
3131
private static void validateLoadedChunks(ServerLevel level, TicketHelper ticketHelper) {
3232
FTBChunks.LOGGER.debug("validating chunk tickets for level {}", level.dimension().location());
3333

34-
ticketHelper.getEntityTickets().forEach((id, chunks) -> {
35-
FTBChunks.LOGGER.debug("validating {} ticking chunk tickets for {}", chunks.ticking().size(), id);
36-
37-
// non-ticking tickets - shouldn't have any of these; purge just in case (older releases of Chunks registered them)
38-
Set<Long> toRemoveNon = new HashSet<>(chunks.nonTicking());
39-
if (!toRemoveNon.isEmpty()) {
40-
toRemoveNon.forEach(l -> ticketHelper.removeTicket(id, l, false));
41-
FTBChunks.LOGGER.info("purged {} non-ticking Forge chunkloading tickets for team ID {} in dimension {}",
42-
toRemoveNon.size(), id, level.dimension().location());
43-
}
44-
45-
// ticking tickets - purge if the chunk is either unclaimed or should not be offline-force-loaded
46-
Set<Long> toRemove = new HashSet<>();
47-
chunks.ticking().forEach(l -> {
48-
ClaimedChunkImpl cc = ClaimedChunkManagerImpl.getInstance().getChunk(new ChunkDimPos(level.dimension(), new ChunkPos(l)));
49-
if (cc == null || !cc.getTeamData().getTeamId().equals(id) || !cc.isActuallyForceLoaded()) {
50-
toRemove.add(l);
51-
}
52-
});
53-
if (!toRemove.isEmpty()) {
54-
toRemove.forEach(l -> ticketHelper.removeTicket(id, l, true));
55-
FTBChunks.LOGGER.info("cleaned up {} stale ticking Forge chunkloading tickets for team ID {} in dimension {}",
56-
toRemove.size(), id, level.dimension().location());
57-
}
58-
});
34+
// TODO: [21.8] Add all of this back.
35+
// ticketHelper.getEntityTickets().forEach((id, chunks) -> {
36+
// FTBChunks.LOGGER.debug("validating {} ticking chunk tickets for {}", chunks.ticking().size(), id);
37+
//
38+
// // non-ticking tickets - shouldn't have any of these; purge just in case (older releases of Chunks registered them)
39+
// Set<Long> toRemoveNon = new HashSet<>(chunks.nonTicking());
40+
// if (!toRemoveNon.isEmpty()) {
41+
// toRemoveNon.forEach(l -> ticketHelper.removeTicket(id, l, false));
42+
// FTBChunks.LOGGER.info("purged {} non-ticking Forge chunkloading tickets for team ID {} in dimension {}",
43+
// toRemoveNon.size(), id, level.dimension().location());
44+
// }
45+
//
46+
// // ticking tickets - purge if the chunk is either unclaimed or should not be offline-force-loaded
47+
// Set<Long> toRemove = new HashSet<>();
48+
// chunks.ticking().forEach(l -> {
49+
// ClaimedChunkImpl cc = ClaimedChunkManagerImpl.getInstance().getChunk(new ChunkDimPos(level.dimension(), new ChunkPos(l)));
50+
// if (cc == null || !cc.getTeamData().getTeamId().equals(id) || !cc.isActuallyForceLoaded()) {
51+
// toRemove.add(l);
52+
// }
53+
// });
54+
// if (!toRemove.isEmpty()) {
55+
// toRemove.forEach(l -> ticketHelper.removeTicket(id, l, true));
56+
// FTBChunks.LOGGER.info("cleaned up {} stale ticking Forge chunkloading tickets for team ID {} in dimension {}",
57+
// toRemove.size(), id, level.dimension().location());
58+
// }
59+
// });
5960
}
6061
}

0 commit comments

Comments
 (0)