Skip to content

Commit

Permalink
Update from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
senseiwells committed Oct 24, 2024
1 parent b5903cf commit 750365d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 231 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[versions]
minecraft = "1.21.2-pre5"
fabric-loom = "1.7-SNAPSHOT"
minecraft = "1.21.3"
fabric-loom = "1.8-SNAPSHOT"
fabric-loader = "0.16.7"
fabric-api = "0.106.0+1.21.2"
fabric-api = "0.106.1+1.21.3"
permissions = "0.3.1"
mod-publish = "0.7.0"
parchment = "1.21:2024.07.28"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.Ticket;
import net.minecraft.util.FastColor;
import net.minecraft.util.ARGB;
import net.minecraft.util.Mth;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -165,26 +165,23 @@ public void renderMinimap(GuiGraphics graphics) {
graphics.pose().popPose();
}

@SuppressWarnings("deprecation")
void renderMap(GuiGraphics graphics, DimensionState state) {
graphics.drawManaged(() -> {
for (ChunkData data : state.chunks.values()) {
for (ChunkData data : state.chunks.values()) {
ChunkPos pos = data.position();
int color = this.calculateChunkColor(data);
graphics.fill(pos.x, pos.z, pos.x + 1, pos.z + 1, color);
}

if (this.config.chunkRetention > 0) {
for (Map.Entry<Integer, ChunkData> entry : state.unloaded.entries()) {
float delta = (float) (entry.getKey() - this.ticks) / this.config.chunkRetention;
int alpha = ((byte) (delta * 255)) << 24 | 0xFFFFFF;
ChunkData data = entry.getValue();
ChunkPos pos = data.position();
int color = this.calculateChunkColor(data);
int color = this.calculateChunkColor(data) & alpha;
graphics.fill(pos.x, pos.z, pos.x + 1, pos.z + 1, color);
}

if (this.config.chunkRetention > 0) {
for (Map.Entry<Integer, ChunkData> entry : state.unloaded.entries()) {
float delta = (float) (entry.getKey() - this.ticks) / this.config.chunkRetention;
int alpha = ((byte) (delta * 255)) << 24 | 0xFFFFFF;
ChunkData data = entry.getValue();
ChunkPos pos = data.position();
int color = this.calculateChunkColor(data) & alpha;
graphics.fill(pos.x, pos.z, pos.x + 1, pos.z + 1, color);
}
}
});
}

if (state.selection != null) {
this.renderChunkSelection(graphics, state.selection, SELECTED_OUTLINE_COLOR);
Expand Down Expand Up @@ -379,7 +376,7 @@ private int calculateChunkColor(ChunkData data) {
List<Ticket<?>> tickets = this.client.config.showTickets ? data.tickets() : List.of();
int color = ChunkColors.calculateChunkColor(data.status(), stage, tickets, data.unloading());
if ((pos.x + pos.z) % 2 == 0) {
color = FastColor.ARGB32.lerp(0.12F, color, 0xFFFFFF);
color = ARGB.lerp(0.12F, color, 0xFFFFFF);
}
return color | 0xFF000000;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.Ticket;
import net.minecraft.util.ARGB;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -433,210 +430,4 @@ private int renderInnerChunkSelectionInfo(
}
return maxY - padding;
}

private void renderChunkSelection(GuiGraphics graphics, ChunkSelection selection, int color) {
this.renderChunkSelection(graphics, selection, 0.3F, color);
}

private void renderChunkSelection(GuiGraphics graphics, ChunkSelection selection, float thickness, int color) {
outline(graphics, selection.minX, selection.minZ, selection.sizeX(), selection.sizeZ(), thickness, color);
}

private void renderPlayer(GuiGraphics graphics, ChunkPos pos) {
outline(graphics, pos.x, pos.z, 1, 1, 0.3F, PLAYER_COLOR);
}

private DimensionState state() {
return this.state(this.dimension());
}

private DimensionState state(ResourceKey<Level> dimension) {
return this.states.computeIfAbsent(dimension, dim -> {
DimensionState state = new DimensionState(dim, this.executor);
this.initializeState(state);
return state;
});
}

private void jumpToCluster(int offset) {
DimensionState state = this.state();
state.getCluster(this.clusterIndex + offset).thenApplyAsync(pair -> {
ChunkSelection selection = pair.first();
this.clusterIndex = pair.secondInt();
this.setMapCenter(selection.getCenterChunkPos());
this.clusterSelection = selection;
this.clusterTicks = 20;
return null;
}, this.minecraft);
}

private void loadDimensions() {
Minecraft minecraft = Minecraft.getInstance();
if (minecraft.getConnection() != null) {
Set<ResourceKey<Level>> dimensions = minecraft.getConnection().levels();
Set<ResourceKey<Level>> sorted = new LinkedHashSet<>();
if (dimensions.contains(Level.OVERWORLD)) {
sorted.add(Level.OVERWORLD);
}
if (dimensions.contains(Level.NETHER)) {
sorted.add(Level.NETHER);
}
if (dimensions.contains(Level.END)) {
sorted.add(Level.END);
}
sorted.addAll(dimensions);
this.dimensions.addAll(sorted);
} else {
this.dimensions.add(Level.OVERWORLD);
this.dimensions.add(Level.NETHER);
this.dimensions.add(Level.END);
}
int width = this.dimensions.stream().mapToInt(key -> {
return minecraft.font.width(key.location().toString());
}).max().orElse(10);
this.dimensionWidth = Math.min(width, 140);

LocalPlayer player = Minecraft.getInstance().player;
if (player != null) {
this.dimensionIndex = this.dimensions.indexOf(player.level().dimension());
}
}

private void initializeState(DimensionState state) {
if (!this.isWatching(state.dimension)) {
ChunkDebugClient.getInstance().startWatching(state.dimension);
}
if (!state.initialized) {
ChunkPos center = ChunkPos.ZERO;
if (this.minecraft != null) {
LocalPlayer player = this.minecraft.player;
if (player != null && player.level().dimension() == state.dimension) {
center = player.chunkPosition();
}
}
state.offsetX = (this.width / 2.0) - center.x * state.scale;
state.offsetY = (this.height / 2.0) - center.z * state.scale;
state.initialized = true;
}
}

private void setMapCenter(ChunkPos pos) {
this.setMapCenter(pos.x, pos.z);
}

private void setMapCenter(int x, int z) {
DimensionState state = this.state();
state.offsetX = (this.width / 2.0) - x * state.scale;
state.offsetY = (this.height / 2.0) - z * state.scale;
}

private ChunkPos convertScreenToChunkPos(double x, double y) {
DimensionState state = this.state();
double scaledX = (x - state.offsetX) / state.scale;
double scaledY = (y - state.offsetY) / state.scale;
return new ChunkPos(Mth.floor(scaledX), Mth.floor(scaledY));
}

private void incrementDimension(int increment) {
this.dimensionIndex = (this.dimensionIndex + increment + this.dimensions.size()) % this.dimensions.size();
}

private ResourceKey<Level> dimension() {
if (this.dimensions.isEmpty()) {
this.loadDimensions();
}
return this.dimensions.get(this.dimensionIndex);
}

private boolean isWatching(ResourceKey<Level> dimension) {
return this.states.containsKey(dimension);
}

private int calculateChunkColor(ChunkData data) {
ChunkPos pos = data.position();
ChunkStatus stage = this.showStages.isToggled() ? data.stage() : null;
List<Ticket<?>> tickets = this.showTickets.isToggled() ? data.tickets() : List.of();
int color = ChunkColors.calculateChunkColor(data.status(), stage, tickets, data.unloading());
if ((pos.x + pos.z) % 2 == 0) {
color = ARGB.lerp(0.12F, color, 0xFFFFFF);
}
return color | 0xFF000000;
}

private enum Minimap {
NONE, STATIC, FOLLOW;

public Minimap previous() {
return switch (this) {
case NONE -> FOLLOW;
case STATIC -> NONE;
case FOLLOW -> STATIC;
};
}

public Minimap next() {
return switch (this) {
case NONE -> STATIC;
case STATIC -> FOLLOW;
case FOLLOW -> NONE;
};
}

public Component pretty() {
return Component.translatable("chunk-debug.settings.minimap." + this.name().toLowerCase());
}
}

private static class DimensionState {

private final Multimap<Integer, ChunkData> unloaded = HashMultimap.create();

private final Long2ObjectMap<ChunkData> chunks = new Long2ObjectOpenHashMap<>();
private final ChunkClusters clusters = new ChunkClusters();
private final ResourceKey<Level> dimension;

private final Executor clusterWorker;

private ChunkSelection selection;
private ChunkPos first;

private float scale = 1.0F;

private double offsetX = 0.0;
private double offsetY = 0.0;

boolean initialized = false;

private DimensionState(ResourceKey<Level> dimension, Executor clusterWorker) {
this.dimension = dimension;
this.clusterWorker = clusterWorker;
}

void add(long pos, ChunkData data) {
this.chunks.put(pos, data);
this.clusterWorker.execute(() -> {
this.clusters.add(pos);
});
}

void remove(long pos, int tick) {
this.clusterWorker.execute(() -> {
this.clusters.remove(pos);
});
ChunkData data = this.chunks.remove(pos);
if (data != null) {
this.unloaded.put(tick, data);
data.updateUnloading(false);
}
}

CompletableFuture<ObjectIntPair<ChunkSelection>> getCluster(int index) {
return CompletableFuture.supplyAsync(() -> {
int corrected = (index + this.clusters.count()) % this.clusters.count();
LongSet cluster = this.clusters.getCluster(corrected);
List<ChunkPos> positions = cluster.longStream().mapToObj(ChunkPos::new).toList();
return ObjectIntPair.of(ChunkSelection.fromPositions(positions), corrected);
}, this.clusterWorker);
}
}
}

0 comments on commit 750365d

Please sign in to comment.