Fixed problems with DataFixer calls and Architectury
This commit is contained in:
parent
670928a604
commit
5e4f4d5b43
3 changed files with 35 additions and 44 deletions
|
@ -23,6 +23,10 @@ repositories {
|
|||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
minecraft {
|
||||
accessWidener = file("src/main/resources/bclib.accesswidener")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings minecraft.officialMojangMappings()
|
||||
|
|
|
@ -1,25 +1,33 @@
|
|||
package ru.bclib.mixin.client;
|
||||
|
||||
import com.mojang.datafixers.util.Function4;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Minecraft.ExperimentalDialogType;
|
||||
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.core.RegistryAccess;
|
||||
import net.minecraft.core.RegistryAccess.RegistryHolder;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.world.level.DataPackConfig;
|
||||
import net.minecraft.world.level.LevelSettings;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
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.dataexchange.DataExchangeAPI;
|
||||
import ru.bclib.api.datafixer.DataFixerAPI;
|
||||
import ru.bclib.interfaces.CustomColorProvider;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public abstract class MinecraftMixin {
|
||||
@Final
|
||||
|
@ -41,57 +49,32 @@ public abstract class MinecraftMixin {
|
|||
});
|
||||
}
|
||||
|
||||
@Shadow
|
||||
protected abstract void doLoadLevel(String string, RegistryHolder registryHolder, Function<LevelStorageAccess, DataPackConfig> function, Function4<LevelStorageAccess, RegistryHolder, ResourceManager, DataPackConfig, WorldData> function4, boolean bl, ExperimentalDialogType experimentalDialogType);
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private LevelStorageSource levelSource;
|
||||
|
||||
@Shadow
|
||||
public abstract void loadLevel(String string);
|
||||
|
||||
@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;
|
||||
} else {
|
||||
@Inject(method = "loadLevel", cancellable = true, at = @At("HEAD"))
|
||||
private void bclib_callFixerOnLoad(String levelID, CallbackInfo ci) {
|
||||
DataExchangeAPI.prepareServerside();
|
||||
}
|
||||
|
||||
final String recursiveLevelID = BCLIB_RECURSION + levelID;
|
||||
if (!recursiveCall && DataFixerAPI.fixData(this.levelSource, levelID, true, (appliedFixes)->{
|
||||
this.loadLevel(recursiveLevelID);
|
||||
})){
|
||||
|
||||
if (DataFixerAPI.fixData(this.levelSource, levelID, true, (appliedFixes) -> {
|
||||
this.doLoadLevel(levelID, RegistryAccess.builtin(), Minecraft::loadDataPacks, Minecraft::loadWorldData, false, Minecraft.ExperimentalDialogType.BACKUP);
|
||||
})) {
|
||||
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="createLevel", at=@At("HEAD"))
|
||||
@Inject(method = "createLevel", at = @At("HEAD"))
|
||||
private void bclib_initPatchData(String levelID, LevelSettings levelSettings, RegistryHolder registryHolder, WorldGenSettings worldGenSettings, CallbackInfo ci) {
|
||||
DataFixerAPI.initializeWorldData(this.levelSource, levelID, true);
|
||||
}
|
||||
|
||||
|
||||
// @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();
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
|
4
src/main/resources/bclib.accesswidener
Normal file
4
src/main/resources/bclib.accesswidener
Normal file
|
@ -0,0 +1,4 @@
|
|||
accessWidener v1 named
|
||||
|
||||
# Classes
|
||||
accessible class net/minecraft/client/Minecraft$ExperimentalDialogType
|
Loading…
Add table
Add a link
Reference in a new issue