97 lines
3 KiB
Java
97 lines
3 KiB
Java
package net.minecraft.client.gui.screens;
|
|
|
|
import java.util.function.BooleanSupplier;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.Util;
|
|
import net.minecraft.client.GameNarrator;
|
|
import net.minecraft.client.gui.GuiGraphics;
|
|
import net.minecraft.client.renderer.RenderType;
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class ReceivingLevelScreen extends Screen {
|
|
private static final Component DOWNLOADING_TERRAIN_TEXT = Component.translatable("multiplayer.downloadingTerrain");
|
|
private static final long CHUNK_LOADING_START_WAIT_LIMIT_MS = 30000L;
|
|
private final long createdAt;
|
|
private final BooleanSupplier levelReceived;
|
|
private final ReceivingLevelScreen.Reason reason;
|
|
@Nullable
|
|
private TextureAtlasSprite cachedNetherPortalSprite;
|
|
|
|
public ReceivingLevelScreen(BooleanSupplier levelReceived, ReceivingLevelScreen.Reason reason) {
|
|
super(GameNarrator.NO_TITLE);
|
|
this.levelReceived = levelReceived;
|
|
this.reason = reason;
|
|
this.createdAt = Util.getMillis();
|
|
}
|
|
|
|
@Override
|
|
public boolean shouldCloseOnEsc() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
protected boolean shouldNarrateNavigation() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
|
super.render(guiGraphics, mouseX, mouseY, partialTick);
|
|
guiGraphics.drawCenteredString(this.font, DOWNLOADING_TERRAIN_TEXT, this.width / 2, this.height / 2 - 50, -1);
|
|
}
|
|
|
|
@Override
|
|
public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
|
switch (this.reason) {
|
|
case NETHER_PORTAL:
|
|
guiGraphics.blitSprite(RenderType::guiOpaqueTexturedBackground, this.getNetherPortalSprite(), 0, 0, guiGraphics.guiWidth(), guiGraphics.guiHeight());
|
|
break;
|
|
case END_PORTAL:
|
|
guiGraphics.fillRenderType(RenderType.endPortal(), 0, 0, this.width, this.height, 0);
|
|
break;
|
|
case OTHER:
|
|
this.renderPanorama(guiGraphics, partialTick);
|
|
this.renderBlurredBackground();
|
|
this.renderMenuBackground(guiGraphics);
|
|
}
|
|
}
|
|
|
|
private TextureAtlasSprite getNetherPortalSprite() {
|
|
if (this.cachedNetherPortalSprite != null) {
|
|
return this.cachedNetherPortalSprite;
|
|
} else {
|
|
this.cachedNetherPortalSprite = this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.NETHER_PORTAL.defaultBlockState());
|
|
return this.cachedNetherPortalSprite;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void tick() {
|
|
if (this.levelReceived.getAsBoolean() || Util.getMillis() > this.createdAt + 30000L) {
|
|
this.onClose();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onClose() {
|
|
this.minecraft.getNarrator().sayNow(Component.translatable("narrator.ready_to_play"));
|
|
super.onClose();
|
|
}
|
|
|
|
@Override
|
|
public boolean isPauseScreen() {
|
|
return false;
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public static enum Reason {
|
|
NETHER_PORTAL,
|
|
END_PORTAL,
|
|
OTHER;
|
|
}
|
|
}
|