From 09f467091f1cb1d69769728c996f060f3da74adc Mon Sep 17 00:00:00 2001 From: apple502j <33279053+apple502j@users.noreply.github.com> Date: Mon, 18 Mar 2024 13:35:38 +0900 Subject: [PATCH] Turn off experiments warning --- .../resource/loader/RegistryLoaderMixin.java | 51 +++++++++++++++++++ .../fabric-resource-loader-v0.mixins.json | 1 + .../damage_type/porting_fabric_api.json | 7 +++ 3 files changed, 59 insertions(+) create mode 100644 fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/RegistryLoaderMixin.java create mode 100644 fabric-resource-loader-v0/src/testmod/resources/resourcepacks/test2/data/fabric-resource-loader-v0-testmod/damage_type/porting_fabric_api.json diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/RegistryLoaderMixin.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/RegistryLoaderMixin.java new file mode 100644 index 0000000000..1e254bb4dc --- /dev/null +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/RegistryLoaderMixin.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.resource.loader; + +import java.util.Optional; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.serialization.Lifecycle; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; + +import net.minecraft.registry.RegistryLoader; +import net.minecraft.registry.entry.RegistryEntryInfo; +import net.minecraft.resource.Resource; + +import net.fabricmc.fabric.api.resource.ModResourcePack; + +@Mixin(RegistryLoader.class) +public class RegistryLoaderMixin { + @Unique + private static final RegistryEntryInfo MOD_PROVIDED_INFO = new RegistryEntryInfo(Optional.empty(), Lifecycle.stable()); + + // On the server side, loading mod-provided DRM entries should not show experiments screen. + // While the lifecycle is set to experimental on the client side (a de-sync), + // there is no good way to fix this without breaking protocol; the lifecycle seems to be unused on + // the client side anyway. + @ModifyExpressionValue(method = "loadFromResource(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/RegistryOps$RegistryInfoGetter;Lnet/minecraft/registry/MutableRegistry;Lcom/mojang/serialization/Decoder;Ljava/util/Map;)V", at = @At(value = "INVOKE", target = "Ljava/util/function/Function;apply(Ljava/lang/Object;)Ljava/lang/Object;")) + private static Object markModProvidedAsStable(Object original, @Local Resource resource) { + if (original instanceof RegistryEntryInfo info && info.knownPackInfo().isEmpty() && resource.getPack() instanceof ModResourcePack) { + return MOD_PROVIDED_INFO; + } + + return original; + } +} diff --git a/fabric-resource-loader-v0/src/main/resources/fabric-resource-loader-v0.mixins.json b/fabric-resource-loader-v0/src/main/resources/fabric-resource-loader-v0.mixins.json index cf05b13a5e..10f9d5e5df 100644 --- a/fabric-resource-loader-v0/src/main/resources/fabric-resource-loader-v0.mixins.json +++ b/fabric-resource-loader-v0/src/main/resources/fabric-resource-loader-v0.mixins.json @@ -7,6 +7,7 @@ "KeyedResourceReloadListenerMixin", "LifecycledResourceManagerImplMixin", "MinecraftServerMixin", + "RegistryLoaderMixin", "ResourceMixin", "ResourcePackManagerMixin", "ResourcePackProfileMixin", diff --git a/fabric-resource-loader-v0/src/testmod/resources/resourcepacks/test2/data/fabric-resource-loader-v0-testmod/damage_type/porting_fabric_api.json b/fabric-resource-loader-v0/src/testmod/resources/resourcepacks/test2/data/fabric-resource-loader-v0-testmod/damage_type/porting_fabric_api.json new file mode 100644 index 0000000000..a413cd294e --- /dev/null +++ b/fabric-resource-loader-v0/src/testmod/resources/resourcepacks/test2/data/fabric-resource-loader-v0-testmod/damage_type/porting_fabric_api.json @@ -0,0 +1,7 @@ +{ + "message_id": "generic", + "exhaustion": 10, + "scaling": "never", + "effects": "thorns", + "death_message_type": "intentional_game_design" +}