mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-23 16:18:29 -05:00
Internal refactor, remove legacy code, fix FabricMC/fabric#878. (#1134)
This commit is contained in:
parent
c2f49c1532
commit
05f948543b
19 changed files with 242 additions and 463 deletions
|
@ -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<InputStream> streamSupplier) throws IOException {
|
||||
if (DeferredNioExecutionHandler.shouldDefer()) {
|
||||
return new DeferredInputStream(streamSupplier);
|
||||
} else {
|
||||
return DeferredNioExecutionHandler.submit(streamSupplier, false);
|
||||
}
|
||||
}
|
||||
|
||||
DeferredInputStream(Callable<InputStream> 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;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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<Boolean> 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> V submit(Callable<V> 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> V submit(Callable<V> callable) throws IOException {
|
||||
if (EXECUTOR_SERVICE == null) {
|
||||
EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(
|
||||
new ThreadFactoryBuilder()
|
||||
.setNameFormat("Fabric Deferred I/O Thread")
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
Future<V> future = EXECUTOR_SERVICE.submit(callable);
|
||||
return getSubmittedFuture(future);
|
||||
}
|
||||
|
||||
static <V> V getSubmittedFuture(Future<V> 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...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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,27 +77,11 @@ 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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ResourceType, ResourceManagerHelperImpl> 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;
|
||||
}
|
||||
|
|
|
@ -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<InputStream> callback) {
|
||||
if (DefaultResourcePack.resourcePath != null) {
|
|
@ -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<Identifier> 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<Identifier> 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;
|
||||
}
|
||||
}
|
|
@ -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<String> list, Object o, ResourcePackManager resourcePackManager) {
|
||||
String profileName = (String) o;
|
|
@ -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<Identifier> fabric_idDeps;
|
||||
private Identifier fabric_id;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"ConstantConditions", "RedundantCast"})
|
||||
public Collection<Identifier> 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<Identifier> fabric_idDeps;
|
||||
private Identifier fabric_id;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"ConstantConditions", "RedundantCast"})
|
||||
public Collection<Identifier> 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<ResourceReloadListener> listeners;
|
||||
@Shadow
|
||||
private List<ResourceReloadListener> initialListeners;
|
||||
@Shadow
|
||||
private ResourceType type;
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "beginInitialMonitoredReload")
|
||||
public void createReloadHandler(Executor executor_1, Executor executor_2, CompletableFuture<Void> completableFuture_1, CallbackInfoReturnable<ResourceReloadMonitor> callback) {
|
||||
ResourceManagerHelperImpl.sort(type, listeners);
|
||||
ResourceManagerHelperImpl.sort(type, initialListeners);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
@ -37,7 +37,7 @@ import net.minecraft.resource.ResourceType;
|
|||
import net.fabricmc.fabric.impl.resource.loader.ModResourcePackCreator;
|
||||
|
||||
@Mixin(ResourcePackManager.class)
|
||||
public abstract class MixinResourcePackManager<T extends ResourcePackProfile> {
|
||||
public abstract class ResourcePackManagerMixin<T extends ResourcePackProfile> {
|
||||
@Shadow
|
||||
@Final
|
||||
@Mutable
|
|
@ -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<ResourcePackProfile> consumer, ResourcePackProfile.Factory factory, CallbackInfo ci) {
|
||||
// Register mod and built-in resource packs after the vanilla built-in resource packs are registered.
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<String> resourcePacks;
|
||||
|
|
@ -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<Identifier> 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<Identifier> 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;
|
||||
}
|
||||
}
|
|
@ -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.
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue