From b805fa74f8ebe713528639d1965e8c17d5c1b93d Mon Sep 17 00:00:00 2001 From: Jonathing Date: Tue, 18 Feb 2025 16:13:58 -0500 Subject: [PATCH] Backport even more future ResourceLocation methods (#10428) --- .../resources/ResourceLocation.java.patch | 60 ++++++++++++++++--- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/patches/minecraft/net/minecraft/resources/ResourceLocation.java.patch b/patches/minecraft/net/minecraft/resources/ResourceLocation.java.patch index eedccb18f8..9749e8f87d 100644 --- a/patches/minecraft/net/minecraft/resources/ResourceLocation.java.patch +++ b/patches/minecraft/net/minecraft/resources/ResourceLocation.java.patch @@ -1,21 +1,29 @@ --- a/net/minecraft/resources/ResourceLocation.java +++ b/net/minecraft/resources/ResourceLocation.java -@@ -34,6 +_,7 @@ +@@ -34,6 +_,8 @@ this.f_135805_ = p_249394_; } -+ /** Forge: Consider using {@link #fromNamespaceAndPath(String, String)} instead, as Mojang made this constructor private in Vanilla 1.21 */ ++ /** @deprecated Forge: Consider using {@link #fromNamespaceAndPath(String, String)} instead, as Mojang made this constructor private in 1.21 */ ++ @Deprecated(forRemoval = true, since = "1.20.6") public ResourceLocation(String p_135811_, String p_135812_) { this(m_245413_(p_135811_, p_135812_), m_245185_(p_135811_, p_135812_), (ResourceLocation.Dummy)null); } -@@ -42,6 +_,7 @@ +@@ -42,10 +_,14 @@ this(p_135814_[0], p_135814_[1]); } -+ /** Forge: Consider using {@link #parse(String)} instead, as Mojang made this constructor private in Vanilla 1.21 */ ++ /** @deprecated Forge: Consider using {@link #parse(String)} instead, as Mojang made this constructor private in 1.21 */ ++ @Deprecated(forRemoval = true, since = "1.20.6") public ResourceLocation(String p_135809_) { this(m_135832_(p_135809_, ':')); } + ++ /** @deprecated Forge: Consider using {@link #bySeparator(String, char)} instead, as Mojang removed this method in 1.21 */ ++ @Deprecated(forRemoval = true, since = "1.20.6") + public static ResourceLocation m_135822_(String p_135823_, char p_135824_) { + return new ResourceLocation(m_135832_(p_135823_, p_135824_)); + } @@ -143,6 +_,12 @@ return i; } @@ -29,19 +37,55 @@ public String m_179910_() { return this.toString().replace('/', '_').replace(':', '_'); } -@@ -244,5 +_,15 @@ +@@ -243,6 +_,51 @@ + public JsonElement serialize(ResourceLocation p_135855_, Type p_135856_, JsonSerializationContext p_135857_) { return new JsonPrimitive(p_135855_.toString()); - } ++ } + } + -+ /** Forge: Backport of Vanilla 1.21 method */ ++ /** Forge: This is a backported method from 1.21, and is the replacement for {@link #ResourceLocation(String, String)}. */ + public static ResourceLocation fromNamespaceAndPath(String namespace, String path) { + return new ResourceLocation(namespace, path); + } + -+ /** Forge: Backport of Vanilla 1.21 method */ ++ /** Forge: This is a backported method from 1.21, and is the replacement for {@link #ResourceLocation(String)}. */ + public static ResourceLocation parse(String location) { + return new ResourceLocation(location); ++ } ++ ++ /** ++ * Forge: This is a backported method from 1.21, and acts as an alternative to using {@link #parse(String)}. If you ++ * know for sure you are going to be using the {@linkplain #DEFAULT_NAMESPACE default namespace} ++ * ({@code "minecraft"}), use this. ++ */ ++ public static ResourceLocation withDefaultNamespace(String path) { ++ return new ResourceLocation(f_179908_, m_245185_(f_179908_, path), null); ++ } ++ ++ /** Forge: This is a backported method from 1.21, and is the replacement for {@link #of(String, char)}. */ ++ public static ResourceLocation bySeparator(String location, char separator) { ++ return m_135822_(location, separator); ++ } ++ ++ /** ++ * Forge: This is a backported method from 1.21, and is the same as {@link #bySeparator(String, char)} but returns ++ * {@code null} if a resource location cannot be created. ++ */ ++ public static @Nullable ResourceLocation tryBySeparator(String location, char separator) { ++ int i = location.indexOf(separator); ++ if (i >= 0) { ++ String s = location.substring(i + 1); ++ if (!m_135841_(s)) { ++ return null; ++ } else if (i != 0) { ++ String s1 = location.substring(0, i); ++ return m_135843_(s1) ? new ResourceLocation(s1, s, null) : null; ++ } else { ++ return new ResourceLocation(f_179908_, s, null); ++ } ++ } else { ++ return m_135841_(location) ? new ResourceLocation(f_179908_, location, null) : null; + } } }