reformatted all src files (#141)
This commit is contained in:
@@ -19,15 +19,11 @@
|
||||
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 appeng.bootstrap.components.ItemColorComponent;
|
||||
import appeng.bootstrap.components.ItemMeshDefinitionComponent;
|
||||
import appeng.bootstrap.components.ItemModelComponent;
|
||||
import appeng.bootstrap.components.ItemVariantsComponent;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
@@ -41,137 +37,114 @@ import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.bootstrap.components.ItemColorComponent;
|
||||
import appeng.bootstrap.components.ItemMeshDefinitionComponent;
|
||||
import appeng.bootstrap.components.ItemModelComponent;
|
||||
import appeng.bootstrap.components.ItemVariantsComponent;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
class ItemRendering implements IItemRendering
|
||||
{
|
||||
class ItemRendering implements IItemRendering {
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private IItemColor itemColor;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IItemColor itemColor;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private ItemMeshDefinition itemMeshDefinition;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private ItemMeshDefinition itemMeshDefinition;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private Map<Integer, ModelResourceLocation> itemModels = new HashMap<>();
|
||||
@SideOnly(Side.CLIENT)
|
||||
private final Map<Integer, ModelResourceLocation> itemModels = new HashMap<>();
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private Set<ResourceLocation> variants = new HashSet<>();
|
||||
@SideOnly(Side.CLIENT)
|
||||
private final Set<ResourceLocation> variants = new HashSet<>();
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private Map<String, IModel> builtInModels = new HashMap<>();
|
||||
@SideOnly(Side.CLIENT)
|
||||
private final Map<String, IModel> builtInModels = new HashMap<>();
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public IItemRendering meshDefinition( ItemMeshDefinition meshDefinition )
|
||||
{
|
||||
this.itemMeshDefinition = meshDefinition;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IItemRendering meshDefinition(ItemMeshDefinition meshDefinition) {
|
||||
this.itemMeshDefinition = meshDefinition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public IItemRendering model( int meta, ModelResourceLocation model )
|
||||
{
|
||||
this.itemModels.put( meta, model );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IItemRendering model(int meta, ModelResourceLocation model) {
|
||||
this.itemModels.put(meta, model);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemRendering variants( Collection<ResourceLocation> resources )
|
||||
{
|
||||
this.variants.addAll( resources );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemRendering variants(Collection<ResourceLocation> resources) {
|
||||
this.variants.addAll(resources);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public IItemRendering color( IItemColor itemColor )
|
||||
{
|
||||
this.itemColor = itemColor;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IItemRendering color(IItemColor itemColor) {
|
||||
this.itemColor = itemColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemRendering builtInModel( String name, IModel model )
|
||||
{
|
||||
this.builtInModels.put( name, model );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemRendering builtInModel(String name, IModel model) {
|
||||
this.builtInModels.put(name, model);
|
||||
return this;
|
||||
}
|
||||
|
||||
void apply( FeatureFactory factory, Item item )
|
||||
{
|
||||
if( this.itemMeshDefinition != null )
|
||||
{
|
||||
factory.addBootstrapComponent( new ItemMeshDefinitionComponent( item, this.itemMeshDefinition ) );
|
||||
}
|
||||
void apply(FeatureFactory factory, Item item) {
|
||||
if (this.itemMeshDefinition != null) {
|
||||
factory.addBootstrapComponent(new ItemMeshDefinitionComponent(item, this.itemMeshDefinition));
|
||||
}
|
||||
|
||||
if( !this.itemModels.isEmpty() )
|
||||
{
|
||||
factory.addBootstrapComponent( new ItemModelComponent( item, this.itemModels ) );
|
||||
}
|
||||
if (!this.itemModels.isEmpty()) {
|
||||
factory.addBootstrapComponent(new ItemModelComponent(item, this.itemModels));
|
||||
}
|
||||
|
||||
Set<ResourceLocation> resources = new HashSet<>( this.variants );
|
||||
Set<ResourceLocation> resources = new HashSet<>(this.variants);
|
||||
|
||||
// Register a default item model if neither items by meta nor an item mesh definition exist
|
||||
if( this.itemMeshDefinition == null && this.itemModels.isEmpty() )
|
||||
{
|
||||
ModelResourceLocation model;
|
||||
// Register a default item model if neither items by meta nor an item mesh definition exist
|
||||
if (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 ItemBlock )
|
||||
{
|
||||
Block block = ( (ItemBlock) item ).getBlock();
|
||||
// For block items, the default will try to use the default state of the associated block
|
||||
if (item instanceof ItemBlock) {
|
||||
Block block = ((ItemBlock) item).getBlock();
|
||||
|
||||
// We can only do this once the blocks are actually registered...
|
||||
StateMapperHelper helper = new StateMapperHelper( item.getRegistryName() );
|
||||
model = helper.getModelResourceLocation( block.getDefaultState() );
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new ModelResourceLocation( item.getRegistryName(), "inventory" );
|
||||
}
|
||||
factory.addBootstrapComponent( new ItemModelComponent( item, ImmutableMap.of( 0, model ) ) );
|
||||
}
|
||||
// We can only do this once the blocks are actually registered...
|
||||
StateMapperHelper helper = new StateMapperHelper(item.getRegistryName());
|
||||
model = helper.getModelResourceLocation(block.getDefaultState());
|
||||
} else {
|
||||
model = new ModelResourceLocation(item.getRegistryName(), "inventory");
|
||||
}
|
||||
factory.addBootstrapComponent(new ItemModelComponent(item, ImmutableMap.of(0, model)));
|
||||
}
|
||||
|
||||
// TODO : 1.12
|
||||
this.builtInModels.forEach( factory::addBuiltInModel );
|
||||
// TODO : 1.12
|
||||
this.builtInModels.forEach(factory::addBuiltInModel);
|
||||
|
||||
if( !resources.isEmpty() )
|
||||
{
|
||||
factory.addBootstrapComponent( new ItemVariantsComponent( item, resources ) );
|
||||
}
|
||||
else if( this.itemMeshDefinition != null )
|
||||
{
|
||||
// Adding an empty variant list here will prevent Vanilla from trying to load the default item model in this
|
||||
// case
|
||||
factory.addBootstrapComponent( new ItemVariantsComponent( item, Collections.emptyList() ) );
|
||||
}
|
||||
if (!resources.isEmpty()) {
|
||||
factory.addBootstrapComponent(new ItemVariantsComponent(item, resources));
|
||||
} else if (this.itemMeshDefinition != null) {
|
||||
// Adding an empty variant list here will prevent Vanilla from trying to load the default item model in this
|
||||
// case
|
||||
factory.addBootstrapComponent(new ItemVariantsComponent(item, Collections.emptyList()));
|
||||
}
|
||||
|
||||
if( this.itemColor != null )
|
||||
{
|
||||
factory.addBootstrapComponent( new ItemColorComponent( item, this.itemColor ) );
|
||||
}
|
||||
}
|
||||
if (this.itemColor != null) {
|
||||
factory.addBootstrapComponent(new ItemColorComponent(item, this.itemColor));
|
||||
}
|
||||
}
|
||||
|
||||
private static class StateMapperHelper extends StateMapperBase
|
||||
{
|
||||
private static class StateMapperHelper extends StateMapperBase {
|
||||
|
||||
private final ResourceLocation registryName;
|
||||
private final ResourceLocation registryName;
|
||||
|
||||
public StateMapperHelper( ResourceLocation registryName )
|
||||
{
|
||||
this.registryName = registryName;
|
||||
}
|
||||
public StateMapperHelper(ResourceLocation registryName) {
|
||||
this.registryName = registryName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation( IBlockState state )
|
||||
{
|
||||
return new ModelResourceLocation( this.registryName, this.getPropertyString( state.getProperties() ) );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
|
||||
return new ModelResourceLocation(this.registryName, this.getPropertyString(state.getProperties()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user