Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions patchwork-dispatcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dependencies {
compile project(path: ':patchwork-registries', configuration: 'dev')
compile project(path: ':patchwork-events-lifecycle', configuration: 'dev')
compile project(path: ':patchwork-events-rendering', configuration: 'dev')
compile project(path: ':patchwork-model-loader', configuration: 'dev')
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import net.patchworkmc.api.ForgeInitializer;
import net.patchworkmc.impl.event.lifecycle.LifecycleEvents;
import net.patchworkmc.impl.event.render.RenderEvents;
import net.patchworkmc.impl.modelloader.ModelEventDispatcher;
import net.patchworkmc.impl.registries.RegistryEventDispatcher;

public class Patchwork implements ModInitializer {
Expand Down Expand Up @@ -122,6 +123,7 @@ public void onInitialize() {
dispatch(mods, FMLCommonSetupEvent::new);

DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
ModelEventDispatcher.fireModelRegistryEvent();
dispatch(mods, container -> new FMLClientSetupEvent(MinecraftClient::getInstance, container));
RenderEvents.registerEventDispatcher(event -> dispatch(mods, event));
});
Expand Down
6 changes: 6 additions & 0 deletions patchwork-model-loader/build.gradle
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')
}
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;
}
}
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 {
}
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;
}
}
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.
*/
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);
}
}
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";
}
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();
}
}
Loading