From 05f948543b492eb2cf0967f2597f25c2ff39ec9b Mon Sep 17 00:00:00 2001 From: LambdAurora Date: Fri, 13 Nov 2020 19:21:24 +0100 Subject: [PATCH] Internal refactor, remove legacy code, fix FabricMC/fabric#878. (#1134) --- .../resource/loader/DeferredInputStream.java | 106 ------------- .../loader/DeferredNioExecutionHandler.java | 96 ------------ .../resource/loader/ModNioResourcePack.java | 45 +----- .../resource/loader/ModResourcePackUtil.java | 2 +- .../loader/ResourceManagerHelperImpl.java | 11 +- ...ack.java => DefaultResourcePackMixin.java} | 2 +- .../KeyedResourceReloadListenerMixin.java | 83 ++++++++++ ...tServer.java => MinecraftServerMixin.java} | 2 +- .../MixinKeyedResourceReloadListener.java | 146 ------------------ ...inReloadableResourceManagerImplClient.java | 50 ------ ...> ReloadableResourceManagerImplMixin.java} | 4 +- ...ger.java => ResourcePackManagerMixin.java} | 2 +- ...ientBuiltinResourcePackProviderMixin.java} | 4 +- .../CreateWorldScreenMixin.java} | 5 +- ...ontManagerResourceReloadListenerMixin.java | 32 ++++ .../GameOptionsMixin.java} | 4 +- ...eyedResourceReloadListenerClientMixin.java | 86 +++++++++++ .../PackScreenMixin.java} | 4 +- .../fabric-resource-loader-v0.mixins.json | 21 +-- 19 files changed, 242 insertions(+), 463 deletions(-) delete mode 100644 fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/DeferredInputStream.java delete mode 100644 fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/DeferredNioExecutionHandler.java rename fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/{MixinDefaultResourcePack.java => DefaultResourcePackMixin.java} (98%) create mode 100644 fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/KeyedResourceReloadListenerMixin.java rename fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/{MixinMinecraftServer.java => MinecraftServerMixin.java} (98%) delete mode 100644 fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinKeyedResourceReloadListener.java delete mode 100644 fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinReloadableResourceManagerImplClient.java rename fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/{MixinReloadableResourceManagerImpl.java => ReloadableResourceManagerImplMixin.java} (94%) rename fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/{MixinResourcePackManager.java => ResourcePackManagerMixin.java} (97%) rename fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/{MixinClientBuiltinResourcePackProvider.java => client/ClientBuiltinResourcePackProviderMixin.java} (93%) rename fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/{MixinCreateWorldScreen.java => client/CreateWorldScreenMixin.java} (95%) create mode 100644 fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/FontManagerResourceReloadListenerMixin.java rename fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/{MixinGameOptions.java => client/GameOptionsMixin.java} (95%) create mode 100644 fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/KeyedResourceReloadListenerClientMixin.java rename fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/{MixinPackScreen.java => client/PackScreenMixin.java} (94%) diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/DeferredInputStream.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/DeferredInputStream.java deleted file mode 100644 index 0ebccffb7..000000000 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/DeferredInputStream.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.impl.resource.loader; - -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.Callable; - -import net.minecraft.util.Unit; - -/** - * InputStream deferring to a separate I/O thread to work around - * Thread.interrupt()-related issues in NIO. - */ -class DeferredInputStream extends InputStream { - private final InputStream stream; - - public static InputStream deferIfNeeded(Callable streamSupplier) throws IOException { - if (DeferredNioExecutionHandler.shouldDefer()) { - return new DeferredInputStream(streamSupplier); - } else { - return DeferredNioExecutionHandler.submit(streamSupplier, false); - } - } - - DeferredInputStream(Callable streamSupplier) throws IOException { - stream = DeferredNioExecutionHandler.submit(streamSupplier); - - if (stream == null) { - throw new IOException("Something happened while trying to create an InputStream!"); - } - } - - DeferredInputStream(InputStream stream) throws IOException { - this.stream = stream; - - if (this.stream == null) { - throw new IOException("Something happened while trying to create an InputStream!"); - } - } - - @Override - public int available() throws IOException { - return DeferredNioExecutionHandler.submit(stream::available); - } - - @Override - public boolean markSupported() { - return stream.markSupported(); - } - - @Override - public void mark(int readLimit) { - stream.mark(readLimit); - } - - @Override - public void reset() throws IOException { - DeferredNioExecutionHandler.submit(() -> { - stream.reset(); - return Unit.INSTANCE; - }); - } - - @Override - public long skip(long n) throws IOException { - return DeferredNioExecutionHandler.submit(() -> stream.skip(n)); - } - - @Override - public int read() throws IOException { - return DeferredNioExecutionHandler.submit(stream::read); - } - - @Override - public int read(byte[] b) throws IOException { - return DeferredNioExecutionHandler.submit(() -> stream.read(b)); - } - - @Override - public int read(byte[] b, int offset, int length) throws IOException { - return DeferredNioExecutionHandler.submit(() -> stream.read(b, offset, length)); - } - - @Override - public void close() throws IOException { - DeferredNioExecutionHandler.submit(() -> { - stream.close(); - return Unit.INSTANCE; - }); - } -} diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/DeferredNioExecutionHandler.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/DeferredNioExecutionHandler.java deleted file mode 100644 index c7ffc4bb7..000000000 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/DeferredNioExecutionHandler.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.impl.resource.loader; - -import java.io.IOException; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; - -class DeferredNioExecutionHandler { - // private static final ThreadLocal DEFERRED_REQUIRED = new ThreadLocal<>(); - private static final boolean DEFER_REQUESTED = System.getProperty("fabric.resource-loader.deferFilesystemOperations", "false").equalsIgnoreCase("true"); - private static ExecutorService EXECUTOR_SERVICE; - - public static boolean shouldDefer() { - return DEFER_REQUESTED; - /* Boolean deferRequired = DEFERRED_REQUIRED.get(); - - if (deferRequired == null) { - deferRequired = false; - - StackTraceElement[] elements = Thread.currentThread().getStackTrace(); - - for (int i = 0; i < elements.length; i++) { - if (elements[i].getClassName().startsWith("paulscode.sound.")) { - deferRequired = true; - break; - } - } - - DEFERRED_REQUIRED.set(deferRequired); - } - - return deferRequired; */ - } - - public static V submit(Callable callable, boolean cond) throws IOException { - try { - return cond ? submit(callable) : callable.call(); - } catch (IOException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException("Exception which should not happen!", e); - } - } - - public static V submit(Callable callable) throws IOException { - if (EXECUTOR_SERVICE == null) { - EXECUTOR_SERVICE = Executors.newSingleThreadExecutor( - new ThreadFactoryBuilder() - .setNameFormat("Fabric Deferred I/O Thread") - .build() - ); - } - - Future future = EXECUTOR_SERVICE.submit(callable); - return getSubmittedFuture(future); - } - - static V getSubmittedFuture(Future future) throws IOException { - while (true) { - try { - return future.get(); - } catch (ExecutionException e) { - Throwable t = e.getCause(); - - if (t instanceof IOException) { - throw (IOException) t; - } else { - throw new RuntimeException("ExecutionException which should not happen!", t); - } - } catch (InterruptedException e) { - // keep calm, carry on... - } - } - } -} - diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ModNioResourcePack.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ModNioResourcePack.java index 5d1614bdd..2203aa3a5 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ModNioResourcePack.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ModNioResourcePack.java @@ -50,10 +50,9 @@ public class ModNioResourcePack extends AbstractFileResourcePack implements ModR private final boolean cacheable; private final AutoCloseable closer; private final String separator; - private final String name; private final boolean defaultEnabled; - public ModNioResourcePack(ModMetadata modInfo, Path path, AutoCloseable closer, String name, boolean defaultEnabled) { + public ModNioResourcePack(ModMetadata modInfo, Path path, AutoCloseable closer, boolean defaultEnabled) { super(null); this.modInfo = modInfo; this.basePath = path.toAbsolutePath().normalize(); @@ -61,7 +60,6 @@ public class ModNioResourcePack extends AbstractFileResourcePack implements ModR this.closer = closer; this.separator = basePath.getFileSystem().getSeparator(); // Specific to registered built-in resource packs. - this.name = name; this.defaultEnabled = defaultEnabled; } @@ -79,26 +77,10 @@ public class ModNioResourcePack extends AbstractFileResourcePack implements ModR protected InputStream openFile(String filename) throws IOException { InputStream stream; - if (DeferredNioExecutionHandler.shouldDefer()) { - stream = DeferredNioExecutionHandler.submit(() -> { - Path path = getPath(filename); + Path path = getPath(filename); - if (path != null && Files.isRegularFile(path)) { - return new DeferredInputStream(Files.newInputStream(path)); - } else { - return null; - } - }); - - if (stream != null) { - return stream; - } - } else { - Path path = getPath(filename); - - if (path != null && Files.isRegularFile(path)) { - return Files.newInputStream(path); - } + if (path != null && Files.isRegularFile(path)) { + return Files.newInputStream(path); } stream = ModResourcePackUtil.openDefault(modInfo, filename); @@ -117,19 +99,8 @@ public class ModNioResourcePack extends AbstractFileResourcePack implements ModR return true; } - if (DeferredNioExecutionHandler.shouldDefer()) { - try { - return DeferredNioExecutionHandler.submit(() -> { - Path path = getPath(filename); - return path != null && Files.isRegularFile(path); - }); - } catch (IOException e) { - return false; - } - } else { - Path path = getPath(filename); - return path != null && Files.isRegularFile(path); - } + Path path = getPath(filename); + return path != null && Files.isRegularFile(path); } @Override @@ -236,10 +207,6 @@ public class ModNioResourcePack extends AbstractFileResourcePack implements ModR @Override public String getName() { - if (this.name != null) { - return this.name; // Built-in resource pack provided by a mod, the name is overriden. - } - return ModResourcePackUtil.getName(modInfo); } } diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ModResourcePackUtil.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ModResourcePackUtil.java index 827824587..894796b04 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ModResourcePackUtil.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ModResourcePackUtil.java @@ -46,7 +46,7 @@ public final class ModResourcePackUtil { } Path path = container.getRootPath(); - ResourcePack pack = new ModNioResourcePack(container.getMetadata(), path, null, null, true); + ResourcePack pack = new ModNioResourcePack(container.getMetadata(), path, null, true); if (!pack.getNamespaces(type).isEmpty()) { packList.add(pack); diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ResourceManagerHelperImpl.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ResourceManagerHelperImpl.java index 6f232d0a7..0e5bb7b42 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ResourceManagerHelperImpl.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/impl/resource/loader/ResourceManagerHelperImpl.java @@ -38,9 +38,9 @@ import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; import net.minecraft.util.Pair; -import net.fabricmc.loader.api.ModContainer; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; +import net.fabricmc.loader.api.ModContainer; public class ResourceManagerHelperImpl implements ResourceManagerHelper { private static final Map registryMap = new HashMap<>(); @@ -62,7 +62,6 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper { * @param container The mod container. * @param enabledByDefault True if enabled by default, else false. * @return True if successfully registered the resource pack, else false. - * * @see ResourceManagerHelper#registerBuiltinResourcePack(Identifier, String, ModContainer, boolean) */ public static boolean registerBuiltinResourcePack(Identifier id, String subPath, ModContainer container, boolean enabledByDefault) { @@ -76,7 +75,13 @@ public class ResourceManagerHelperImpl implements ResourceManagerHelper { } String name = id.getNamespace() + "/" + id.getPath(); - builtinResourcePacks.add(new Pair<>(name, new ModNioResourcePack(container.getMetadata(), resourcePackPath, null, name, enabledByDefault))); + + builtinResourcePacks.add(new Pair<>(name, new ModNioResourcePack(container.getMetadata(), resourcePackPath, null, enabledByDefault) { + @Override + public String getName() { + return name; // Built-in resource pack provided by a mod, the name is overriden. + } + })); return true; } diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinDefaultResourcePack.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/DefaultResourcePackMixin.java similarity index 98% rename from fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinDefaultResourcePack.java rename to fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/DefaultResourcePackMixin.java index 86bdebbbe..a75a1709e 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinDefaultResourcePack.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/DefaultResourcePackMixin.java @@ -33,7 +33,7 @@ import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; @Mixin(DefaultResourcePack.class) -public class MixinDefaultResourcePack { +public class DefaultResourcePackMixin { @Inject(method = "findInputStream", at = @At("HEAD"), cancellable = true) protected void onFindInputStream(ResourceType resourceType, Identifier identifier, CallbackInfoReturnable callback) { if (DefaultResourcePack.resourcePath != null) { diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/KeyedResourceReloadListenerMixin.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/KeyedResourceReloadListenerMixin.java new file mode 100644 index 000000000..cd1d59def --- /dev/null +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/KeyedResourceReloadListenerMixin.java @@ -0,0 +1,83 @@ +/* + * 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.Collection; +import java.util.Collections; +import java.util.Locale; + +import org.spongepowered.asm.mixin.Mixin; + +import net.minecraft.loot.LootManager; +import net.minecraft.recipe.RecipeManager; +import net.minecraft.server.ServerAdvancementLoader; +import net.minecraft.server.function.CommandFunctionManager; +import net.minecraft.tag.TagManagerLoader; +import net.minecraft.util.Identifier; + +import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; +import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys; + +@Mixin({ + /* public */ + RecipeManager.class, ServerAdvancementLoader.class, CommandFunctionManager.class, LootManager.class, TagManagerLoader.class + /* private */ +}) +public abstract class KeyedResourceReloadListenerMixin implements IdentifiableResourceReloadListener { + private Identifier fabric$id; + private Collection fabric$dependencies; + + @Override + @SuppressWarnings({"ConstantConditions", "RedundantCast"}) + public Identifier getFabricId() { + if (this.fabric$id == null) { + Object self = this; + + if (self instanceof RecipeManager) { + this.fabric$id = ResourceReloadListenerKeys.RECIPES; + } else if (self instanceof ServerAdvancementLoader) { + this.fabric$id = ResourceReloadListenerKeys.ADVANCEMENTS; + } else if (self instanceof CommandFunctionManager) { + this.fabric$id = ResourceReloadListenerKeys.FUNCTIONS; + } else if (self instanceof LootManager) { + this.fabric$id = ResourceReloadListenerKeys.LOOT_TABLES; + } else if (self instanceof TagManagerLoader) { + this.fabric$id = ResourceReloadListenerKeys.TAGS; + } else { + this.fabric$id = new Identifier("minecraft", "private/" + self.getClass().getSimpleName().toLowerCase(Locale.ROOT)); + } + } + + return this.fabric$id; + } + + @Override + @SuppressWarnings({"ConstantConditions", "RedundantCast"}) + public Collection getFabricDependencies() { + if (this.fabric$dependencies == null) { + Object self = this; + + if (self instanceof TagManagerLoader) { + this.fabric$dependencies = Collections.emptyList(); + } else { + this.fabric$dependencies = Collections.singletonList(ResourceReloadListenerKeys.TAGS); + } + } + + return this.fabric$dependencies; + } +} diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinMinecraftServer.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MinecraftServerMixin.java similarity index 98% rename from fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinMinecraftServer.java rename to fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MinecraftServerMixin.java index e27b60709..483ea31e2 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinMinecraftServer.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MinecraftServerMixin.java @@ -31,7 +31,7 @@ import net.minecraft.server.MinecraftServer; import net.fabricmc.fabric.impl.resource.loader.ModNioResourcePack; @Mixin(MinecraftServer.class) -public class MixinMinecraftServer { +public class MinecraftServerMixin { @Redirect(method = "loadDataPacks", at = @At(value = "INVOKE", target = "Ljava/util/List;contains(Ljava/lang/Object;)Z")) private static boolean onCheckDisabled(List list, Object o, ResourcePackManager resourcePackManager) { String profileName = (String) o; diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinKeyedResourceReloadListener.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinKeyedResourceReloadListener.java deleted file mode 100644 index cc329acc2..000000000 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinKeyedResourceReloadListener.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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.Collection; -import java.util.Collections; -import java.util.Locale; - -import org.spongepowered.asm.mixin.Mixin; - -import net.minecraft.client.font.FontManager; -import net.minecraft.client.render.WorldRenderer; -import net.minecraft.client.render.block.BlockRenderManager; -import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.client.render.model.BakedModelManager; -import net.minecraft.client.resource.language.LanguageManager; -import net.minecraft.client.sound.SoundLoader; -import net.minecraft.client.texture.TextureManager; -import net.minecraft.recipe.RecipeManager; -import net.minecraft.server.ServerAdvancementLoader; -import net.minecraft.server.function.CommandFunctionManager; -import net.minecraft.tag.TagManagerLoader; -import net.minecraft.util.Identifier; -import net.minecraft.loot.LootManager; - -import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; -import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys; - -public class MixinKeyedResourceReloadListener { - @Mixin({ - /* public */ - SoundLoader.class, FontManager.class, BakedModelManager.class, LanguageManager.class, TextureManager.class, - /* private */ - WorldRenderer.class, BlockRenderManager.class, ItemRenderer.class - }) - public abstract static class Client implements IdentifiableResourceReloadListener { - private Collection fabric_idDeps; - private Identifier fabric_id; - - @Override - @SuppressWarnings({"ConstantConditions", "RedundantCast"}) - public Collection getFabricDependencies() { - if (fabric_idDeps == null) { - Object self = this; - - if (self instanceof BakedModelManager || self instanceof WorldRenderer) { - fabric_idDeps = Collections.singletonList(ResourceReloadListenerKeys.TEXTURES); - } else if (self instanceof ItemRenderer || self instanceof BlockRenderManager) { - fabric_idDeps = Collections.singletonList(ResourceReloadListenerKeys.MODELS); - } else { - fabric_idDeps = Collections.emptyList(); - } - } - - return fabric_idDeps; - } - - @Override - @SuppressWarnings({"ConstantConditions", "RedundantCast"}) - public Identifier getFabricId() { - if (fabric_id == null) { - Object self = this; - - if (self instanceof SoundLoader) { - fabric_id = ResourceReloadListenerKeys.SOUNDS; - } else if (self instanceof FontManager) { - fabric_id = ResourceReloadListenerKeys.FONTS; - } else if (self instanceof BakedModelManager) { - fabric_id = ResourceReloadListenerKeys.MODELS; - } else if (self instanceof LanguageManager) { - fabric_id = ResourceReloadListenerKeys.LANGUAGES; - } else if (self instanceof TextureManager) { - fabric_id = ResourceReloadListenerKeys.TEXTURES; - } else { - fabric_id = new Identifier("minecraft", "private/" + self.getClass().getSimpleName().toLowerCase(Locale.ROOT)); - } - } - - return fabric_id; - } - } - - @Mixin({ - /* public */ - RecipeManager.class, ServerAdvancementLoader.class, CommandFunctionManager.class, LootManager.class, TagManagerLoader.class - /* private */ - }) - public abstract static class Server implements IdentifiableResourceReloadListener { - private Collection fabric_idDeps; - private Identifier fabric_id; - - @Override - @SuppressWarnings({"ConstantConditions", "RedundantCast"}) - public Collection getFabricDependencies() { - if (fabric_idDeps == null) { - Object self = this; - - if (self instanceof TagManagerLoader) { - fabric_idDeps = Collections.emptyList(); - } else { - fabric_idDeps = Collections.singletonList(ResourceReloadListenerKeys.TAGS); - } - } - - return fabric_idDeps; - } - - @Override - @SuppressWarnings({"ConstantConditions", "RedundantCast"}) - public Identifier getFabricId() { - if (fabric_id == null) { - Object self = this; - - if (self instanceof RecipeManager) { - fabric_id = ResourceReloadListenerKeys.RECIPES; - } else if (self instanceof ServerAdvancementLoader) { - fabric_id = ResourceReloadListenerKeys.ADVANCEMENTS; - } else if (self instanceof CommandFunctionManager) { - fabric_id = ResourceReloadListenerKeys.FUNCTIONS; - } else if (self instanceof LootManager) { - fabric_id = ResourceReloadListenerKeys.LOOT_TABLES; - } else if (self instanceof TagManagerLoader) { - fabric_id = ResourceReloadListenerKeys.TAGS; - } else { - fabric_id = new Identifier("minecraft", "private/" + self.getClass().getSimpleName().toLowerCase(Locale.ROOT)); - } - } - - return fabric_id; - } - } -} diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinReloadableResourceManagerImplClient.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinReloadableResourceManagerImplClient.java deleted file mode 100644 index d411e1e9e..000000000 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinReloadableResourceManagerImplClient.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -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.callback.CallbackInfoReturnable; - -import net.minecraft.resource.ReloadableResourceManagerImpl; -import net.minecraft.resource.ResourceReloadListener; -import net.minecraft.resource.ResourceReloadMonitor; -import net.minecraft.resource.ResourceType; - -import net.fabricmc.fabric.impl.resource.loader.ResourceManagerHelperImpl; - -@Mixin(ReloadableResourceManagerImpl.class) -public class MixinReloadableResourceManagerImplClient { - @Shadow - private List listeners; - @Shadow - private List initialListeners; - @Shadow - private ResourceType type; - - @Inject(at = @At("HEAD"), method = "beginInitialMonitoredReload") - public void createReloadHandler(Executor executor_1, Executor executor_2, CompletableFuture completableFuture_1, CallbackInfoReturnable callback) { - ResourceManagerHelperImpl.sort(type, listeners); - ResourceManagerHelperImpl.sort(type, initialListeners); - } -} diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinReloadableResourceManagerImpl.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/ReloadableResourceManagerImplMixin.java similarity index 94% rename from fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinReloadableResourceManagerImpl.java rename to fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/ReloadableResourceManagerImplMixin.java index db1b47e0a..199535f51 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinReloadableResourceManagerImpl.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/ReloadableResourceManagerImplMixin.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; +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; @@ -33,7 +34,8 @@ import net.minecraft.resource.ResourceType; import net.fabricmc.fabric.impl.resource.loader.ResourceManagerHelperImpl; @Mixin(ReloadableResourceManagerImpl.class) -public class MixinReloadableResourceManagerImpl { +public class ReloadableResourceManagerImplMixin { + @Final @Shadow private ResourceType type; diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinResourcePackManager.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/ResourcePackManagerMixin.java similarity index 97% rename from fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinResourcePackManager.java rename to fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/ResourcePackManagerMixin.java index 3c2a00283..11813de92 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinResourcePackManager.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/ResourcePackManagerMixin.java @@ -37,7 +37,7 @@ import net.minecraft.resource.ResourceType; import net.fabricmc.fabric.impl.resource.loader.ModResourcePackCreator; @Mixin(ResourcePackManager.class) -public abstract class MixinResourcePackManager { +public abstract class ResourcePackManagerMixin { @Shadow @Final @Mutable diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinClientBuiltinResourcePackProvider.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/ClientBuiltinResourcePackProviderMixin.java similarity index 93% rename from fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinClientBuiltinResourcePackProvider.java rename to fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/ClientBuiltinResourcePackProviderMixin.java index 8d86f6d20..d113439d9 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinClientBuiltinResourcePackProvider.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/ClientBuiltinResourcePackProviderMixin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.mixin.resource.loader; +package net.fabricmc.fabric.mixin.resource.loader.client; import java.util.function.Consumer; @@ -29,7 +29,7 @@ import net.minecraft.client.resource.ClientBuiltinResourcePackProvider; import net.fabricmc.fabric.impl.resource.loader.ModResourcePackCreator; @Mixin(ClientBuiltinResourcePackProvider.class) -public class MixinClientBuiltinResourcePackProvider { +public class ClientBuiltinResourcePackProviderMixin { @Inject(method = "register", at = @At("RETURN")) private void addBuiltinResourcePacks(Consumer consumer, ResourcePackProfile.Factory factory, CallbackInfo ci) { // Register mod and built-in resource packs after the vanilla built-in resource packs are registered. diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinCreateWorldScreen.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/CreateWorldScreenMixin.java similarity index 95% rename from fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinCreateWorldScreen.java rename to fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/CreateWorldScreenMixin.java index aa2a9314e..f165d4bf2 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinCreateWorldScreen.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/CreateWorldScreenMixin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.mixin.resource.loader; +package net.fabricmc.fabric.mixin.resource.loader.client; import java.io.File; import java.util.ArrayList; @@ -37,9 +37,10 @@ import net.minecraft.resource.ResourceType; import net.fabricmc.fabric.impl.resource.loader.ModNioResourcePack; import net.fabricmc.fabric.impl.resource.loader.ModResourcePackCreator; +import net.fabricmc.fabric.mixin.resource.loader.ResourcePackManagerAccessor; @Mixin(CreateWorldScreen.class) -public class MixinCreateWorldScreen { +public class CreateWorldScreenMixin { @Shadow private ResourcePackManager field_25792; diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/FontManagerResourceReloadListenerMixin.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/FontManagerResourceReloadListenerMixin.java new file mode 100644 index 000000000..a424fa76f --- /dev/null +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/FontManagerResourceReloadListenerMixin.java @@ -0,0 +1,32 @@ +/* + * 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.client; + +import org.spongepowered.asm.mixin.Mixin; + +import net.minecraft.util.Identifier; + +import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; +import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys; + +@Mixin(targets = "net/minecraft/client/font/FontManager$1") +public abstract class FontManagerResourceReloadListenerMixin implements IdentifiableResourceReloadListener { + @Override + public Identifier getFabricId() { + return ResourceReloadListenerKeys.FONTS; + } +} diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinGameOptions.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/GameOptionsMixin.java similarity index 95% rename from fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinGameOptions.java rename to fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/GameOptionsMixin.java index 18ab8a86c..514761df7 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinGameOptions.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/GameOptionsMixin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.mixin.resource.loader; +package net.fabricmc.fabric.mixin.resource.loader.client; import java.util.ArrayList; import java.util.List; @@ -33,7 +33,7 @@ import net.fabricmc.fabric.impl.resource.loader.ModNioResourcePack; import net.fabricmc.fabric.impl.resource.loader.ModResourcePackCreator; @Mixin(GameOptions.class) -public class MixinGameOptions { +public class GameOptionsMixin { @Shadow public List resourcePacks; diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/KeyedResourceReloadListenerClientMixin.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/KeyedResourceReloadListenerClientMixin.java new file mode 100644 index 000000000..5225d8c2d --- /dev/null +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/KeyedResourceReloadListenerClientMixin.java @@ -0,0 +1,86 @@ +/* + * 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.client; + +import java.util.Collection; +import java.util.Collections; +import java.util.Locale; + +import org.spongepowered.asm.mixin.Mixin; + +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.render.block.BlockRenderManager; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.render.model.BakedModelManager; +import net.minecraft.client.resource.language.LanguageManager; +import net.minecraft.client.sound.SoundLoader; +import net.minecraft.client.texture.TextureManager; +import net.minecraft.util.Identifier; + +import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; +import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys; + +@Mixin({ + /* public */ + SoundLoader.class, BakedModelManager.class, LanguageManager.class, TextureManager.class, + /* private */ + WorldRenderer.class, BlockRenderManager.class, ItemRenderer.class +}) +public abstract class KeyedResourceReloadListenerClientMixin implements IdentifiableResourceReloadListener { + private Identifier fabric$id; + private Collection fabric$dependencies; + + @Override + @SuppressWarnings({"ConstantConditions", "RedundantCast"}) + public Identifier getFabricId() { + if (this.fabric$id == null) { + Object self = this; + + if (self instanceof SoundLoader) { + this.fabric$id = ResourceReloadListenerKeys.SOUNDS; + } else if (self instanceof BakedModelManager) { + this.fabric$id = ResourceReloadListenerKeys.MODELS; + } else if (self instanceof LanguageManager) { + this.fabric$id = ResourceReloadListenerKeys.LANGUAGES; + } else if (self instanceof TextureManager) { + this.fabric$id = ResourceReloadListenerKeys.TEXTURES; + } else { + this.fabric$id = new Identifier("minecraft", "private/" + self.getClass().getSimpleName().toLowerCase(Locale.ROOT)); + } + } + + return this.fabric$id; + } + + @Override + @SuppressWarnings({"ConstantConditions", "RedundantCast"}) + public Collection getFabricDependencies() { + if (this.fabric$dependencies == null) { + Object self = this; + + if (self instanceof BakedModelManager || self instanceof WorldRenderer) { + this.fabric$dependencies = Collections.singletonList(ResourceReloadListenerKeys.TEXTURES); + } else if (self instanceof ItemRenderer || self instanceof BlockRenderManager) { + this.fabric$dependencies = Collections.singletonList(ResourceReloadListenerKeys.MODELS); + } else { + this.fabric$dependencies = Collections.emptyList(); + } + } + + return this.fabric$dependencies; + } +} diff --git a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinPackScreen.java b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/PackScreenMixin.java similarity index 94% rename from fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinPackScreen.java rename to fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/PackScreenMixin.java index 39aa05580..e836235b9 100644 --- a/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/MixinPackScreen.java +++ b/fabric-resource-loader-v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/client/PackScreenMixin.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.mixin.resource.loader; +package net.fabricmc.fabric.mixin.resource.loader.client; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -28,7 +28,7 @@ import net.minecraft.client.gui.screen.pack.ResourcePackOrganizer; import net.fabricmc.fabric.impl.resource.loader.ModResourcePackCreator; @Mixin(PackScreen.class) -public class MixinPackScreen { +public class PackScreenMixin { @Inject(method = "method_29672", at = @At("HEAD"), cancellable = true) private void addPackEntry(PackListWidget packListWidget, ResourcePackOrganizer.Pack pack, CallbackInfo info) { // Every mod resource packs should be hidden from the user. 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 7508edecf..7784c015c 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 @@ -4,20 +4,21 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "FileResourcePackProviderAccessor", - "MixinDefaultResourcePack", - "MixinKeyedResourceReloadListener$Server", - "MixinMinecraftServer", - "MixinReloadableResourceManagerImpl", - "MixinResourcePackManager", + "DefaultResourcePackMixin", + "KeyedResourceReloadListenerMixin", + "MinecraftServerMixin", + "ReloadableResourceManagerImplMixin", + "ResourcePackManagerMixin", "ResourcePackManagerAccessor", "ResourcePackProfileAccessor" ], "client": [ - "MixinClientBuiltinResourcePackProvider", - "MixinCreateWorldScreen", - "MixinGameOptions", - "MixinKeyedResourceReloadListener$Client", - "MixinPackScreen" + "client.ClientBuiltinResourcePackProviderMixin", + "client.CreateWorldScreenMixin", + "client.FontManagerResourceReloadListenerMixin", + "client.GameOptionsMixin", + "client.KeyedResourceReloadListenerClientMixin", + "client.PackScreenMixin" ], "injectors": { "defaultRequire": 1