This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Impl ModelBakeEvent, ModelRegistryEvent and some ModelLoader methods #106
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
23a5c0b
Impl ModelBakeEvent, ModelRegistryEvent and some ModelLoader methods
rikka0w0 60ef15a
Apply suggestions from code review
rikka0w0 8436199
Rename AbstractModelLoader to SpecialModelProvider
rikka0w0 eb30ed0
Simplify MixinModelLoader
rikka0w0 b6d7925
Add comments
rikka0w0 f527a90
Apply suggestions from code review
rikka0w0 63b6fd2
Update ModelEventDispatcher.java
rikka0w0 0dc0107
Better mixin target
TheGlitch76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,6 @@ | ||
| archivesBaseName = "patchwork-model-loader" | ||
| version = getSubprojectVersion(project, "0.1.0") | ||
|
|
||
| dependencies { | ||
| compile project(path: ':patchwork-fml', configuration: 'dev') | ||
| } |
59 changes: 59 additions & 0 deletions
59
patchwork-model-loader/src/main/java/net/minecraftforge/client/event/ModelBakeEvent.java
This file contains hidden or 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,59 @@ | ||
| /* | ||
| * Minecraft Forge, Patchwork Project | ||
| * Copyright (c) 2016-2020, 2019-2020 | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation version 2.1 | ||
| * of the License. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.minecraftforge.client.event; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import net.minecraftforge.client.model.ModelLoader; | ||
| import net.minecraftforge.eventbus.api.Event; | ||
|
|
||
| import net.minecraft.client.render.model.BakedModel; | ||
| import net.minecraft.client.render.model.BakedModelManager; | ||
| import net.minecraft.util.Identifier; | ||
|
|
||
| /** | ||
| * Fired when the BakedModelManager is notified of the resource manager reloading. | ||
| * Called after model registry is setup, but before it's passed to | ||
| * BlockModelShapes. | ||
| */ | ||
| public class ModelBakeEvent extends Event { | ||
| private final BakedModelManager modelManager; | ||
| private final Map<Identifier, BakedModel> modelRegistry; | ||
| private final ModelLoader modelLoader; | ||
|
|
||
| public ModelBakeEvent(BakedModelManager modelManager, Map<Identifier, BakedModel> modelRegistry, | ||
| ModelLoader modelLoader) { | ||
| this.modelManager = modelManager; | ||
| this.modelRegistry = modelRegistry; | ||
| this.modelLoader = modelLoader; | ||
| } | ||
|
|
||
| public BakedModelManager getModelManager() { | ||
| return modelManager; | ||
| } | ||
|
|
||
| public Map<Identifier, BakedModel> getModelRegistry() { | ||
| return modelRegistry; | ||
| } | ||
|
|
||
| public ModelLoader getModelLoader() { | ||
| return modelLoader; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
patchwork-model-loader/src/main/java/net/minecraftforge/client/event/ModelRegistryEvent.java
This file contains hidden or 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,29 @@ | ||
| /* | ||
| * Minecraft Forge, Patchwork Project | ||
| * Copyright (c) 2016-2020, 2019-2020 | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation version 2.1 | ||
| * of the License. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.minecraftforge.client.event; | ||
|
|
||
| import net.minecraftforge.eventbus.api.Event; | ||
|
|
||
| /** | ||
| * Fired when the {@link net.minecraftforge.client.model.ModelLoader} is ready | ||
| * to receive registrations. | ||
| */ | ||
| public class ModelRegistryEvent extends Event { | ||
| } |
109 changes: 109 additions & 0 deletions
109
patchwork-model-loader/src/main/java/net/minecraftforge/client/model/ModelLoader.java
This file contains hidden or 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,109 @@ | ||
| /* | ||
| * Minecraft Forge, Patchwork Project | ||
| * Copyright (c) 2016-2020, 2019-2020 | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation version 2.1 | ||
| * of the License. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.minecraftforge.client.model; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.apache.logging.log4j.Marker; | ||
| import org.apache.logging.log4j.MarkerManager; | ||
|
|
||
| import net.minecraft.client.color.block.BlockColors; | ||
| import net.minecraft.client.render.model.BakedModel; | ||
| import net.minecraft.client.texture.SpriteAtlasTexture; | ||
| import net.minecraft.client.util.ModelIdentifier; | ||
| import net.minecraft.resource.ResourceManager; | ||
| import net.minecraft.util.Identifier; | ||
| import net.minecraft.util.profiler.Profiler; | ||
|
|
||
| import net.patchworkmc.impl.modelloader.SpecialModelProvider; | ||
|
|
||
| public class ModelLoader extends net.minecraft.client.render.model.ModelLoader implements SpecialModelProvider { | ||
| private static final Marker MODELLOADING = MarkerManager.getMarker("MODELLOADING"); | ||
| private static Set<Identifier> specialModels = new HashSet<>(); | ||
| private static final Logger LOGGER = LogManager.getLogger(); | ||
| private final Map<Identifier, Exception> loadingExceptions = new HashMap<>(); | ||
| private boolean isLoading = false; | ||
| private static ModelLoader instance; | ||
|
|
||
| @Nullable | ||
| public static ModelLoader instance() { | ||
| return instance; | ||
| } | ||
|
|
||
| public boolean isLoading() { | ||
| return isLoading; | ||
| } | ||
|
|
||
| public ModelLoader(ResourceManager resourceManager, SpriteAtlasTexture spriteAtlas, BlockColors blockColors, | ||
| Profiler profiler) { | ||
| super(resourceManager, spriteAtlas, blockColors, profiler); | ||
| } | ||
|
|
||
| /** | ||
| * Indicate to vanilla that it should load and bake the given model, even if no | ||
| * blocks or items use it. This is useful if e.g. you have baked models only for | ||
| * entity renderers. Call during | ||
| * {@link net.minecraftforge.client.event.ModelRegistryEvent} | ||
| * | ||
| * @param rl The model, either {@link ModelResourceLocation} to point to a | ||
| * blockstate variant, or plain {@link ResourceLocation} to point | ||
| * directly to a json in the models folder. | ||
| */ | ||
| public static void addSpecialModel(Identifier rl) { | ||
| specialModels.add(rl); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<Identifier> getSpecialModels() { | ||
| return specialModels; | ||
| } | ||
|
|
||
| /** | ||
| * Internal, do not use. | ||
| */ | ||
| public void onPostBakeEvent(Map<Identifier, BakedModel> modelRegistry) { | ||
| BakedModel missingModel = modelRegistry.get(MISSING); | ||
|
|
||
| for (Map.Entry<Identifier, Exception> entry : loadingExceptions.entrySet()) { | ||
| // ignoring pure Identifier arguments, all things we care about pass | ||
| // ModelIdentifier | ||
| if (entry.getKey() instanceof ModelIdentifier) { | ||
| LOGGER.debug(MODELLOADING, "Model {} failed to load: {}", entry.getKey().toString(), | ||
| entry.getValue().getLocalizedMessage()); | ||
| final ModelIdentifier location = (ModelIdentifier) entry.getKey(); | ||
| final BakedModel model = modelRegistry.get(location); | ||
|
|
||
| if (model == null) { | ||
| modelRegistry.put(location, missingModel); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| loadingExceptions.clear(); | ||
| isLoading = false; | ||
| } | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
...ork-model-loader/src/main/java/net/patchworkmc/impl/modelloader/ModelEventDispatcher.java
This file contains hidden or 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 @@ | ||
| /* | ||
| * Minecraft Forge, Patchwork Project | ||
| * Copyright (c) 2016-2020, 2019-2020 | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation version 2.1 | ||
| * of the License. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.patchworkmc.impl.modelloader; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import net.minecraftforge.client.event.ModelBakeEvent; | ||
| import net.minecraftforge.client.event.ModelRegistryEvent; | ||
| import net.minecraftforge.client.model.ModelLoader; | ||
| import net.minecraftforge.fml.ModLoader; | ||
|
|
||
| import net.minecraft.client.render.model.BakedModel; | ||
| import net.minecraft.client.render.model.BakedModelManager; | ||
| import net.minecraft.util.Identifier; | ||
|
|
||
| public class ModelEventDispatcher { | ||
| /** | ||
| * In Forge, ModelRegistryEvent is fired in parallel with FMLClientSetupEvent. | ||
| * Here we fire ModelRegistryEvent before FMLClientSetupEvent. | ||
| * The official forge does not set the ModLoadingContext here, so this should be fine. | ||
rikka0w0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| public static void fireModelRegistryEvent() { | ||
| ModLoader.get().postEvent(new ModelRegistryEvent()); | ||
| } | ||
|
|
||
| public static void onModelBake(BakedModelManager modelManager, Map<Identifier, BakedModel> modelRegistry, ModelLoader modelLoader) { | ||
| ModLoader.get().postEvent(new ModelBakeEvent(modelManager, modelRegistry, modelLoader)); | ||
| modelLoader.onPostBakeEvent(modelRegistry); | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
patchwork-model-loader/src/main/java/net/patchworkmc/impl/modelloader/Signatures.java
This file contains hidden or 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,34 @@ | ||
| /* | ||
| * Minecraft Forge, Patchwork Project | ||
| * Copyright (c) 2016-2020, 2019-2020 | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation version 2.1 | ||
| * of the License. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.patchworkmc.impl.modelloader; | ||
|
|
||
| public class Signatures { | ||
| public static final String Profiler_swap = "net/minecraft/util/profiler/Profiler.swap(Ljava/lang/String;)V"; | ||
|
|
||
| public static final String ModelLoader_new = "(" | ||
| + "Lnet/minecraft/resource/ResourceManager;" | ||
| + "Lnet/minecraft/client/texture/SpriteAtlasTexture;" | ||
| + "Lnet/minecraft/client/color/block/BlockColors;" | ||
| + "Lnet/minecraft/util/profiler/Profiler;" | ||
| + ")" | ||
| + "Lnet/minecraft/client/render/model/ModelLoader;"; | ||
|
|
||
| public static final String ModelLoader_addModel = "net/minecraft/client/render/model/ModelLoader.addModel(Lnet/minecraft/client/util/ModelIdentifier;)V"; | ||
| } |
30 changes: 30 additions & 0 deletions
30
...ork-model-loader/src/main/java/net/patchworkmc/impl/modelloader/SpecialModelProvider.java
This file contains hidden or 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,30 @@ | ||
| /* | ||
| * Minecraft Forge, Patchwork Project | ||
| * Copyright (c) 2016-2020, 2019-2020 | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation version 2.1 | ||
| * of the License. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.patchworkmc.impl.modelloader; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| import net.minecraft.util.Identifier; | ||
|
|
||
| public interface SpecialModelProvider { | ||
| default Set<Identifier> getSpecialModels() { | ||
| return java.util.Collections.emptySet(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.