Basic JEI integration is back

This commit is contained in:
Sebastian Hartte
2020-06-10 20:27:19 +02:00
parent 19e7fd3544
commit 8ccc114f92
280 changed files with 1945 additions and 1374 deletions
@@ -35,10 +35,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -51,9 +48,6 @@ class BlockRendering implements IBlockRendering
@OnlyIn( Dist.CLIENT )
private IBlockColor blockColor;
@OnlyIn( Dist.CLIENT )
private Map<String, IUnbakedModel> builtInModels = new HashMap<>();
@OnlyIn( Dist.CLIENT )
private RenderType renderType;
@@ -76,13 +70,6 @@ class BlockRendering implements IBlockRendering
return this;
}
@Override
public IBlockRendering builtInModel( String name, IUnbakedModel model )
{
this.builtInModels.put( name, model );
return this;
}
@Override
public IBlockRendering renderType(RenderType type) {
this.renderType = type;
@@ -108,8 +95,6 @@ class BlockRendering implements IBlockRendering
factory.addModelOverride( block.getRegistryName().getPath(), ( l, m ) -> new AutoRotatingBakedModel( m ) );
}
this.builtInModels.forEach( factory::addBuiltInModel );
// TODO : 1.12
if( this.blockColor != null )
{
@@ -30,7 +30,6 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import appeng.bootstrap.components.BuiltInModelComponent;
import appeng.bootstrap.components.ModelOverrideComponent;
import appeng.tile.AEBaseTile;
import net.minecraft.block.Block;
@@ -42,17 +41,10 @@ import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.api.definitions.IItemDefinition;
import appeng.api.util.AEColor;
import appeng.api.util.AEColoredItemDefinition;
import appeng.api.features.AEFeature;
import appeng.core.features.ActivityState;
import appeng.core.features.ColoredItemDefinition;
import appeng.core.features.ItemStackSrc;
import appeng.util.Platform;
@@ -66,9 +58,6 @@ public class FeatureFactory
@OnlyIn( Dist.CLIENT )
private ModelOverrideComponent modelOverrideComponent;
@OnlyIn( Dist.CLIENT )
private BuiltInModelComponent builtInModelComponent;
public FeatureFactory()
{
this.defaultFeatures = new AEFeature[] { AEFeature.CORE };
@@ -78,8 +67,6 @@ public class FeatureFactory
{
this.modelOverrideComponent = new ModelOverrideComponent();
this.addBootstrapComponent( this.modelOverrideComponent );
this.builtInModelComponent = new BuiltInModelComponent();
this.addBootstrapComponent( this.builtInModelComponent );
}
}
@@ -90,7 +77,6 @@ public class FeatureFactory
if( Platform.hasClientClasses() )
{
this.modelOverrideComponent = parent.modelOverrideComponent;
this.builtInModelComponent = parent.builtInModelComponent;
}
}
@@ -131,12 +117,6 @@ public class FeatureFactory
this.bootstrapComponents.computeIfAbsent( eventType, c -> new ArrayList<IBootstrapComponent>() ).add( component );
}
@OnlyIn( Dist.CLIENT )
void addBuiltInModel( String path, IUnbakedModel model )
{
this.builtInModelComponent.addModel( path, model );
}
@OnlyIn( Dist.CLIENT )
void addModelOverride( String resourcePath, BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer )
{
@@ -47,12 +47,6 @@ public interface IBlockRendering
@OnlyIn( Dist.CLIENT )
IBlockRendering blockColor( IBlockColor blockColor );
/**
* Registers a built-in model under the given resource path.
*/
@OnlyIn( Dist.CLIENT )
IBlockRendering builtInModel( String name, IUnbakedModel model );
@OnlyIn( Dist.CLIENT )
IBlockRendering renderType(RenderType type);
@@ -23,8 +23,6 @@ import java.util.Arrays;
import java.util.Collection;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.client.renderer.model.IUnbakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -36,29 +34,6 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public interface IItemRendering
{
/**
* Registers a custom item mesh definition that will be used to dynamically determine the
* item model to be used for rendering by inspecting the item stack (i.e. for NBT data).
* Please
*/
//FIXME @OnlyIn( Dist.CLIENT )
//FIXME IItemRendering meshDefinition( ItemMeshDefinition meshDefinition );
/**
* Registers an item model for meta=0, see {@link #model(int, ModelResourceLocation)}.
*/
@OnlyIn( Dist.CLIENT )
default IItemRendering model( ModelResourceLocation model )
{
return this.model( 0, model );
}
/**
* Registers an item model for a given meta.
*/
@OnlyIn( Dist.CLIENT )
IItemRendering model( int meta, ModelResourceLocation model );
/**
* Convenient override for {@link #variants(Collection)}.
*/
@@ -72,8 +47,6 @@ public interface IItemRendering
* Registers the item variants of this item. This are all models that need to be loaded for this item.
* This has no direct effect on rendering, but is used to load models that are used for example by
* the ItemMeshDefinition.
*
* Models registered via {@link #model(int, ModelResourceLocation)} are automatically added here.
*/
@OnlyIn( Dist.CLIENT )
IItemRendering variants( Collection<ResourceLocation> resources );
@@ -85,10 +58,4 @@ public interface IItemRendering
@OnlyIn( Dist.CLIENT )
IItemRendering color( IItemColor itemColor );
/**
* Registers a built-in model under the given resource path.
*/
@OnlyIn( Dist.CLIENT )
IItemRendering builtInModel( String name, IUnbakedModel model );
}
@@ -29,7 +29,4 @@ public interface IModelRegistry
{
void registerItemVariants( Item item, ResourceLocation... names );
void setCustomModelResourceLocation( Item item, int metadata, ModelResourceLocation model );
// FIXME void setCustomMeshDefinition( Item item, ItemMeshDefinition meshDefinition );
}
@@ -20,29 +20,16 @@ package appeng.bootstrap;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.ImmutableMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.client.renderer.model.IUnbakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.bootstrap.components.ItemColorComponent;
import appeng.bootstrap.components.ItemMeshDefinitionComponent;
import appeng.bootstrap.components.ItemModelComponent;
import appeng.bootstrap.components.ItemVariantsComponent;
@@ -52,36 +39,9 @@ class ItemRendering implements IItemRendering
@OnlyIn( Dist.CLIENT )
private IItemColor itemColor;
// FIXME
// @OnlyIn( Dist.CLIENT )
// private ItemMeshDefinition itemMeshDefinition;
@OnlyIn( Dist.CLIENT )
private Map<Integer, ModelResourceLocation> itemModels = new HashMap<>();
@OnlyIn( Dist.CLIENT )
private Set<ResourceLocation> variants = new HashSet<>();
@OnlyIn( Dist.CLIENT )
private Map<String, IUnbakedModel> builtInModels = new HashMap<>();
// FIXME
// @Override
// @OnlyIn( Dist.CLIENT )
// public IItemRendering meshDefinition( ItemMeshDefinition meshDefinition )
// {
// this.itemMeshDefinition = meshDefinition;
// return this;
// }
@Override
@OnlyIn( Dist.CLIENT )
public IItemRendering model( int meta, ModelResourceLocation model )
{
this.itemModels.put( meta, model );
return this;
}
@Override
public IItemRendering variants( Collection<ResourceLocation> resources )
{
@@ -97,65 +57,14 @@ class ItemRendering implements IItemRendering
return this;
}
@Override
public IItemRendering builtInModel( String name, IUnbakedModel model )
{
this.builtInModels.put( name, model );
return this;
}
void apply( FeatureFactory factory, Item item )
{
//FIXME if( this.itemMeshDefinition != null )
//FIXME {
//FIXME factory.addBootstrapComponent( new ItemMeshDefinitionComponent( item, this.itemMeshDefinition ) );
//FIXME }
if( !this.itemModels.isEmpty() )
{
factory.addBootstrapComponent( new ItemModelComponent( item, this.itemModels ) );
}
Set<ResourceLocation> resources = new HashSet<>( this.variants );
// Register a default item model if neither items by meta nor an item mesh definition exist
if( /* FIXME this.itemMeshDefinition == null && */ this.itemModels.isEmpty() )
{
// ModelResourceLocation model;
//
// // For block items, the default will try to use the default state of the associated block
// if( item instanceof BlockItem )
// {
// Block block = ( (BlockItem) item ).getBlock();
//
// // We can only do this once the blocks are actually registered...
// model = new ModelResourceLocation(
// new ResourceLocation(
// block.getRegistryName().getNamespace(),
// "block/" + block.getRegistryName().getPath()
// )
// , "inventory" );
// }
// else
// {
// model = new ModelResourceLocation( item.getRegistryName(), "inventory" );
// }
// factory.addBootstrapComponent( new ItemModelComponent( item, ImmutableMap.of( 0, model ) ) );
}
// TODO : 1.12
this.builtInModels.forEach( factory::addBuiltInModel );
if( !resources.isEmpty() )
{
factory.addBootstrapComponent( new ItemVariantsComponent( item, resources ) );
}
// FIXME else if( this.itemMeshDefinition != null )
// FIXME {
// FIXME // Adding an empty variant list here will prevent Vanilla from trying to load the default item model in this
// FIXME // case
// FIXME factory.addBootstrapComponent( new ItemVariantsComponent( item, Collections.emptyList() ) );
// FIXME }
if( this.itemColor != null )
{
@@ -1,52 +0,0 @@
/*
* 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 com.google.common.base.Preconditions;
import net.minecraft.client.renderer.model.IUnbakedModel;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.HashMap;
import java.util.Map;
@OnlyIn( Dist.CLIENT )
public class BuiltInModelComponent implements IPreInitComponent
{
private final Map<String, IUnbakedModel> builtInModels = new HashMap<>();
private boolean hasInitialized = false;
public void addModel( String path, IUnbakedModel model )
{
Preconditions.checkState( !this.hasInitialized );
this.builtInModels.put( path, model );
}
@Override
public void preInitialize( Dist dist )
{
this.hasInitialized = true;
//
// BuiltInModelLoader loader = new BuiltInModelLoader( this.builtInModels );
// ModelLoaderRegistry.registerLoader( loader );
}
}
@@ -1,31 +0,0 @@
/*
* 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.api.distmarker.Dist;
import appeng.bootstrap.IBootstrapComponent;
@FunctionalInterface
public interface IPreInitComponent extends IBootstrapComponent
{
void preInitialize( Dist dist );
}
@@ -1,59 +0,0 @@
/*
* 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 java.util.Map;
import javax.annotation.Nonnull;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.api.distmarker.Dist;
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 IModelRegistrationComponent
{
private final Item item;
private final Map<Integer, ModelResourceLocation> modelsByMeta;
public ItemModelComponent( @Nonnull Item item, @Nonnull Map<Integer, ModelResourceLocation> modelsByMeta )
{
this.item = item;
this.modelsByMeta = modelsByMeta;
}
@Override
public void modelRegistration( Dist dist, IModelRegistry registry )
{
this.modelsByMeta.forEach( ( meta, model ) ->
{
registry.setCustomModelResourceLocation( this.item, meta, model );
} );
}
}