-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Panorama Specific Splash Text - Internal improvements
- Loading branch information
Showing
10 changed files
with
233 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/main/java/com/terraformersmc/vistas/mixin/SplashTextResourceSupplierMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package com.terraformersmc.vistas.mixin; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.At.Shift; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.terraformersmc.vistas.Vistas; | ||
import com.terraformersmc.vistas.api.panorama.Panorama; | ||
import com.terraformersmc.vistas.api.panorama.Panoramas; | ||
import com.terraformersmc.vistas.resource.InvalidPanoramaException; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.resource.SplashTextResourceSupplier; | ||
import net.minecraft.client.util.Session; | ||
import net.minecraft.resource.Resource; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.profiler.Profiler; | ||
|
||
@Mixin(SplashTextResourceSupplier.class) | ||
public abstract class SplashTextResourceSupplierMixin { | ||
|
||
@Shadow | ||
@Final | ||
private static Identifier RESOURCE_ID; | ||
|
||
@Shadow | ||
@Final | ||
private Session field_18934; | ||
|
||
@Unique | ||
private List<String> storedSplashList = Lists.newArrayList(); | ||
|
||
@Unique | ||
private ArrayList<Panorama> THIS_PANORAMA = Lists.newArrayList(); | ||
|
||
@Unique | ||
private ArrayList<Panorama> READ_SPLASHES = Lists.newArrayList(); | ||
|
||
@Unique | ||
private boolean isUpFirst = true; | ||
|
||
@Unique | ||
private static final String panoramaRegex = "\\B\\$.*(\\$Splash)(\\n|$)"; | ||
|
||
@ModifyVariable(method = "Lnet/minecraft/client/resource/SplashTextResourceSupplier;prepare(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)Ljava/util/List;", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/resource/ResourceManager;getResource(Lnet/minecraft/util/Identifier;)Lnet/minecraft/resource/Resource;"), ordinal = 0) | ||
private Resource VISTAS_redirectSplashReading(Resource in) { | ||
if (isUpFirst) { | ||
THIS_PANORAMA.add(Panoramas.getCurrent()); | ||
} | ||
try { | ||
return MinecraftClient.getInstance().getResourceManager().getResource(THIS_PANORAMA.get(THIS_PANORAMA.size() - 1).getSplashTexts()); | ||
} catch (IOException var36) { | ||
return in; | ||
} | ||
} | ||
|
||
@ModifyVariable(method = "Lnet/minecraft/client/resource/SplashTextResourceSupplier;prepare(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)Ljava/util/List;", at = @At(value = "RETURN", ordinal = 0, shift = Shift.BEFORE), name = "var7") | ||
private List<String> VISTAS_setList(List<String> in) { | ||
this.storedSplashList = Lists.newArrayList((List<String>) in); | ||
return in; | ||
} | ||
|
||
@Inject(method = "Lnet/minecraft/client/resource/SplashTextResourceSupplier;prepare(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)Ljava/util/List;", at = @At(value = "RETURN", ordinal = 0, shift = Shift.BEFORE), cancellable = true) | ||
private void VISTAS_addOtherSplash(ResourceManager resourceManager, Profiler profiler, CallbackInfoReturnable<List<String>> ci) { | ||
isUpFirst = false; | ||
VISTAS_addOtherSplash(resourceManager, profiler, ci, THIS_PANORAMA.get(THIS_PANORAMA.size() - 1)); | ||
THIS_PANORAMA.clear(); | ||
THIS_PANORAMA.add(Panoramas.getCurrent()); | ||
READ_SPLASHES.clear(); | ||
} | ||
|
||
@Unique | ||
private void VISTAS_addOtherSplash(ResourceManager resourceManager, Profiler profiler, CallbackInfoReturnable<List<String>> ci, Panorama thisPanorama) { | ||
if (!READ_SPLASHES.contains(thisPanorama)) { | ||
READ_SPLASHES.add(thisPanorama); | ||
ArrayList<String> splashTexts = Lists.newArrayList(storedSplashList); | ||
ArrayList<String> newSplashTexts = Lists.newArrayList(); | ||
ArrayList<Panorama> needToAdd = Lists.newArrayList(); | ||
Pattern pattern = Pattern.compile(panoramaRegex); | ||
for (String splash : splashTexts) { | ||
Matcher matcher = pattern.matcher(splash); | ||
if (matcher.find()) { | ||
try { | ||
needToAdd.add(Panoramas.getOrThrow(splash.substring(1, splash.lastIndexOf("$Splash")) + "_0")); | ||
} catch (InvalidPanoramaException ex) { | ||
Vistas.LOGGER.warn("\"" + thisPanorama.getSplashTexts().toString() + "\" calls \"" + splash + "\" which leads to no registered Panorama!"); | ||
} | ||
} else { | ||
newSplashTexts.add(splash.replace("$P$Splash", field_18934.getUsername().toUpperCase(Locale.ROOT)).replace("$p$Splash", field_18934.getUsername())); | ||
} | ||
} | ||
|
||
for (Panorama panorama : needToAdd) { | ||
if (!READ_SPLASHES.contains(panorama)) { | ||
THIS_PANORAMA.clear(); | ||
THIS_PANORAMA.add(panorama); | ||
newSplashTexts.addAll(prepare(resourceManager, profiler)); | ||
READ_SPLASHES.clear(); | ||
} | ||
} | ||
|
||
ci.setReturnValue(newSplashTexts); | ||
} | ||
} | ||
|
||
@Inject(method = "get", at = @At("HEAD"), cancellable = true) | ||
private void VISTAS_reloadBeforeGet(CallbackInfoReturnable<String> ci) { | ||
apply(prepare(MinecraftClient.getInstance().getResourceManager(), MinecraftClient.getInstance().getProfiler()), MinecraftClient.getInstance().getResourceManager(), MinecraftClient.getInstance().getProfiler()); | ||
} | ||
|
||
@Shadow | ||
protected abstract List<String> prepare(ResourceManager resourceManager, Profiler profiler); | ||
|
||
@Shadow | ||
protected abstract void apply(List<String> list, ResourceManager resourceManager, Profiler profiler); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/terraformersmc/vistas/resource/InvalidPanoramaException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.terraformersmc.vistas.resource; | ||
|
||
@SuppressWarnings("serial") | ||
public class InvalidPanoramaException extends RuntimeException { | ||
|
||
public InvalidPanoramaException(String string) { | ||
super(string); | ||
} | ||
|
||
public InvalidPanoramaException(String string, Throwable throwable) { | ||
super(string, throwable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "com.terraformersmc.vistas.mixin", | ||
"compatibilityLevel": "JAVA_8", | ||
"client": [ | ||
"GameRendererMixin", | ||
"MinecraftClientMixin", | ||
"RotatingCubeMapRendererMixin", | ||
"TitleScreenBackgroundMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "com.terraformersmc.vistas.mixin", | ||
"compatibilityLevel": "JAVA_8", | ||
"client": [ | ||
"GameRendererMixin", | ||
"MinecraftClientMixin", | ||
"RotatingCubeMapRendererMixin", | ||
"TitleScreenBackgroundMixin", | ||
"SplashTextResourceSupplierMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |