Added Screen to confirm Patches

This commit is contained in:
Frank Bauer 2021-07-26 18:36:20 +02:00
parent c93c271bd4
commit a247b17e7f
8 changed files with 384 additions and 26 deletions

View file

@ -5,16 +5,19 @@ import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.main.GameConfig;
import net.minecraft.core.Registry;
import net.minecraft.world.level.storage.LevelStorageSource;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.api.datafixer.DataFixerAPI;
import ru.bclib.interfaces.CustomColorProvider;
@Mixin(Minecraft.class)
public class MinecraftMixin {
public abstract class MinecraftMixin {
@Final
@Shadow
private BlockColors blockColors;
@ -33,4 +36,51 @@ public class MinecraftMixin {
}
});
}
@Shadow @Final private LevelStorageSource levelSource;
@Shadow public abstract void loadLevel(String string);
private final String BCLIB_RECURSION = "$@BCLIB:";
@Inject(method="loadLevel", cancellable = true, at=@At("HEAD"))
private void bclib_callFixerOnLoad(String levelID, CallbackInfo ci){
boolean recursiveCall = false;
if (levelID.startsWith(BCLIB_RECURSION)) {
levelID = levelID.substring(BCLIB_RECURSION.length());
recursiveCall = true;
}
final String recursiveLevelID = BCLIB_RECURSION + levelID;
if (!recursiveCall && DataFixerAPI.fixData(this.levelSource, levelID, true, (appliedFixes)->{
this.loadLevel(recursiveLevelID);
})){
ci.cancel();
}
}
@ModifyArg(method="loadLevel", at=@At(value="INVOKE", target="Lnet/minecraft/client/Minecraft;doLoadLevel(Ljava/lang/String;Lnet/minecraft/core/RegistryAccess$RegistryHolder;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/client/Minecraft$ExperimentalDialogType;)V"))
private String bclib_correctLevelID(String levelID){
if (levelID.startsWith(BCLIB_RECURSION)) {
levelID = levelID.substring(BCLIB_RECURSION.length());
}
return levelID;
}
// @Inject(method="doLoadLevel", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at=@At(value="INVOKE", target="Lnet/minecraft/client/Minecraft;makeServerStem(Lnet/minecraft/core/RegistryAccess$RegistryHolder;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;)Lnet/minecraft/client/Minecraft$ServerStem;"))
// private void bclib_onCallFixer(
// String string,
// RegistryHolder registryHolder,
// Function<LevelStorageAccess, DataPackConfig> function,
// Function4<LevelStorageAccess, RegistryHolder, ResourceManager, DataPackConfig, WorldData> function4,
// boolean bl,
// ExperimentalDialogType experimentalDialogType,
// CallbackInfo ci,
// LevelStorageSource.LevelStorageAccess levelStorageAccess) {
//
// DataFixerAPI.fixData(levelStorageAccess);
// ci.cancel();
//
// }
}