Allow confirm-and-save of the Experimental Settings warning. (#7275)

This commit is contained in:
Cyborgmas authored and GitHub committed 2022-03-24 21:36:03 +00:00
1 parent 349e12f939
commit 02fd859d5c
10 files changed
+243 -9

No files matched your search

@@ -346,7 +346,16 @@
}));
try {
@@ -1875,7 +_,7 @@
@@ -1869,13 +_,15 @@
WorldData worlddata = worldstem.f_206895_();
boolean flag = worlddata.m_5961_().m_64670_();
boolean flag1 = worlddata.m_5754_() != Lifecycle.stable();
- if (p_205210_ == Minecraft.ExperimentalDialogType.NONE || !flag && !flag1) {
+ //Skip confirmation if it has been done already for this world
+ boolean skipConfirmation = worlddata instanceof PrimaryLevelData pld && pld.hasConfirmedExperimentalWarning();
+ if (skipConfirmation || p_205210_ == Minecraft.ExperimentalDialogType.NONE || !flag && !flag1) {
this.m_91399_();
this.f_90999_.set((StoringChunkProgressListener)null);
try {
RegistryAccess.Frozen registryaccess$frozen = worldstem.f_206894_();
@@ -364,7 +373,7 @@
StoringChunkProgressListener storingchunkprogresslistener = new StoringChunkProgressListener(p_210795_ + 0);
this.f_90999_.set(storingchunkprogresslistener);
return ProcessorChunkProgressListener.m_143583_(storingchunkprogresslistener, this.f_91023_::add);
@@ -1929,11 +_,16 @@
@@ -1929,12 +_,19 @@
connection.m_129505_(new ClientHandshakePacketListenerImpl(connection, this, (Screen)null, (p_210793_) -> {
}));
connection.m_129512_(new ClientIntentionPacket(socketaddress.toString(), 0, ConnectionProtocol.LOGIN));
@@ -377,12 +386,15 @@
+ connection.m_129512_(new ServerboundHelloPacket(gameProfile));
this.f_91009_ = connection;
} else {
+ if (flag) //FORGE: For legacy world options, let vanilla handle it.
this.m_91143_(p_205210_, p_205206_, flag, () -> {
- this.m_205205_(p_205206_, p_205207_, p_205208_, p_205209_, Minecraft.ExperimentalDialogType.NONE);
+ this.doLoadLevel(p_205206_, p_205207_, p_205208_, p_205209_, Minecraft.ExperimentalDialogType.NONE, creating);
});
+ else net.minecraftforge.client.ForgeHooksClient.createWorldConfirmationScreen(f_91031_, p_205206_, creating, p_205208_, wds -> () -> this.doLoadLevel(p_205206_, p_205207_, wds, p_205209_, ExperimentalDialogType.NONE, creating));
worldstem.close();
try {
@@ -2026,6 +_,7 @@
}
@@ -0,0 +1,38 @@
--- a/net/minecraft/client/gui/screens/worldselection/WorldSelectionList.java
+++ b/net/minecraft/client/gui/screens/worldselection/WorldSelectionList.java
@@ -64,6 +_,7 @@
static final DateFormat f_101646_ = new SimpleDateFormat();
static final ResourceLocation f_101647_ = new ResourceLocation("textures/misc/unknown_server.png");
static final ResourceLocation f_101648_ = new ResourceLocation("textures/gui/world_selection.png");
+ private static final ResourceLocation FORGE_EXPERIMENTAL_WARNING_ICON = new ResourceLocation("forge","textures/gui/experimental_warning.png");
static final Component f_101649_ = (new TranslatableComponent("selectWorld.tooltip.fromNewerVersion1")).m_130940_(ChatFormatting.RED);
static final Component f_101650_ = (new TranslatableComponent("selectWorld.tooltip.fromNewerVersion2")).m_130940_(ChatFormatting.RED);
static final Component f_101651_ = (new TranslatableComponent("selectWorld.tooltip.snapshot1")).m_130940_(ChatFormatting.GOLD);
@@ -207,6 +_,7 @@
RenderSystem.m_69478_();
GuiComponent.m_93133_(p_101721_, p_101724_, p_101723_, 0.0F, 0.0F, 32, 32, 32, 32);
RenderSystem.m_69461_();
+ renderExperimentalWarning(p_101721_, p_101727_, p_101728_, p_101723_, p_101724_);
if (this.f_101693_.f_91066_.f_92051_ || p_101729_) {
RenderSystem.m_157456_(0, WorldSelectionList.f_101648_);
GuiComponent.m_93172_(p_101721_, p_101724_, p_101723_, p_101724_ + 32, p_101723_ + 32, -1601138544);
@@ -524,6 +_,19 @@
public String m_170324_() {
return this.f_101695_.m_78361_();
+ }
+ private void renderExperimentalWarning(PoseStack stack, int mouseX, int mouseY, int top, int left) {
+ if (this.f_101695_.isExperimental()) {
+ int leftStart = left + WorldSelectionList.this.m_5759_();
+ RenderSystem.m_157456_(0, WorldSelectionList.FORGE_EXPERIMENTAL_WARNING_ICON);
+ GuiComponent.m_93133_(stack, leftStart - 36, top, 0.0F, 0.0F, 32, 32, 32, 32);
+ //Reset texture to what it was before
+ RenderSystem.m_157456_(0, this.f_101698_ != null ? this.f_101696_ : WorldSelectionList.f_101647_);
+ if (WorldSelectionList.this.m_93412_(mouseX, mouseY) == this && mouseX > leftStart - 36 && mouseX < leftStart) {
+ List<net.minecraft.util.FormattedCharSequence> tooltip = Minecraft.m_91087_().f_91062_.m_92923_(new TranslatableComponent("forge.experimentalsettings.tooltip"), 200);
+ WorldSelectionList.this.f_101654_.m_96617_(stack, tooltip, mouseX, mouseY);
+ }
+ }
}
}
}
@@ -1,10 +1,61 @@
--- a/net/minecraft/world/level/LevelSettings.java
+++ b/net/minecraft/world/level/LevelSettings.java
@@ -62,6 +_,7 @@
@@ -11,8 +_,12 @@
private final boolean f_46906_;
private final GameRules f_46907_;
private final DataPackConfig f_46908_;
+ private final com.mojang.serialization.Lifecycle lifecycle;
public LevelSettings(String p_46910_, GameType p_46911_, boolean p_46912_, Difficulty p_46913_, boolean p_46914_, GameRules p_46915_, DataPackConfig p_46916_) {
+ this(p_46910_, p_46911_, p_46912_, p_46913_, p_46914_, p_46915_, p_46916_, com.mojang.serialization.Lifecycle.stable());
+ }
+ public LevelSettings(String p_46910_, GameType p_46911_, boolean p_46912_, Difficulty p_46913_, boolean p_46914_, GameRules p_46915_, DataPackConfig p_46916_, com.mojang.serialization.Lifecycle lifecycle) {
this.f_46902_ = p_46910_;
this.f_46903_ = p_46911_;
this.f_46904_ = p_46912_;
@@ -20,13 +_,14 @@
this.f_46906_ = p_46914_;
this.f_46907_ = p_46915_;
this.f_46908_ = p_46916_;
+ this.lifecycle = lifecycle;
}
public static LevelSettings m_46924_(Dynamic<?> p_46925_, DataPackConfig p_46926_) {
GameType gametype = GameType.m_46393_(p_46925_.get("GameType").asInt(0));
return new LevelSettings(p_46925_.get("LevelName").asString(""), gametype, p_46925_.get("hardcore").asBoolean(false), p_46925_.get("Difficulty").asNumber().map((p_46928_) -> {
return Difficulty.m_19029_(p_46928_.byteValue());
- }).result().orElse(Difficulty.NORMAL), p_46925_.get("allowCommands").asBoolean(gametype == GameType.CREATIVE), new GameRules(p_46925_.get("GameRules")), p_46926_);
+ }).result().orElse(Difficulty.NORMAL), p_46925_.get("allowCommands").asBoolean(gametype == GameType.CREATIVE), new GameRules(p_46925_.get("GameRules")), p_46926_, net.minecraftforge.common.ForgeHooks.parseLifecycle(p_46925_.get("forgeLifecycle").asString("stable")));
}
public String m_46917_() {
@@ -58,18 +_,25 @@
}
public LevelSettings m_46922_(GameType p_46923_) {
- return new LevelSettings(this.f_46902_, p_46923_, this.f_46904_, this.f_46905_, this.f_46906_, this.f_46907_, this.f_46908_);
+ return new LevelSettings(this.f_46902_, p_46923_, this.f_46904_, this.f_46905_, this.f_46906_, this.f_46907_, this.f_46908_, this.lifecycle);
}
public LevelSettings m_46918_(Difficulty p_46919_) {
- return new LevelSettings(this.f_46902_, this.f_46903_, this.f_46904_, p_46919_, this.f_46906_, this.f_46907_, this.f_46908_);
+ net.minecraftforge.common.ForgeHooks.onDifficultyChange(p_46919_, this.f_46905_);
return new LevelSettings(this.f_46902_, this.f_46903_, this.f_46904_, p_46919_, this.f_46906_, this.f_46907_, this.f_46908_);
+ return new LevelSettings(this.f_46902_, this.f_46903_, this.f_46904_, p_46919_, this.f_46906_, this.f_46907_, this.f_46908_, this.lifecycle);
}
public LevelSettings m_46920_(DataPackConfig p_46921_) {
- return new LevelSettings(this.f_46902_, this.f_46903_, this.f_46904_, this.f_46905_, this.f_46906_, this.f_46907_, p_46921_);
+ return new LevelSettings(this.f_46902_, this.f_46903_, this.f_46904_, this.f_46905_, this.f_46906_, this.f_46907_, p_46921_, this.lifecycle);
}
public LevelSettings m_46935_() {
- return new LevelSettings(this.f_46902_, this.f_46903_, this.f_46904_, this.f_46905_, this.f_46906_, this.f_46907_.m_46202_(), this.f_46908_);
+ return new LevelSettings(this.f_46902_, this.f_46903_, this.f_46904_, this.f_46905_, this.f_46906_, this.f_46907_.m_46202_(), this.f_46908_, this.lifecycle);
+ }
+ public LevelSettings withLifecycle(com.mojang.serialization.Lifecycle lifecycle) {
+ return new LevelSettings(this.f_46902_, this.f_46903_, this.f_46904_, this.f_46905_, this.f_46906_, this.f_46907_, this.f_46908_, lifecycle);
+ }
+ public com.mojang.serialization.Lifecycle getLifecycle() {
+ return this.lifecycle;
}
}
@@ -0,0 +1,10 @@
--- a/net/minecraft/world/level/storage/LevelSummary.java
+++ b/net/minecraft/world/level/storage/LevelSummary.java
@@ -181,4 +_,7 @@
return this.f_164922_;
}
}
+ public boolean isExperimental() {
+ return this.f_78344_.getLifecycle().equals(com.mojang.serialization.Lifecycle.experimental());
+ }
}
@@ -0,0 +1,53 @@
--- a/net/minecraft/world/level/storage/PrimaryLevelData.java
+++ b/net/minecraft/world/level/storage/PrimaryLevelData.java
@@ -76,6 +_,7 @@
private final Set<String> f_78439_;
private boolean f_78440_;
private final TimerQueue<MinecraftServer> f_78441_;
+ private boolean confirmedExperimentalWarning = false;
private PrimaryLevelData(@Nullable DataFixer p_164942_, int p_164943_, @Nullable CompoundTag p_164944_, boolean p_164945_, int p_164946_, int p_164947_, int p_164948_, float p_164949_, long p_164950_, long p_164951_, int p_164952_, int p_164953_, int p_164954_, boolean p_164955_, int p_164956_, boolean p_164957_, boolean p_164958_, boolean p_164959_, WorldBorder.Settings p_164960_, int p_164961_, int p_164962_, @Nullable UUID p_164963_, Set<String> p_164964_, TimerQueue<MinecraftServer> p_164965_, @Nullable CompoundTag p_164966_, CompoundTag p_164967_, LevelSettings p_164968_, WorldGenSettings p_164969_, Lifecycle p_164970_) {
this.f_78452_ = p_164942_;
@@ -104,7 +_,9 @@
this.f_78441_ = p_164965_;
this.f_78466_ = p_164966_;
this.f_78465_ = p_164967_;
- this.f_78443_ = p_164968_;
+ this.f_78443_ = p_164968_.withLifecycle(p_164970_);
+ if (p_164970_ == Lifecycle.stable()) //Reset to unconfirmed if the lifecycle goes back to stable
+ this.confirmedExperimentalWarning = false;
this.f_78444_ = p_164969_;
this.f_78445_ = p_164970_;
}
@@ -120,7 +_,7 @@
});
return new PrimaryLevelData(p_78532_, p_78533_, p_78534_, p_78531_.get("WasModded").asBoolean(false), p_78531_.get("SpawnX").asInt(0), p_78531_.get("SpawnY").asInt(0), p_78531_.get("SpawnZ").asInt(0), p_78531_.get("SpawnAngle").asFloat(0.0F), i, p_78531_.get("DayTime").asLong(i), p_78536_.m_78389_(), p_78531_.get("clearWeatherTime").asInt(0), p_78531_.get("rainTime").asInt(0), p_78531_.get("raining").asBoolean(false), p_78531_.get("thunderTime").asInt(0), p_78531_.get("thundering").asBoolean(false), p_78531_.get("initialized").asBoolean(true), p_78531_.get("DifficultyLocked").asBoolean(false), WorldBorder.Settings.m_62037_(p_78531_, WorldBorder.f_61907_), p_78531_.get("WanderingTraderSpawnDelay").asInt(0), p_78531_.get("WanderingTraderSpawnChance").asInt(0), p_78531_.get("WanderingTraderId").read(SerializableUUID.f_123272_).result().orElse((UUID)null), p_78531_.get("ServerBrands").asStream().flatMap((p_78529_) -> {
return p_78529_.asString().result().stream();
- }).collect(Collectors.toCollection(Sets::newLinkedHashSet)), new TimerQueue<>(TimerCallbacks.f_82226_, p_78531_.get("ScheduledEvents").asStream()), (CompoundTag)p_78531_.get("CustomBossEvents").orElseEmptyMap().getValue(), compoundtag, p_78535_, p_78537_, p_78538_);
+ }).collect(Collectors.toCollection(Sets::newLinkedHashSet)), new TimerQueue<>(TimerCallbacks.f_82226_, p_78531_.get("ScheduledEvents").asStream()), (CompoundTag)p_78531_.get("CustomBossEvents").orElseEmptyMap().getValue(), compoundtag, p_78535_, p_78537_, p_78538_).withConfirmedWarning(p_78538_ != Lifecycle.stable() && p_78531_.get("confirmedExperimentalSettings").asBoolean(false));
}
public CompoundTag m_6626_(RegistryAccess p_78543_, @Nullable CompoundTag p_78544_) {
@@ -191,6 +_,8 @@
p_78547_.m_128362_("WanderingTraderId", this.f_78438_);
}
+ p_78547_.m_128359_("forgeLifecycle", net.minecraftforge.common.ForgeHooks.encodeLifecycle(this.f_78443_.getLifecycle()));
+ p_78547_.m_128379_("confirmedExperimentalSettings", this.confirmedExperimentalWarning);
}
public int m_6789_() {
@@ -453,5 +_,13 @@
public LevelSettings m_5926_() {
return this.f_78443_.m_46935_();
+ }
+ //FORGE
+ public boolean hasConfirmedExperimentalWarning() {
+ return this.confirmedExperimentalWarning;
+ }
+ public PrimaryLevelData withConfirmedWarning(boolean confirmedWarning) { //Builder-like to not patch ctor
+ this.confirmedExperimentalWarning = confirmedWarning;
+ return this;
}
}
@@ -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();
@@ -190,5 +190,8 @@
"generic.reachDistance": "Reach Distance",
"fluid.minecraft.milk": "Milk",
"fluid.minecraft.flowing_milk": "Milk"
"fluid.minecraft.flowing_milk": "Milk",
"forge.experimentalsettings.tooltip": "This world uses experimental settings, which could stop working at any time.",
"forge.selectWorld.backupWarning.experimental.additional" : "This message will not show again for this world."
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

+1
View File
@@ -46,6 +46,7 @@ net/minecraft/world/item/ItemStack.onItemUseFirst(Lnet/minecraft/world/item/cont
net/minecraft/world/item/MapItem.getCustomMapData(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/Level;)Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData;=|p_42910_,p_42911_
net/minecraft/world/item/alchemy/PotionBrewing$Mix.<init>(Lnet/minecraftforge/registries/ForgeRegistryEntry;Lnet/minecraft/world/item/crafting/Ingredient;Lnet/minecraftforge/registries/ForgeRegistryEntry;)V=|p_43536_,p_43537_,p_43538_
net/minecraft/world/level/Level.markAndNotifyBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/chunk/LevelChunk;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;II)V=|p_46605_,levelchunk,blockstate,p_46606_,p_46607_,p_46608_
net/minecraft/world/level/LevelSettings.<init>(Ljava/lang/String;Lnet/minecraft/world/level/GameType;ZLnet/minecraft/world/Difficulty;ZLnet/minecraft/world/level/GameRules;Lnet/minecraft/world/level/DataPackConfig;Lcom/mojang/serialization/Lifecycle;)V=|p_46910_,p_46911_,p_46912_,p_46913_,p_46914_,p_46915_,p_46916_,lifecycle
net/minecraft/world/level/block/FireBlock.tryCatchFire(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;ILjava/util/Random;ILnet/minecraft/core/Direction;)V=|p_53432_,p_53433_,p_53434_,p_53435_,p_53436_,face
net/minecraft/world/level/block/FlowerPotBlock.<init>(Ljava/util/function/Supplier;Ljava/util/function/Supplier;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V=|emptyPot,p_53528_,properties
net/minecraft/world/level/block/LiquidBlock.<init>(Ljava/util/function/Supplier;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V=|p_54694_,p_54695_