-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix accessing existing reload listeners in server data reload
- Loading branch information
Showing
8 changed files
with
147 additions
and
69 deletions.
There are no files selected for viewing
37 changes: 0 additions & 37 deletions
37
...src/client/java/net/fabricmc/fabric/impl/client/resource/loader/ResourceLoaderClient.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
...c/main/java/net/fabricmc/fabric/impl/resource/loader/FabricLifecycledResourceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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 net.minecraft.resource.ResourceType; | ||
|
||
public interface FabricLifecycledResourceManager { | ||
ResourceType fabric_getResourceType(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...in/java/net/fabricmc/fabric/mixin/resource/loader/LifecycledResourceManagerImplMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
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.resource.LifecycledResourceManagerImpl; | ||
import net.minecraft.resource.ResourcePack; | ||
import net.minecraft.resource.ResourceType; | ||
|
||
import net.fabricmc.fabric.impl.resource.loader.FabricLifecycledResourceManager; | ||
|
||
@Mixin(LifecycledResourceManagerImpl.class) | ||
public class LifecycledResourceManagerImplMixin implements FabricLifecycledResourceManager { | ||
@Unique | ||
private ResourceType fabric_ResourceType; | ||
|
||
@Inject(method = "<init>", at = @At("TAIL")) | ||
private void init(ResourceType resourceType, List<ResourcePack> list, CallbackInfo ci) { | ||
this.fabric_ResourceType = resourceType; | ||
} | ||
|
||
@Override | ||
public ResourceType fabric_getResourceType() { | ||
return fabric_ResourceType; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...v0/src/main/java/net/fabricmc/fabric/mixin/resource/loader/SimpleResourceReloadMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import net.minecraft.resource.ProfiledResourceReload; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.resource.ResourceReload; | ||
import net.minecraft.resource.ResourceReloader; | ||
import net.minecraft.resource.ResourceType; | ||
import net.minecraft.resource.SimpleResourceReload; | ||
import net.minecraft.util.Unit; | ||
|
||
import net.fabricmc.fabric.impl.resource.loader.FabricLifecycledResourceManager; | ||
import net.fabricmc.fabric.impl.resource.loader.ResourceManagerHelperImpl; | ||
|
||
@Mixin(SimpleResourceReload.class) | ||
public class SimpleResourceReloadMixin { | ||
@Unique | ||
private static final ThreadLocal<ResourceType> fabric_resourceType = new ThreadLocal<>(); | ||
|
||
@Inject(method = "start", at = @At("HEAD")) | ||
private static void method_40087(ResourceManager resourceManager, List<ResourceReloader> list, Executor executor, Executor executor2, CompletableFuture<Unit> completableFuture, boolean bl, CallbackInfoReturnable<ResourceReload> cir) { | ||
if (resourceManager instanceof FabricLifecycledResourceManager flrm) { | ||
fabric_resourceType.set(flrm.fabric_getResourceType()); | ||
} | ||
} | ||
|
||
@ModifyArg(method = "start", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/SimpleResourceReload;create(Lnet/minecraft/resource/ResourceManager;Ljava/util/List;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;)Lnet/minecraft/resource/SimpleResourceReload;")) | ||
private static List<ResourceReloader> sortSimple(List<ResourceReloader> reloaders) { | ||
List<ResourceReloader> sorted = ResourceManagerHelperImpl.sort(fabric_resourceType.get(), reloaders); | ||
fabric_resourceType.set(null); | ||
return sorted; | ||
} | ||
|
||
@Redirect(method = "start", at = @At(value = "NEW", target = "Lnet/minecraft/resource/ProfiledResourceReload;<init>")) | ||
private static ProfiledResourceReload sortProfiled(ResourceManager manager, List<ResourceReloader> reloaders, Executor prepareExecutor, Executor applyExecutor, CompletableFuture<Unit> initialStage) { | ||
List<ResourceReloader> sorted = ResourceManagerHelperImpl.sort(fabric_resourceType.get(), reloaders); | ||
fabric_resourceType.set(null); | ||
return new ProfiledResourceReload(manager, sorted, prepareExecutor, applyExecutor, initialStage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters