Skip to content

Commit

Permalink
Fix a couple minor bugs in Vistas for recent Minecraft.
Browse files Browse the repository at this point in the history
- Always select a Vista for the initial title screen.
- Don't crash when displaying the Vistas title.
  • Loading branch information
gniftygnome committed Aug 27, 2022
1 parent 6afab1e commit 9961f07
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Random;
import java.util.function.BiConsumer;

import com.terraformersmc.vistas.resource.PanoramaResourceReloader;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -63,17 +64,19 @@ protected TitleScreenMixin(Text title) {
super(title);
}

@Inject(method = "Lnet/minecraft/client/gui/screen/TitleScreen;<init>(Z)V", at = @At("TAIL"))
@Inject(method = "<init>(Z)V", at = @At("TAIL"))
private void vistas$init(boolean doBackgroundFade, CallbackInfo ci) {
this.backgroundRenderer = new BenignCubemapRenderer();
this.isVistas = new Random().nextDouble() < 1.0E-4D && VistasTitle.PANORAMAS_INVERT.get(VistasTitle.CURRENT.getValue()).equals(Vistas.DEFAULT);
this.isVistas = new Random().nextDouble() < 1.0E-4D && VistasTitle.CURRENT.getValue().equals(VistasTitle.PANORAMAS.get(Vistas.DEFAULT));
}

@Inject(method = "init", at = @At("HEAD"))
private void vistas$init(CallbackInfo ci) {
VistasTitle.choose();
if (PanoramaResourceReloader.isReady()) {
VistasTitle.choose();
}
if (!VistasConfig.getInstance().forcePanorama && VistasConfig.getInstance().randomPerScreen) {
this.isVistas = new Random().nextDouble() < 1.0E-4D && VistasTitle.PANORAMAS_INVERT.get(VistasTitle.CURRENT.getValue()).equals(Vistas.DEFAULT);
this.isVistas = new Random().nextDouble() < 1.0E-4D && VistasTitle.CURRENT.getValue().equals(VistasTitle.PANORAMAS.get(Vistas.DEFAULT));
this.splashText = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.mojang.serialization.Decoder;
import com.mojang.serialization.JsonOps;
import com.terraformersmc.vistas.Vistas;
import com.terraformersmc.vistas.config.VistasConfig;
import com.terraformersmc.vistas.panorama.Panorama;
import com.terraformersmc.vistas.title.VistasTitle;

Expand All @@ -38,6 +39,12 @@ public class PanoramaResourceReloader extends SinglePreparationResourceReloader<
private final ConcurrentMap<Identifier, Pair<List<String>, List<Identifier>>> parsedSplashWeb = Maps.newConcurrentMap();
private final ConcurrentMap<Identifier, List<String>> splashTexts = Maps.newConcurrentMap();

private static boolean ready = false;

public static boolean isReady() {
return ready;
}

@Override
protected HashMap<Identifier, Pair<Panorama, List<String>>> prepare(ResourceManager manager, Profiler profiler) {
profiler.startTick();
Expand Down Expand Up @@ -189,6 +196,7 @@ protected void iterateImports(Identifier panoramaId, List<Identifier> imports, L
@Override
protected void apply(HashMap<Identifier, Pair<Panorama, List<String>>> prepared, ResourceManager manager, Profiler profiler) {
profiler.startTick();
ready = false;

profiler.push("clear");
VistasTitle.clear();
Expand All @@ -209,8 +217,16 @@ protected void apply(HashMap<Identifier, Pair<Panorama, List<String>>> prepared,

profiler.pop();

VistasTitle.choose(profiler);
if (VistasConfig.getInstance().randomPerScreen || VistasConfig.getInstance().forcePanorama) {
VistasTitle.choose(profiler);
} else {
// We need to set a random panorama once at start-up and this is a decent proxy for that.
profiler.push("initialize");
VistasTitle.CURRENT.setValue(VistasTitle.getRandom());
profiler.pop();
}

ready = true;
profiler.endTick();
}

Expand Down

0 comments on commit 9961f07

Please sign in to comment.