Move model loading to the correct event. Fixes #2991 (#2994)

* Use the correct event for loading models.
* Introduce IModelRegistry to wrap the ModelLoader
This commit is contained in:
fscan
2017-07-31 15:51:53 +02:00
committed by yueh
parent b13a338948
commit 5e001d86cb
21 changed files with 155 additions and 67 deletions
@@ -25,7 +25,7 @@ import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraftforge.fml.relauncher.Side;
public class BlockColorComponent implements InitComponent
public class BlockColorComponent implements IInitComponent
{
private final Block block;
@@ -33,7 +33,7 @@ import appeng.client.render.model.BuiltInModelLoader;
@SideOnly( Side.CLIENT )
public class BuiltInModelComponent implements PreInitComponent
public class BuiltInModelComponent implements IPreInitComponent
{
private final Map<String, IModel> builtInModels = new HashMap<>();
@@ -25,7 +25,7 @@ import appeng.bootstrap.IBootstrapComponent;
@FunctionalInterface
public interface InitComponent extends IBootstrapComponent
public interface IInitComponent extends IBootstrapComponent
{
@Override
@@ -0,0 +1,39 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 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, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 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 Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.bootstrap.components;
import net.minecraftforge.fml.relauncher.Side;
import appeng.bootstrap.IBootstrapComponent;
import appeng.bootstrap.IModelRegistry;
/**
* @author GuntherDW
*/
@FunctionalInterface
public interface IModelRegistrationComponent extends IBootstrapComponent
{
@Override
void modelRegistration( Side side, IModelRegistry registry );
}
@@ -25,7 +25,7 @@ import appeng.bootstrap.IBootstrapComponent;
@FunctionalInterface
public interface PostInitComponent extends IBootstrapComponent
public interface IPostInitComponent extends IBootstrapComponent
{
@Override
@@ -25,7 +25,7 @@ import appeng.bootstrap.IBootstrapComponent;
@FunctionalInterface
public interface PreInitComponent extends IBootstrapComponent
public interface IPreInitComponent extends IBootstrapComponent
{
@Override
@@ -25,7 +25,7 @@ import net.minecraft.item.Item;
import net.minecraftforge.fml.relauncher.Side;
public class ItemColorComponent implements InitComponent
public class ItemColorComponent implements IInitComponent
{
private final Item item;
@@ -21,17 +21,18 @@ package appeng.bootstrap.components;
import javax.annotation.Nonnull;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.item.Item;
import net.minecraftforge.fml.relauncher.Side;
import appeng.bootstrap.IModelRegistry;
/**
* Registers a custom item mesh definition that can be used to dynamically determine the item model based on
* item stack properties.
*/
public class ItemMeshDefinitionComponent implements InitComponent
public class ItemMeshDefinitionComponent implements IModelRegistrationComponent
{
private final Item item;
@@ -45,8 +46,8 @@ public class ItemMeshDefinitionComponent implements InitComponent
}
@Override
public void initialize( Side side )
public void modelRegistration( Side side, IModelRegistry registry )
{
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register( this.item, this.meshDefinition );
registry.setCustomMeshDefinition( this.item, this.meshDefinition );
}
}
@@ -23,18 +23,18 @@ import java.util.Map;
import javax.annotation.Nonnull;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.relauncher.Side;
import appeng.bootstrap.IModelRegistry;
/**
* Registers the models that should by used for an item, including the ability to
* distinguish by meta.
*/
public class ItemModelComponent implements InitComponent
public class ItemModelComponent implements IModelRegistrationComponent
{
private final Item item;
@@ -48,13 +48,11 @@ public class ItemModelComponent implements InitComponent
}
@Override
public void initialize( Side side )
public void modelRegistration( Side side, IModelRegistry registry )
{
ItemModelMesher itemMesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
this.modelsByMeta.forEach( ( meta, model ) ->
{
itemMesher.register( this.item, meta, model );
registry.setCustomModelResourceLocation( this.item, meta, model );
} );
}
@@ -21,15 +21,14 @@ package appeng.bootstrap.components;
import java.util.Collection;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import appeng.bootstrap.IBootstrapComponent;
import appeng.bootstrap.IModelRegistry;
public class ItemVariantsComponent implements IBootstrapComponent
public class ItemVariantsComponent implements IModelRegistrationComponent
{
private final Item item;
@@ -43,9 +42,9 @@ public class ItemVariantsComponent implements IBootstrapComponent
}
@Override
public void preInitialize( Side side )
public void modelRegistration( Side side, IModelRegistry registry )
{
ResourceLocation[] resourceArr = this.resources.toArray( new ResourceLocation[0] );
ModelBakery.registerItemVariants( this.item, resourceArr );
registry.registerItemVariants( this.item, resourceArr );
}
}
@@ -39,7 +39,7 @@ import net.minecraftforge.fml.relauncher.Side;
import appeng.core.AppEng;
public class ModelOverrideComponent implements PreInitComponent
public class ModelOverrideComponent implements IPreInitComponent
{
private static final ModelResourceLocation MODEL_MISSING = new ModelResourceLocation( "builtin/missing", "missing" );
@@ -1,21 +0,0 @@
package appeng.bootstrap.components;
import net.minecraftforge.fml.relauncher.Side;
import appeng.bootstrap.IBootstrapComponent;
/**
* @author GuntherDW
*/
@FunctionalInterface
public interface ModelRegComponent extends IBootstrapComponent
{
@Override
void modelReg( Side side );
}
@@ -24,14 +24,15 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.statemap.IStateMapper;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import appeng.bootstrap.IModelRegistry;
/**
* Registers a custom state mapper for a given block.
*/
public class StateMapperComponent implements ModelRegComponent
public class StateMapperComponent implements IModelRegistrationComponent
{
private final Block block;
@@ -45,9 +46,9 @@ public class StateMapperComponent implements ModelRegComponent
}
@Override
public void modelReg( Side side )
public void modelRegistration( Side side, IModelRegistry registry )
{
ModelLoader.setCustomStateMapper( this.block, this.stateMapper );
registry.setCustomStateMapper( this.block, this.stateMapper );
if( this.stateMapper instanceof IResourceManagerReloadListener )
{
( (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager() )
@@ -32,7 +32,7 @@ import appeng.tile.AEBaseTile;
* @param <T>
*/
// public class TesrComponent<T extends AEBaseTile> implements ModelRegComponent
public class TesrComponent<T extends AEBaseTile> implements PreInitComponent
public class TesrComponent<T extends AEBaseTile> implements IPreInitComponent
{
private final Class<T> tileEntityClass;
@@ -15,7 +15,7 @@ import appeng.core.AppEng;
/**
* @author GuntherDW
*/
public class TileEntityComponent implements PreInitComponent
public class TileEntityComponent implements IPreInitComponent
{
private List<TileEntityDefinition> tileEntityDefinitions = new ArrayList<>();