mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Allow confirm-and-save of the Experimental Settings warning. (#7275)
This commit is contained in:
1 parent
349e12f939
commit
02fd859d5c
10 files changed
+243
-9
No files matched your search
@@ -12,6 +12,8 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import net.minecraft.client.gui.chat.NarratorChatListener;
|
||||
import net.minecraft.client.gui.components.toasts.SystemToast;
|
||||
import net.minecraft.client.gui.screens.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||
import net.minecraft.client.model.Model;
|
||||
@@ -25,9 +27,9 @@ import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.server.WorldStem;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||
@@ -74,6 +76,8 @@ import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.client.player.Input;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.PrimaryLevelData;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
@@ -81,9 +85,7 @@ import com.mojang.math.Matrix3f;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Transformation;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
@@ -1096,4 +1098,46 @@ public class ForgeHooksClient
|
||||
{
|
||||
return ItemBlockRenderTypes.canRenderInLayer(state, RenderType.solid());
|
||||
}
|
||||
|
||||
public static void createWorldConfirmationScreen(
|
||||
LevelStorageSource save, String worldName, boolean creatingWorld,
|
||||
Function<LevelStorageSource.LevelStorageAccess, WorldStem.WorldDataSupplier> worldData,
|
||||
Function<Function<LevelStorageSource.LevelStorageAccess, WorldStem.WorldDataSupplier>, Runnable> runAfter)
|
||||
{
|
||||
Component title = new TranslatableComponent("selectWorld.backupQuestion.experimental");
|
||||
Component msg = new TranslatableComponent("selectWorld.backupWarning.experimental")
|
||||
.append("\n\n")
|
||||
.append(new TranslatableComponent("forge.selectWorld.backupWarning.experimental.additional"));
|
||||
|
||||
Screen screen = new ConfirmScreen(confirmed ->
|
||||
{
|
||||
if (confirmed)
|
||||
{
|
||||
//The WorldData is re-created when re-running the runnable,
|
||||
// so make sure to be setting the field to true on the right instance.
|
||||
runAfter.apply(worldData.andThen(wds -> (rm, dpc) ->
|
||||
wds.get(rm, dpc).mapFirst(wd -> wd instanceof PrimaryLevelData pld ? pld.withConfirmedWarning(true) : wd))
|
||||
).run();
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
|
||||
if (creatingWorld) // delete save when cancelling creation.
|
||||
{
|
||||
try (LevelStorageSource.LevelStorageAccess levelSave = save.createAccess(worldName))
|
||||
{
|
||||
levelSave.deleteLevel();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
SystemToast.onWorldDeleteFailure(Minecraft.getInstance(), worldName);
|
||||
LOGGER.error("Failed to delete world {}", worldName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, title, msg, CommonComponents.GUI_PROCEED, CommonComponents.GUI_CANCEL);
|
||||
|
||||
Minecraft.getInstance().setScreen(screen);
|
||||
}
|
||||
}
|
||||
@@ -1405,6 +1405,28 @@ public class ForgeHooks
|
||||
}
|
||||
}
|
||||
|
||||
public static String encodeLifecycle(Lifecycle lifecycle)
|
||||
{
|
||||
if (lifecycle == Lifecycle.stable())
|
||||
return "stable";
|
||||
if (lifecycle == Lifecycle.experimental())
|
||||
return "experimental";
|
||||
if (lifecycle instanceof Lifecycle.Deprecated dep)
|
||||
return "deprecated=" + dep.since();
|
||||
throw new IllegalArgumentException("Unknown lifecycle.");
|
||||
}
|
||||
|
||||
public static Lifecycle parseLifecycle(String lifecycle)
|
||||
{
|
||||
if (lifecycle.equals("stable"))
|
||||
return Lifecycle.stable();
|
||||
if (lifecycle.equals("experimental"))
|
||||
return Lifecycle.experimental();
|
||||
if (lifecycle.startsWith("deprecated="))
|
||||
return Lifecycle.deprecated(Integer.parseInt(lifecycle.substring(lifecycle.indexOf('=') + 1)));
|
||||
throw new IllegalArgumentException("Unknown lifecycle.");
|
||||
}
|
||||
|
||||
public static void saveMobEffect(CompoundTag nbt, String key, MobEffect effect)
|
||||
{
|
||||
var registryName = effect.getRegistryName();
|
||||
|
||||
Reference in new issue
Block a user