mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
Make Fabric mod data packs automatically enable on world creation, allow mod data packs to load on dedicated servers (#663)
* make mod data packs load on dedi servers, auto-enable * license headers
This commit is contained in:
parent
d6bf72d59b
commit
3d52d1e569
6 changed files with 112 additions and 17 deletions
fabric-resource-loader-v0/src/main
java/net/fabricmc/fabric
impl/resource/loader
mixin/resource/loader
resources
|
@ -20,11 +20,11 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.class_5352;
|
||||
import net.minecraft.resource.ResourcePack;
|
||||
import net.minecraft.resource.ResourcePackProfile;
|
||||
import net.minecraft.resource.ResourcePackProvider;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
||||
import net.fabricmc.fabric.api.resource.ModResourcePack;
|
||||
|
||||
|
@ -47,7 +47,8 @@ public class ModResourcePackCreator implements ResourcePackProvider {
|
|||
}
|
||||
|
||||
T var3 = ResourcePackProfile.of("fabric/" + ((ModResourcePack) pack).getFabricModMetadata().getId(),
|
||||
false, () -> pack, factory, ResourcePackProfile.InsertionPosition.TOP, class_5352.field_25348);
|
||||
false, () -> pack, factory, ResourcePackProfile.InsertionPosition.TOP,
|
||||
text -> new TranslatableText("pack.nameAndSource", text, new TranslatableText("pack.source.fabricmod")));
|
||||
|
||||
if (var3 != null) {
|
||||
consumer.accept(var3);
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
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.CallbackInfo;
|
||||
|
||||
import net.minecraft.class_5359;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
|
||||
@Mixin(class_5359.class)
|
||||
public class MixinClass_5359 {
|
||||
@Shadow
|
||||
@Final
|
||||
@Mutable
|
||||
private List<String> field_25395;
|
||||
|
||||
/*
|
||||
This injection takes all instances of this class with an enabled list that only have the vanilla pack enabled,
|
||||
and forcibly enables all mod resource packs. This is probably not the best option, but it's the only one that I can
|
||||
think of that will work on both existing and new worlds. Is there a better option?
|
||||
*/
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void init(List<String> enabled, List<String> disabled, CallbackInfo info) {
|
||||
if (enabled.size() == 1 && enabled.get(0).equals("vanilla")) {
|
||||
List<String> newEnabled = new ArrayList<>(enabled);
|
||||
|
||||
for (ModContainer container : FabricLoader.getInstance().getAllMods()) {
|
||||
if (!container.getMetadata().getType().equals("builtin")) {
|
||||
newEnabled.add("fabric/" + container.getMetadata().getId());
|
||||
}
|
||||
}
|
||||
|
||||
this.field_25395 = newEnabled;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,9 +16,7 @@
|
|||
|
||||
package net.fabricmc.fabric.mixin.resource.loader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
|
@ -28,15 +26,12 @@ 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.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.resource.ResourcePack;
|
||||
import net.minecraft.resource.ResourcePackManager;
|
||||
import net.minecraft.resource.ResourcePackProfile;
|
||||
import net.minecraft.resource.ResourcePackProvider;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
|
||||
import net.fabricmc.fabric.impl.resource.loader.ModResourcePackUtil;
|
||||
import net.fabricmc.fabric.impl.resource.loader.ModResourcePackCreator;
|
||||
|
||||
@Mixin(ResourcePackManager.class)
|
||||
|
@ -51,11 +46,4 @@ public class MixinResourcePackManager<T extends ResourcePackProfile> {
|
|||
providers = new HashSet<>(providers);
|
||||
providers.add(new ModResourcePackCreator(ResourceType.SERVER_DATA));
|
||||
}
|
||||
|
||||
@Inject(method = "method_29211", at = @At("RETURN"), cancellable = true)
|
||||
public void method_29211(CallbackInfoReturnable<List<ResourcePack>> infoReturnable) {
|
||||
List<ResourcePack> list = new ArrayList<>(infoReturnable.getReturnValue());
|
||||
ModResourcePackUtil.modifyResourcePackList(list);
|
||||
infoReturnable.setReturnValue(list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
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.ResourcePack;
|
||||
import net.minecraft.resource.ResourcePackManager;
|
||||
|
||||
import net.fabricmc.fabric.impl.resource.loader.ModResourcePackUtil;
|
||||
|
||||
@Mixin(ResourcePackManager.class)
|
||||
public class MixinResourcePackManagerClient {
|
||||
@Inject(method = "method_29211", at = @At("RETURN"), cancellable = true)
|
||||
public void method_29211(CallbackInfoReturnable<List<ResourcePack>> infoReturnable) {
|
||||
List<ResourcePack> list = new ArrayList<>(infoReturnable.getReturnValue());
|
||||
ModResourcePackUtil.modifyResourcePackList(list);
|
||||
infoReturnable.setReturnValue(list);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"pack.source.fabricmod": "Fabric mod"
|
||||
}
|
|
@ -3,15 +3,17 @@
|
|||
"package": "net.fabricmc.fabric.mixin.resource.loader",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"MixinClass_5359",
|
||||
"MixinDefaultResourcePack",
|
||||
"MixinKeyedResourceReloadListener$Server",
|
||||
"MixinReloadableResourceManagerImpl",
|
||||
"MixinDefaultResourcePack"
|
||||
"MixinResourcePackManager"
|
||||
],
|
||||
"client": [
|
||||
"MixinFormat4ResourcePack",
|
||||
"MixinKeyedResourceReloadListener$Client",
|
||||
"MixinResourcePackManager",
|
||||
"MixinMinecraftGame"
|
||||
"MixinMinecraftGame",
|
||||
"MixinResourcePackManagerClient"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue