reformatted all src files (#141)
This commit is contained in:
@@ -19,25 +19,6 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.block.AEBaseItemBlock;
|
||||
@@ -49,233 +30,209 @@ import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.ActivityState;
|
||||
import appeng.core.features.BlockDefinition;
|
||||
import appeng.core.features.BlockStackSrc;
|
||||
import appeng.core.features.TileDefinition;
|
||||
import appeng.core.features.*;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
class BlockDefinitionBuilder implements IBlockBuilder
|
||||
{
|
||||
class BlockDefinitionBuilder implements IBlockBuilder {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final String registryName;
|
||||
private final String registryName;
|
||||
|
||||
private final Supplier<? extends Block> blockSupplier;
|
||||
private final Supplier<? extends Block> blockSupplier;
|
||||
|
||||
private final List<BiFunction<Block, Item, IBootstrapComponent>> bootstrapComponents = new ArrayList<>();
|
||||
private final List<BiFunction<Block, Item, IBootstrapComponent>> bootstrapComponents = new ArrayList<>();
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf( AEFeature.class );
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
private CreativeTabs creativeTab = CreativeTab.instance;
|
||||
private final CreativeTabs creativeTab = CreativeTab.instance;
|
||||
|
||||
private TileEntityDefinition tileEntityDefinition;
|
||||
private TileEntityDefinition tileEntityDefinition;
|
||||
|
||||
private boolean disableItem = false;
|
||||
private boolean disableItem = false;
|
||||
|
||||
private Function<Block, ItemBlock> itemFactory;
|
||||
private Function<Block, ItemBlock> itemFactory;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private BlockRendering blockRendering;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private BlockRendering blockRendering;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private ItemRendering itemRendering;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private ItemRendering itemRendering;
|
||||
|
||||
BlockDefinitionBuilder( FeatureFactory factory, String id, Supplier<? extends Block> blockSupplier )
|
||||
{
|
||||
this.factory = factory;
|
||||
this.registryName = id;
|
||||
this.blockSupplier = blockSupplier;
|
||||
BlockDefinitionBuilder(FeatureFactory factory, String id, Supplier<? extends Block> blockSupplier) {
|
||||
this.factory = factory;
|
||||
this.registryName = id;
|
||||
this.blockSupplier = blockSupplier;
|
||||
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
this.blockRendering = new BlockRendering();
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
if (Platform.isClient()) {
|
||||
this.blockRendering = new BlockRendering();
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockDefinitionBuilder bootstrap( BiFunction<Block, Item, IBootstrapComponent> callback )
|
||||
{
|
||||
this.bootstrapComponents.add( callback );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public BlockDefinitionBuilder bootstrap(BiFunction<Block, Item, IBootstrapComponent> callback) {
|
||||
this.bootstrapComponents.add(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder features( AEFeature... features )
|
||||
{
|
||||
this.features.clear();
|
||||
this.addFeatures( features );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockBuilder features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder addFeatures( AEFeature... features )
|
||||
{
|
||||
Collections.addAll( this.features, features );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockBuilder addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockDefinitionBuilder rendering( BlockRenderingCustomizer callback )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
this.customizeForClient( callback );
|
||||
}
|
||||
@Override
|
||||
public BlockDefinitionBuilder rendering(BlockRenderingCustomizer callback) {
|
||||
if (Platform.isClient()) {
|
||||
this.customizeForClient(callback);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder tileEntity( TileEntityDefinition tileEntityDefinition )
|
||||
{
|
||||
this.tileEntityDefinition = tileEntityDefinition;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockBuilder tileEntity(TileEntityDefinition tileEntityDefinition) {
|
||||
this.tileEntityDefinition = tileEntityDefinition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder useCustomItemModel()
|
||||
{
|
||||
this.rendering( new BlockRenderingCustomizer()
|
||||
{
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
ModelResourceLocation model = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, BlockDefinitionBuilder.this.registryName ), "inventory" );
|
||||
itemRendering.model( model ).variants( model );
|
||||
}
|
||||
} );
|
||||
@Override
|
||||
public IBlockBuilder useCustomItemModel() {
|
||||
this.rendering(new BlockRenderingCustomizer() {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
|
||||
ModelResourceLocation model = new ModelResourceLocation(new ResourceLocation(AppEng.MOD_ID, BlockDefinitionBuilder.this.registryName), "inventory");
|
||||
itemRendering.model(model).variants(model);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder item( Function<Block, ItemBlock> factory )
|
||||
{
|
||||
this.itemFactory = factory;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockBuilder item(Function<Block, ItemBlock> factory) {
|
||||
this.itemFactory = factory;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder disableItem()
|
||||
{
|
||||
this.disableItem = true;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockBuilder disableItem() {
|
||||
this.disableItem = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private void customizeForClient( BlockRenderingCustomizer callback )
|
||||
{
|
||||
callback.customize( this.blockRendering, this.itemRendering );
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void customizeForClient(BlockRenderingCustomizer callback) {
|
||||
callback.customize(this.blockRendering, this.itemRendering);
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
@Override
|
||||
public <T extends IBlockDefinition> T build()
|
||||
{
|
||||
if( !AEConfig.instance().areFeaturesEnabled( this.features ) )
|
||||
{
|
||||
return (T) new TileDefinition( this.registryName, null, null );
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T extends IBlockDefinition> T build() {
|
||||
if (!AEConfig.instance().areFeaturesEnabled(this.features)) {
|
||||
return (T) new TileDefinition(this.registryName, null, null);
|
||||
}
|
||||
|
||||
// Create block and matching item, and set factory name of both
|
||||
Block block = this.blockSupplier.get();
|
||||
block.setRegistryName( AppEng.MOD_ID, this.registryName );
|
||||
block.setUnlocalizedName( "appliedenergistics2." + this.registryName );
|
||||
// Create block and matching item, and set factory name of both
|
||||
Block block = this.blockSupplier.get();
|
||||
block.setRegistryName(AppEng.MOD_ID, this.registryName);
|
||||
block.setUnlocalizedName("appliedenergistics2." + this.registryName);
|
||||
|
||||
ItemBlock item = this.constructItemFromBlock( block );
|
||||
if( item != null )
|
||||
{
|
||||
item.setRegistryName( AppEng.MOD_ID, this.registryName );
|
||||
}
|
||||
ItemBlock item = this.constructItemFromBlock(block);
|
||||
if (item != null) {
|
||||
item.setRegistryName(AppEng.MOD_ID, this.registryName);
|
||||
}
|
||||
|
||||
// Register the item and block with the game
|
||||
this.factory.addBootstrapComponent( (IBlockRegistrationComponent) ( side, registry ) -> registry.register( block ) );
|
||||
if( item != null )
|
||||
{
|
||||
this.factory.addBootstrapComponent( (IItemRegistrationComponent) ( side, registry ) -> registry.register( item ) );
|
||||
}
|
||||
// Register the item and block with the game
|
||||
this.factory.addBootstrapComponent((IBlockRegistrationComponent) (side, registry) -> registry.register(block));
|
||||
if (item != null) {
|
||||
this.factory.addBootstrapComponent((IItemRegistrationComponent) (side, registry) -> registry.register(item));
|
||||
}
|
||||
|
||||
block.setCreativeTab( this.creativeTab );
|
||||
block.setCreativeTab(this.creativeTab);
|
||||
|
||||
// Register all extra handlers
|
||||
this.bootstrapComponents.forEach( component -> this.factory.addBootstrapComponent( component.apply( block, item ) ) );
|
||||
// Register all extra handlers
|
||||
this.bootstrapComponents.forEach(component -> this.factory.addBootstrapComponent(component.apply(block, item)));
|
||||
|
||||
if( this.tileEntityDefinition != null && block instanceof AEBaseTileBlock )
|
||||
{
|
||||
( (AEBaseTileBlock) block ).setTileEntity( this.tileEntityDefinition.getTileEntityClass() );
|
||||
if( this.tileEntityDefinition.getName() == null )
|
||||
{
|
||||
this.tileEntityDefinition.setName( this.registryName );
|
||||
}
|
||||
if (this.tileEntityDefinition != null && block instanceof AEBaseTileBlock) {
|
||||
((AEBaseTileBlock) block).setTileEntity(this.tileEntityDefinition.getTileEntityClass());
|
||||
if (this.tileEntityDefinition.getName() == null) {
|
||||
this.tileEntityDefinition.setName(this.registryName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
if( block instanceof AEBaseTileBlock )
|
||||
{
|
||||
AEBaseTileBlock tileBlock = (AEBaseTileBlock) block;
|
||||
this.blockRendering.apply( this.factory, block, tileBlock.getTileEntityClass() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.blockRendering.apply( this.factory, block, null );
|
||||
}
|
||||
if (Platform.isClient()) {
|
||||
if (block instanceof AEBaseTileBlock) {
|
||||
AEBaseTileBlock tileBlock = (AEBaseTileBlock) block;
|
||||
this.blockRendering.apply(this.factory, block, tileBlock.getTileEntityClass());
|
||||
} else {
|
||||
this.blockRendering.apply(this.factory, block, null);
|
||||
}
|
||||
|
||||
if( item != null )
|
||||
{
|
||||
this.itemRendering.apply( this.factory, item );
|
||||
}
|
||||
}
|
||||
if (item != null) {
|
||||
this.itemRendering.apply(this.factory, item);
|
||||
}
|
||||
}
|
||||
|
||||
if( block instanceof AEBaseTileBlock )
|
||||
{
|
||||
this.factory.addBootstrapComponent( (IPreInitComponent) side ->
|
||||
{
|
||||
AEBaseTile.registerTileItem(
|
||||
this.tileEntityDefinition == null ? ( (AEBaseTileBlock) block ).getTileEntityClass() : this.tileEntityDefinition.getTileEntityClass(),
|
||||
new BlockStackSrc( block, 0, ActivityState.Enabled ) );
|
||||
} );
|
||||
if (block instanceof AEBaseTileBlock) {
|
||||
this.factory.addBootstrapComponent((IPreInitComponent) side ->
|
||||
{
|
||||
AEBaseTile.registerTileItem(
|
||||
this.tileEntityDefinition == null ? ((AEBaseTileBlock) block).getTileEntityClass() : this.tileEntityDefinition.getTileEntityClass(),
|
||||
new BlockStackSrc(block, 0, ActivityState.Enabled));
|
||||
});
|
||||
|
||||
if( this.tileEntityDefinition != null )
|
||||
{
|
||||
this.factory.tileEntityComponent.addTileEntity( this.tileEntityDefinition );
|
||||
}
|
||||
if (this.tileEntityDefinition != null) {
|
||||
this.factory.tileEntityComponent.addTileEntity(this.tileEntityDefinition);
|
||||
}
|
||||
|
||||
return (T) new TileDefinition( this.registryName, (AEBaseTileBlock) block, item );
|
||||
}
|
||||
else
|
||||
{
|
||||
return (T) new BlockDefinition( this.registryName, block, item );
|
||||
}
|
||||
}
|
||||
return (T) new TileDefinition(this.registryName, (AEBaseTileBlock) block, item);
|
||||
} else {
|
||||
return (T) new BlockDefinition(this.registryName, block, item);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ItemBlock constructItemFromBlock( Block block )
|
||||
{
|
||||
if( this.disableItem )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Nullable
|
||||
private ItemBlock constructItemFromBlock(Block block) {
|
||||
if (this.disableItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if( this.itemFactory != null )
|
||||
{
|
||||
return this.itemFactory.apply( block );
|
||||
}
|
||||
else if( block instanceof AEBaseBlock )
|
||||
{
|
||||
return new AEBaseItemBlock( block );
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ItemBlock( block );
|
||||
}
|
||||
}
|
||||
if (this.itemFactory != null) {
|
||||
return this.itemFactory.apply(block);
|
||||
} else if (block instanceof AEBaseBlock) {
|
||||
return new AEBaseItemBlock(block);
|
||||
} else {
|
||||
return new ItemBlock(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.BlockColorComponent;
|
||||
import appeng.bootstrap.components.StateMapperComponent;
|
||||
import appeng.bootstrap.components.TesrComponent;
|
||||
import appeng.client.render.model.AutoRotatingModel;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
@@ -33,103 +34,87 @@ import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.BlockColorComponent;
|
||||
import appeng.bootstrap.components.StateMapperComponent;
|
||||
import appeng.bootstrap.components.TesrComponent;
|
||||
import appeng.client.render.model.AutoRotatingModel;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
|
||||
class BlockRendering implements IBlockRendering
|
||||
{
|
||||
class BlockRendering implements IBlockRendering {
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> modelCustomizer;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> modelCustomizer;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private IBlockColor blockColor;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IBlockColor blockColor;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private TileEntitySpecialRenderer<?> tesr;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private TileEntitySpecialRenderer<?> tesr;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private IStateMapper stateMapper;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IStateMapper stateMapper;
|
||||
|
||||
@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 IBlockRendering modelCustomizer( BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer )
|
||||
{
|
||||
this.modelCustomizer = customizer;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IBlockRendering modelCustomizer(BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer) {
|
||||
this.modelCustomizer = customizer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
@Override
|
||||
public IBlockRendering blockColor( IBlockColor blockColor )
|
||||
{
|
||||
this.blockColor = blockColor;
|
||||
return this;
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IBlockRendering blockColor(IBlockColor blockColor) {
|
||||
this.blockColor = blockColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
@Override
|
||||
public IBlockRendering tesr( TileEntitySpecialRenderer<?> tesr )
|
||||
{
|
||||
this.tesr = tesr;
|
||||
return this;
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IBlockRendering tesr(TileEntitySpecialRenderer<?> tesr) {
|
||||
this.tesr = tesr;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockRendering builtInModel( String name, IModel model )
|
||||
{
|
||||
this.builtInModels.put( name, model );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockRendering builtInModel(String name, IModel model) {
|
||||
this.builtInModels.put(name, model);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
@Override
|
||||
public IBlockRendering stateMapper( IStateMapper mapper )
|
||||
{
|
||||
this.stateMapper = mapper;
|
||||
return this;
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IBlockRendering stateMapper(IStateMapper mapper) {
|
||||
this.stateMapper = mapper;
|
||||
return this;
|
||||
}
|
||||
|
||||
void apply( FeatureFactory factory, Block block, Class<?> tileEntityClass )
|
||||
{
|
||||
if( this.tesr != null )
|
||||
{
|
||||
if( tileEntityClass == null )
|
||||
{
|
||||
throw new IllegalStateException( "Tried to register a TESR for " + block + " even though no tile entity has been specified." );
|
||||
}
|
||||
factory.addBootstrapComponent( new TesrComponent( tileEntityClass, this.tesr ) );
|
||||
}
|
||||
void apply(FeatureFactory factory, Block block, Class<?> tileEntityClass) {
|
||||
if (this.tesr != null) {
|
||||
if (tileEntityClass == null) {
|
||||
throw new IllegalStateException("Tried to register a TESR for " + block + " even though no tile entity has been specified.");
|
||||
}
|
||||
factory.addBootstrapComponent(new TesrComponent(tileEntityClass, this.tesr));
|
||||
}
|
||||
|
||||
if( this.modelCustomizer != null )
|
||||
{
|
||||
factory.addModelOverride( block.getRegistryName().getResourcePath(), this.modelCustomizer );
|
||||
}
|
||||
else if( block instanceof AEBaseTileBlock )
|
||||
{
|
||||
// This is a default rotating model if the base-block uses an AE tile entity which exposes UP/FRONT as
|
||||
// extended props
|
||||
factory.addModelOverride( block.getRegistryName().getResourcePath(), ( l, m ) -> new AutoRotatingModel( m ) );
|
||||
}
|
||||
if (this.modelCustomizer != null) {
|
||||
factory.addModelOverride(block.getRegistryName().getResourcePath(), this.modelCustomizer);
|
||||
} else if (block instanceof AEBaseTileBlock) {
|
||||
// This is a default rotating model if the base-block uses an AE tile entity which exposes UP/FRONT as
|
||||
// extended props
|
||||
factory.addModelOverride(block.getRegistryName().getResourcePath(), (l, m) -> new AutoRotatingModel(m));
|
||||
}
|
||||
|
||||
// TODO : 1.12
|
||||
this.builtInModels.forEach( factory::addBuiltInModel );
|
||||
// TODO : 1.12
|
||||
this.builtInModels.forEach(factory::addBuiltInModel);
|
||||
|
||||
if( this.blockColor != null )
|
||||
{
|
||||
factory.addBootstrapComponent( new BlockColorComponent( block, this.blockColor ) );
|
||||
}
|
||||
if (this.blockColor != null) {
|
||||
factory.addBootstrapComponent(new BlockColorComponent(block, this.blockColor));
|
||||
}
|
||||
|
||||
if( this.stateMapper != null )
|
||||
{
|
||||
factory.addBootstrapComponent( new StateMapperComponent( block, this.stateMapper ) );
|
||||
}
|
||||
}
|
||||
if (this.stateMapper != null) {
|
||||
factory.addBootstrapComponent(new StateMapperComponent(block, this.stateMapper));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,9 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
* used
|
||||
* due to them not being able to be annotated with @SideOnly(CLIENT).
|
||||
*/
|
||||
public abstract class BlockRenderingCustomizer
|
||||
{
|
||||
public abstract class BlockRenderingCustomizer {
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public abstract void customize( IBlockRendering rendering, IItemRendering itemRendering );
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract void customize(IBlockRendering rendering, IItemRendering itemRendering);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,24 +19,6 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.AEColoredItemDefinition;
|
||||
@@ -48,111 +30,107 @@ import appeng.core.features.ActivityState;
|
||||
import appeng.core.features.ColoredItemDefinition;
|
||||
import appeng.core.features.ItemStackSrc;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public class FeatureFactory
|
||||
{
|
||||
public class FeatureFactory {
|
||||
|
||||
private final AEFeature[] defaultFeatures;
|
||||
private final AEFeature[] defaultFeatures;
|
||||
|
||||
private final Map<Class<? extends IBootstrapComponent>, List<IBootstrapComponent>> bootstrapComponents;
|
||||
private final Map<Class<? extends IBootstrapComponent>, List<IBootstrapComponent>> bootstrapComponents;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private ModelOverrideComponent modelOverrideComponent;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private ModelOverrideComponent modelOverrideComponent;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private BuiltInModelComponent builtInModelComponent;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private BuiltInModelComponent builtInModelComponent;
|
||||
|
||||
public final TileEntityComponent tileEntityComponent;
|
||||
public final TileEntityComponent tileEntityComponent;
|
||||
|
||||
public FeatureFactory()
|
||||
{
|
||||
this.defaultFeatures = new AEFeature[] { AEFeature.CORE };
|
||||
this.bootstrapComponents = new HashMap<>();
|
||||
public FeatureFactory() {
|
||||
this.defaultFeatures = new AEFeature[]{AEFeature.CORE};
|
||||
this.bootstrapComponents = new HashMap<>();
|
||||
|
||||
this.tileEntityComponent = new TileEntityComponent();
|
||||
this.addBootstrapComponent( this.tileEntityComponent );
|
||||
this.tileEntityComponent = new TileEntityComponent();
|
||||
this.addBootstrapComponent(this.tileEntityComponent);
|
||||
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
this.modelOverrideComponent = new ModelOverrideComponent();
|
||||
this.addBootstrapComponent( this.modelOverrideComponent );
|
||||
if (Platform.isClient()) {
|
||||
this.modelOverrideComponent = new ModelOverrideComponent();
|
||||
this.addBootstrapComponent(this.modelOverrideComponent);
|
||||
|
||||
this.builtInModelComponent = new BuiltInModelComponent();
|
||||
this.addBootstrapComponent( this.builtInModelComponent );
|
||||
}
|
||||
}
|
||||
this.builtInModelComponent = new BuiltInModelComponent();
|
||||
this.addBootstrapComponent(this.builtInModelComponent);
|
||||
}
|
||||
}
|
||||
|
||||
private FeatureFactory( FeatureFactory parent, AEFeature... defaultFeatures )
|
||||
{
|
||||
this.defaultFeatures = defaultFeatures.clone();
|
||||
this.bootstrapComponents = parent.bootstrapComponents;
|
||||
this.tileEntityComponent = parent.tileEntityComponent;
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
this.modelOverrideComponent = parent.modelOverrideComponent;
|
||||
this.builtInModelComponent = parent.builtInModelComponent;
|
||||
}
|
||||
}
|
||||
private FeatureFactory(FeatureFactory parent, AEFeature... defaultFeatures) {
|
||||
this.defaultFeatures = defaultFeatures.clone();
|
||||
this.bootstrapComponents = parent.bootstrapComponents;
|
||||
this.tileEntityComponent = parent.tileEntityComponent;
|
||||
if (Platform.isClient()) {
|
||||
this.modelOverrideComponent = parent.modelOverrideComponent;
|
||||
this.builtInModelComponent = parent.builtInModelComponent;
|
||||
}
|
||||
}
|
||||
|
||||
public IBlockBuilder block( String id, Supplier<Block> block )
|
||||
{
|
||||
return new BlockDefinitionBuilder( this, id, block ).features( this.defaultFeatures );
|
||||
}
|
||||
public IBlockBuilder block(String id, Supplier<Block> block) {
|
||||
return new BlockDefinitionBuilder(this, id, block).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public IItemBuilder item( String id, Supplier<Item> item )
|
||||
{
|
||||
return new ItemDefinitionBuilder( this, id, item ).features( this.defaultFeatures );
|
||||
}
|
||||
public IItemBuilder item(String id, Supplier<Item> item) {
|
||||
return new ItemDefinitionBuilder(this, id, item).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public AEColoredItemDefinition colored( IItemDefinition target, int offset )
|
||||
{
|
||||
ColoredItemDefinition definition = new ColoredItemDefinition();
|
||||
public AEColoredItemDefinition colored(IItemDefinition target, int offset) {
|
||||
ColoredItemDefinition definition = new ColoredItemDefinition();
|
||||
|
||||
target.maybeItem().ifPresent( targetItem ->
|
||||
{
|
||||
for( final AEColor color : AEColor.VALID_COLORS )
|
||||
{
|
||||
final ActivityState state = ActivityState.from( target.isEnabled() );
|
||||
target.maybeItem().ifPresent(targetItem ->
|
||||
{
|
||||
for (final AEColor color : AEColor.VALID_COLORS) {
|
||||
final ActivityState state = ActivityState.from(target.isEnabled());
|
||||
|
||||
definition.add( color, new ItemStackSrc( targetItem, offset + color.ordinal(), state ) );
|
||||
}
|
||||
} );
|
||||
definition.add(color, new ItemStackSrc(targetItem, offset + color.ordinal(), state));
|
||||
}
|
||||
});
|
||||
|
||||
return definition;
|
||||
}
|
||||
return definition;
|
||||
}
|
||||
|
||||
public FeatureFactory features( AEFeature... features )
|
||||
{
|
||||
return new FeatureFactory( this, features );
|
||||
}
|
||||
public FeatureFactory features(AEFeature... features) {
|
||||
return new FeatureFactory(this, features);
|
||||
}
|
||||
|
||||
public void addBootstrapComponent( IBootstrapComponent component )
|
||||
{
|
||||
Arrays.stream( component.getClass().getInterfaces() )
|
||||
.filter( i -> IBootstrapComponent.class.isAssignableFrom( i ) )
|
||||
.forEach( i -> this.addBootstrapComponent( (Class<? extends IBootstrapComponent>) i, component ) );
|
||||
}
|
||||
public void addBootstrapComponent(IBootstrapComponent component) {
|
||||
Arrays.stream(component.getClass().getInterfaces())
|
||||
.filter(i -> IBootstrapComponent.class.isAssignableFrom(i))
|
||||
.forEach(i -> this.addBootstrapComponent((Class<? extends IBootstrapComponent>) i, component));
|
||||
}
|
||||
|
||||
private <T extends IBootstrapComponent> void addBootstrapComponent( Class<? extends IBootstrapComponent> eventType, T component )
|
||||
{
|
||||
this.bootstrapComponents.computeIfAbsent( eventType, c -> new ArrayList<IBootstrapComponent>() ).add( component );
|
||||
}
|
||||
private <T extends IBootstrapComponent> void addBootstrapComponent(Class<? extends IBootstrapComponent> eventType, T component) {
|
||||
this.bootstrapComponents.computeIfAbsent(eventType, c -> new ArrayList<IBootstrapComponent>()).add(component);
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
void addBuiltInModel( String path, IModel model )
|
||||
{
|
||||
this.builtInModelComponent.addModel( path, model );
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
void addBuiltInModel(String path, IModel model) {
|
||||
this.builtInModelComponent.addModel(path, model);
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
void addModelOverride( String resourcePath, BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer )
|
||||
{
|
||||
this.modelOverrideComponent.addOverride( resourcePath, customizer );
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
void addModelOverride(String resourcePath, BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer) {
|
||||
this.modelOverrideComponent.addOverride(resourcePath, customizer);
|
||||
}
|
||||
|
||||
public <T extends IBootstrapComponent> Iterator<T> getBootstrapComponents( Class<T> eventType )
|
||||
{
|
||||
return (Iterator<T>) this.bootstrapComponents.getOrDefault( eventType, Collections.emptyList() ).iterator();
|
||||
}
|
||||
public <T extends IBootstrapComponent> Iterator<T> getBootstrapComponents(Class<T> eventType) {
|
||||
return (Iterator<T>) this.bootstrapComponents.getOrDefault(eventType, Collections.emptyList()).iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,42 +19,40 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.features.AEFeature;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.features.AEFeature;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public interface IBlockBuilder
|
||||
{
|
||||
IBlockBuilder bootstrap( BiFunction<Block, Item, IBootstrapComponent> component );
|
||||
public interface IBlockBuilder {
|
||||
IBlockBuilder bootstrap(BiFunction<Block, Item, IBootstrapComponent> component);
|
||||
|
||||
IBlockBuilder features( AEFeature... features );
|
||||
IBlockBuilder features(AEFeature... features);
|
||||
|
||||
IBlockBuilder addFeatures( AEFeature... features );
|
||||
IBlockBuilder addFeatures(AEFeature... features);
|
||||
|
||||
IBlockBuilder rendering( BlockRenderingCustomizer callback );
|
||||
IBlockBuilder rendering(BlockRenderingCustomizer callback);
|
||||
|
||||
IBlockBuilder tileEntity( TileEntityDefinition tileEntityDefinition );
|
||||
IBlockBuilder tileEntity(TileEntityDefinition tileEntityDefinition);
|
||||
|
||||
/**
|
||||
* Don't register an item for this block.
|
||||
*/
|
||||
IBlockBuilder disableItem();
|
||||
/**
|
||||
* Don't register an item for this block.
|
||||
*/
|
||||
IBlockBuilder disableItem();
|
||||
|
||||
/**
|
||||
* Forces this block's item to uses a custom model, instead of using the default block state as the item model.
|
||||
* The model has the same name as the registry name.
|
||||
*/
|
||||
IBlockBuilder useCustomItemModel();
|
||||
/**
|
||||
* Forces this block's item to uses a custom model, instead of using the default block state as the item model.
|
||||
* The model has the same name as the registry name.
|
||||
*/
|
||||
IBlockBuilder useCustomItemModel();
|
||||
|
||||
IBlockBuilder item( Function<Block, ItemBlock> factory );
|
||||
IBlockBuilder item(Function<Block, ItemBlock> factory);
|
||||
|
||||
<T extends IBlockDefinition> T build();
|
||||
<T extends IBlockDefinition> T build();
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
@@ -30,29 +28,30 @@ import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
|
||||
/**
|
||||
* Allows for client-side rendering to be customized in the context of block/item registration.
|
||||
*/
|
||||
public interface IBlockRendering
|
||||
{
|
||||
public interface IBlockRendering {
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
IBlockRendering modelCustomizer( BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer );
|
||||
@SideOnly(Side.CLIENT)
|
||||
IBlockRendering modelCustomizer(BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer);
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
IBlockRendering blockColor( IBlockColor blockColor );
|
||||
@SideOnly(Side.CLIENT)
|
||||
IBlockRendering blockColor(IBlockColor blockColor);
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
IBlockRendering stateMapper( IStateMapper mapper );
|
||||
@SideOnly(Side.CLIENT)
|
||||
IBlockRendering stateMapper(IStateMapper mapper);
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
IBlockRendering tesr( TileEntitySpecialRenderer<?> tesr );
|
||||
@SideOnly(Side.CLIENT)
|
||||
IBlockRendering tesr(TileEntitySpecialRenderer<?> tesr);
|
||||
|
||||
/**
|
||||
* Registers a built-in model under the given resource path.
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
IBlockRendering builtInModel( String name, IModel model );
|
||||
/**
|
||||
* Registers a built-in model under the given resource path.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
IBlockRendering builtInModel(String name, IModel model);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,5 @@ package appeng.bootstrap;
|
||||
* Bootstrap components can be registered to take part in the various initialization phases of Forge.
|
||||
* See the individual subclasses for a specific forge initalization event.
|
||||
*/
|
||||
public interface IBootstrapComponent
|
||||
{
|
||||
public interface IBootstrapComponent {
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import net.minecraft.advancements.ICriterionTrigger;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ICriterionTriggerRegistry
|
||||
{
|
||||
void register( ICriterionTrigger<? extends ICriterionInstance> trigger );
|
||||
public interface ICriterionTriggerRegistry {
|
||||
void register(ICriterionTrigger<? extends ICriterionInstance> trigger);
|
||||
}
|
||||
|
||||
@@ -19,37 +19,35 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.ItemDefinition;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.dispenser.IBehaviorDispenseItem;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.ItemDefinition;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
/**
|
||||
* Allows an item to be defined and registered with the game.
|
||||
* The item is only registered once build is called.
|
||||
*/
|
||||
public interface IItemBuilder
|
||||
{
|
||||
IItemBuilder bootstrap( Function<Item, IBootstrapComponent> component );
|
||||
public interface IItemBuilder {
|
||||
IItemBuilder bootstrap(Function<Item, IBootstrapComponent> component);
|
||||
|
||||
IItemBuilder features( AEFeature... features );
|
||||
IItemBuilder features(AEFeature... features);
|
||||
|
||||
IItemBuilder addFeatures( AEFeature... features );
|
||||
IItemBuilder addFeatures(AEFeature... features);
|
||||
|
||||
IItemBuilder creativeTab( CreativeTabs tab );
|
||||
IItemBuilder creativeTab(CreativeTabs tab);
|
||||
|
||||
IItemBuilder rendering( ItemRenderingCustomizer callback );
|
||||
IItemBuilder rendering(ItemRenderingCustomizer callback);
|
||||
|
||||
/**
|
||||
* Registers a custom dispenser behavior for this item.
|
||||
*/
|
||||
IItemBuilder dispenserBehavior( Supplier<IBehaviorDispenseItem> behavior );
|
||||
/**
|
||||
* Registers a custom dispenser behavior for this item.
|
||||
*/
|
||||
IItemBuilder dispenserBehavior(Supplier<IBehaviorDispenseItem> behavior);
|
||||
|
||||
ItemDefinition build();
|
||||
ItemDefinition build();
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.color.IItemColor;
|
||||
@@ -30,66 +27,66 @@ import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Allows the rendering of an item to be customized.
|
||||
*/
|
||||
public interface IItemRendering
|
||||
{
|
||||
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
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
IItemRendering meshDefinition( ItemMeshDefinition meshDefinition );
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
IItemRendering meshDefinition(ItemMeshDefinition meshDefinition);
|
||||
|
||||
/**
|
||||
* Registers an item model for meta=0, see {@link #model(int, ModelResourceLocation)}.
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
default IItemRendering model( ModelResourceLocation model )
|
||||
{
|
||||
return model( 0, model );
|
||||
}
|
||||
/**
|
||||
* Registers an item model for meta=0, see {@link #model(int, ModelResourceLocation)}.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
default IItemRendering model(ModelResourceLocation model) {
|
||||
return model(0, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an item model for a given meta.
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
IItemRendering model( int meta, ModelResourceLocation model );
|
||||
/**
|
||||
* Registers an item model for a given meta.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
IItemRendering model(int meta, ModelResourceLocation model);
|
||||
|
||||
/**
|
||||
* Convenient override for {@link #variants(Collection)}.
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
default IItemRendering variants( ResourceLocation... resources )
|
||||
{
|
||||
return variants( Arrays.asList( resources ) );
|
||||
}
|
||||
/**
|
||||
* Convenient override for {@link #variants(Collection)}.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
default IItemRendering variants(ResourceLocation... resources) {
|
||||
return variants(Arrays.asList(resources));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
IItemRendering variants( Collection<ResourceLocation> resources );
|
||||
/**
|
||||
* 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.
|
||||
* <p>
|
||||
* Models registered via {@link #model(int, ModelResourceLocation)} are automatically added here.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
IItemRendering variants(Collection<ResourceLocation> resources);
|
||||
|
||||
/**
|
||||
* Registers a custom item color definition that inspects an item stack and tint and
|
||||
* returns a color multiplier.
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
IItemRendering color( IItemColor itemColor );
|
||||
/**
|
||||
* Registers a custom item color definition that inspects an item stack and tint and
|
||||
* returns a color multiplier.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
IItemRendering color(IItemColor itemColor);
|
||||
|
||||
/**
|
||||
* Registers a built-in model under the given resource path.
|
||||
*/
|
||||
@SideOnly( Side.CLIENT )
|
||||
IItemRendering builtInModel( String name, IModel model );
|
||||
/**
|
||||
* Registers a built-in model under the given resource path.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
IItemRendering builtInModel(String name, IModel model);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,13 +27,12 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
public interface IModelRegistry
|
||||
{
|
||||
void registerItemVariants( Item item, ResourceLocation... names );
|
||||
public interface IModelRegistry {
|
||||
void registerItemVariants(Item item, ResourceLocation... names);
|
||||
|
||||
void setCustomModelResourceLocation( Item item, int metadata, ModelResourceLocation model );
|
||||
void setCustomModelResourceLocation(Item item, int metadata, ModelResourceLocation model);
|
||||
|
||||
void setCustomMeshDefinition( Item item, ItemMeshDefinition meshDefinition );
|
||||
void setCustomMeshDefinition(Item item, ItemMeshDefinition meshDefinition);
|
||||
|
||||
void setCustomStateMapper( Block block, IStateMapper mapper );
|
||||
void setCustomStateMapper(Block block, IStateMapper mapper);
|
||||
}
|
||||
|
||||
@@ -19,20 +19,6 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.dispenser.IBehaviorDispenseItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.bootstrap.components.IItemRegistrationComponent;
|
||||
import appeng.bootstrap.components.IPostInitComponent;
|
||||
import appeng.core.AEConfig;
|
||||
@@ -41,129 +27,127 @@ import appeng.core.CreativeTab;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.ItemDefinition;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.dispenser.IBehaviorDispenseItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
class ItemDefinitionBuilder implements IItemBuilder
|
||||
{
|
||||
class ItemDefinitionBuilder implements IItemBuilder {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final String registryName;
|
||||
private final String registryName;
|
||||
|
||||
private final Supplier<Item> itemSupplier;
|
||||
private final Supplier<Item> itemSupplier;
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf( AEFeature.class );
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
private final List<Function<Item, IBootstrapComponent>> boostrapComponents = new ArrayList<>();
|
||||
private final List<Function<Item, IBootstrapComponent>> boostrapComponents = new ArrayList<>();
|
||||
|
||||
private Supplier<IBehaviorDispenseItem> dispenserBehaviorSupplier;
|
||||
private Supplier<IBehaviorDispenseItem> dispenserBehaviorSupplier;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private ItemRendering itemRendering;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private ItemRendering itemRendering;
|
||||
|
||||
private CreativeTabs creativeTab = CreativeTab.instance;
|
||||
private CreativeTabs creativeTab = CreativeTab.instance;
|
||||
|
||||
ItemDefinitionBuilder( FeatureFactory factory, String registryName, Supplier<Item> itemSupplier )
|
||||
{
|
||||
this.factory = factory;
|
||||
this.registryName = registryName;
|
||||
this.itemSupplier = itemSupplier;
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
ItemDefinitionBuilder(FeatureFactory factory, String registryName, Supplier<Item> itemSupplier) {
|
||||
this.factory = factory;
|
||||
this.registryName = registryName;
|
||||
this.itemSupplier = itemSupplier;
|
||||
if (Platform.isClient()) {
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder bootstrap( Function<Item, IBootstrapComponent> component )
|
||||
{
|
||||
this.boostrapComponents.add( component );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder bootstrap(Function<Item, IBootstrapComponent> component) {
|
||||
this.boostrapComponents.add(component);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder features( AEFeature... features )
|
||||
{
|
||||
this.features.clear();
|
||||
this.addFeatures( features );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder addFeatures( AEFeature... features )
|
||||
{
|
||||
Collections.addAll( this.features, features );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder creativeTab( CreativeTabs tab )
|
||||
{
|
||||
this.creativeTab = tab;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder creativeTab(CreativeTabs tab) {
|
||||
this.creativeTab = tab;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder rendering( ItemRenderingCustomizer callback )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
this.customizeForClient( callback );
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder rendering(ItemRenderingCustomizer callback) {
|
||||
if (Platform.isClient()) {
|
||||
this.customizeForClient(callback);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder dispenserBehavior( Supplier<IBehaviorDispenseItem> behavior )
|
||||
{
|
||||
this.dispenserBehaviorSupplier = behavior;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder dispenserBehavior(Supplier<IBehaviorDispenseItem> behavior) {
|
||||
this.dispenserBehaviorSupplier = behavior;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private void customizeForClient( ItemRenderingCustomizer callback )
|
||||
{
|
||||
callback.customize( this.itemRendering );
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void customizeForClient(ItemRenderingCustomizer callback) {
|
||||
callback.customize(this.itemRendering);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDefinition build()
|
||||
{
|
||||
if( !AEConfig.instance().areFeaturesEnabled( this.features ) )
|
||||
{
|
||||
return new ItemDefinition( this.registryName, null );
|
||||
}
|
||||
@Override
|
||||
public ItemDefinition build() {
|
||||
if (!AEConfig.instance().areFeaturesEnabled(this.features)) {
|
||||
return new ItemDefinition(this.registryName, null);
|
||||
}
|
||||
|
||||
Item item = this.itemSupplier.get();
|
||||
item.setRegistryName( AppEng.MOD_ID, this.registryName );
|
||||
Item item = this.itemSupplier.get();
|
||||
item.setRegistryName(AppEng.MOD_ID, this.registryName);
|
||||
|
||||
ItemDefinition definition = new ItemDefinition( this.registryName, item );
|
||||
ItemDefinition definition = new ItemDefinition(this.registryName, item);
|
||||
|
||||
item.setUnlocalizedName( "appliedenergistics2." + this.registryName );
|
||||
item.setCreativeTab( this.creativeTab );
|
||||
item.setUnlocalizedName("appliedenergistics2." + this.registryName);
|
||||
item.setCreativeTab(this.creativeTab);
|
||||
|
||||
// Register all extra handlers
|
||||
this.boostrapComponents.forEach( component -> this.factory.addBootstrapComponent( component.apply( item ) ) );
|
||||
// Register all extra handlers
|
||||
this.boostrapComponents.forEach(component -> this.factory.addBootstrapComponent(component.apply(item)));
|
||||
|
||||
// Register custom dispenser behavior if requested
|
||||
if( this.dispenserBehaviorSupplier != null )
|
||||
{
|
||||
this.factory.addBootstrapComponent( (IPostInitComponent) side ->
|
||||
{
|
||||
IBehaviorDispenseItem behavior = this.dispenserBehaviorSupplier.get();
|
||||
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject( item, behavior );
|
||||
} );
|
||||
}
|
||||
// Register custom dispenser behavior if requested
|
||||
if (this.dispenserBehaviorSupplier != null) {
|
||||
this.factory.addBootstrapComponent((IPostInitComponent) side ->
|
||||
{
|
||||
IBehaviorDispenseItem behavior = this.dispenserBehaviorSupplier.get();
|
||||
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(item, behavior);
|
||||
});
|
||||
}
|
||||
|
||||
this.factory.addBootstrapComponent( (IItemRegistrationComponent) ( side, reg ) -> reg.register( item ) );
|
||||
this.factory.addBootstrapComponent((IItemRegistrationComponent) (side, reg) -> reg.register(item));
|
||||
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
this.itemRendering.apply( this.factory, item );
|
||||
}
|
||||
if (Platform.isClient()) {
|
||||
this.itemRendering.apply(this.factory, item);
|
||||
}
|
||||
|
||||
return definition;
|
||||
}
|
||||
return definition;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,8 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
* used
|
||||
* due to them not being able to be annotated with @SideOnly(CLIENT).
|
||||
*/
|
||||
public abstract class ItemRenderingCustomizer
|
||||
{
|
||||
public abstract class ItemRenderingCustomizer {
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public abstract void customize( IItemRendering rendering );
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract void customize(IItemRendering rendering);
|
||||
}
|
||||
|
||||
@@ -25,23 +25,20 @@ import net.minecraft.client.renderer.color.IBlockColor;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
|
||||
public class BlockColorComponent implements IInitComponent
|
||||
{
|
||||
public class BlockColorComponent implements IInitComponent {
|
||||
|
||||
private final Block block;
|
||||
private final Block block;
|
||||
|
||||
private final IBlockColor blockColor;
|
||||
private final IBlockColor blockColor;
|
||||
|
||||
public BlockColorComponent( Block block, IBlockColor blockColor )
|
||||
{
|
||||
this.block = block;
|
||||
this.blockColor = blockColor;
|
||||
}
|
||||
public BlockColorComponent(Block block, IBlockColor blockColor) {
|
||||
this.block = block;
|
||||
this.blockColor = blockColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize( Side side )
|
||||
{
|
||||
Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler( this.blockColor, this.block );
|
||||
}
|
||||
@Override
|
||||
public void initialize(Side side) {
|
||||
Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(this.blockColor, this.block);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,39 +19,34 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.client.render.model.BuiltInModelLoader;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.client.render.model.BuiltInModelLoader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public class BuiltInModelComponent implements IPreInitComponent
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class BuiltInModelComponent implements IPreInitComponent {
|
||||
|
||||
private final Map<String, IModel> builtInModels = new HashMap<>();
|
||||
private final Map<String, IModel> builtInModels = new HashMap<>();
|
||||
|
||||
private boolean hasInitialized = false;
|
||||
private boolean hasInitialized = false;
|
||||
|
||||
public void addModel( String path, IModel model )
|
||||
{
|
||||
Preconditions.checkState( !this.hasInitialized );
|
||||
this.builtInModels.put( path, model );
|
||||
}
|
||||
public void addModel(String path, IModel model) {
|
||||
Preconditions.checkState(!this.hasInitialized);
|
||||
this.builtInModels.put(path, model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInitialize( Side side )
|
||||
{
|
||||
this.hasInitialized = true;
|
||||
@Override
|
||||
public void preInitialize(Side side) {
|
||||
this.hasInitialized = true;
|
||||
|
||||
BuiltInModelLoader loader = new BuiltInModelLoader( this.builtInModels );
|
||||
ModelLoaderRegistry.registerLoader( loader );
|
||||
}
|
||||
BuiltInModelLoader loader = new BuiltInModelLoader(this.builtInModels);
|
||||
ModelLoaderRegistry.registerLoader(loader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IBlockRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void blockRegistration( Side side, IForgeRegistry<Block> blockRegistry );
|
||||
public interface IBlockRegistrationComponent extends IBootstrapComponent {
|
||||
void blockRegistration(Side side, IForgeRegistry<Block> blockRegistry);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraftforge.fml.common.registry.EntityEntry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IEntityRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void entityRegistration( IForgeRegistry<EntityEntry> entityRegistry );
|
||||
public interface IEntityRegistrationComponent extends IBootstrapComponent {
|
||||
void entityRegistration(IForgeRegistry<EntityEntry> entityRegistry);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,11 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IInitComponent extends IBootstrapComponent
|
||||
{
|
||||
void initialize( Side side );
|
||||
public interface IInitComponent extends IBootstrapComponent {
|
||||
void initialize(Side side);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IItemRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void itemRegistration( Side side, IForgeRegistry<Item> itemRegistry );
|
||||
public interface IItemRegistrationComponent extends IBootstrapComponent {
|
||||
void itemRegistration(Side side, IForgeRegistry<Item> itemRegistry);
|
||||
}
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,7 +29,6 @@ import appeng.bootstrap.IModelRegistry;
|
||||
*/
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IModelRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void modelRegistration( Side side, IModelRegistry registry );
|
||||
public interface IModelRegistrationComponent extends IBootstrapComponent {
|
||||
void modelRegistration(Side side, IModelRegistry registry);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,11 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IOreDictComponent extends IBootstrapComponent
|
||||
{
|
||||
void oreRegistration( Side side );
|
||||
public interface IOreDictComponent extends IBootstrapComponent {
|
||||
void oreRegistration(Side side);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,11 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IPostInitComponent extends IBootstrapComponent
|
||||
{
|
||||
void postInitialize( Side side );
|
||||
public interface IPostInitComponent extends IBootstrapComponent {
|
||||
void postInitialize(Side side);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,11 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IPreInitComponent extends IBootstrapComponent
|
||||
{
|
||||
void preInitialize( Side side );
|
||||
public interface IPreInitComponent extends IBootstrapComponent {
|
||||
void preInitialize(Side side);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IRecipeRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void recipeRegistration( Side side, IForgeRegistry<IRecipe> recipeRegistry );
|
||||
public interface IRecipeRegistrationComponent extends IBootstrapComponent {
|
||||
void recipeRegistration(Side side, IForgeRegistry<IRecipe> recipeRegistry);
|
||||
}
|
||||
|
||||
@@ -25,22 +25,19 @@ import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
|
||||
public class ItemColorComponent implements IInitComponent
|
||||
{
|
||||
public class ItemColorComponent implements IInitComponent {
|
||||
|
||||
private final Item item;
|
||||
private final Item item;
|
||||
|
||||
private final IItemColor itemColor;
|
||||
private final IItemColor itemColor;
|
||||
|
||||
public ItemColorComponent( Item item, IItemColor itemColor )
|
||||
{
|
||||
this.item = item;
|
||||
this.itemColor = itemColor;
|
||||
}
|
||||
public ItemColorComponent(Item item, IItemColor itemColor) {
|
||||
this.item = item;
|
||||
this.itemColor = itemColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize( Side side )
|
||||
{
|
||||
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( this.itemColor, this.item );
|
||||
}
|
||||
@Override
|
||||
public void initialize(Side side) {
|
||||
Minecraft.getMinecraft().getItemColors().registerItemColorHandler(this.itemColor, this.item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,35 +19,31 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
/**
|
||||
* 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 IModelRegistrationComponent
|
||||
{
|
||||
public class ItemMeshDefinitionComponent implements IModelRegistrationComponent {
|
||||
|
||||
private final Item item;
|
||||
private final Item item;
|
||||
|
||||
private final ItemMeshDefinition meshDefinition;
|
||||
private final ItemMeshDefinition meshDefinition;
|
||||
|
||||
public ItemMeshDefinitionComponent( @Nonnull Item item, @Nonnull ItemMeshDefinition meshDefinition )
|
||||
{
|
||||
this.item = item;
|
||||
this.meshDefinition = meshDefinition;
|
||||
}
|
||||
public ItemMeshDefinitionComponent(@Nonnull Item item, @Nonnull ItemMeshDefinition meshDefinition) {
|
||||
this.item = item;
|
||||
this.meshDefinition = meshDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modelRegistration( Side side, IModelRegistry registry )
|
||||
{
|
||||
registry.setCustomMeshDefinition( this.item, this.meshDefinition );
|
||||
}
|
||||
@Override
|
||||
public void modelRegistration(Side side, IModelRegistry registry) {
|
||||
registry.setCustomMeshDefinition(this.item, this.meshDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,41 +19,36 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Registers the models that should by used for an item, including the ability to
|
||||
* distinguish by meta.
|
||||
*/
|
||||
public class ItemModelComponent implements IModelRegistrationComponent
|
||||
{
|
||||
public class ItemModelComponent implements IModelRegistrationComponent {
|
||||
|
||||
private final Item item;
|
||||
private final Item item;
|
||||
|
||||
private final Map<Integer, ModelResourceLocation> modelsByMeta;
|
||||
private final Map<Integer, ModelResourceLocation> modelsByMeta;
|
||||
|
||||
public ItemModelComponent( @Nonnull Item item, @Nonnull Map<Integer, ModelResourceLocation> modelsByMeta )
|
||||
{
|
||||
this.item = item;
|
||||
this.modelsByMeta = modelsByMeta;
|
||||
}
|
||||
public ItemModelComponent(@Nonnull Item item, @Nonnull Map<Integer, ModelResourceLocation> modelsByMeta) {
|
||||
this.item = item;
|
||||
this.modelsByMeta = modelsByMeta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modelRegistration( Side side, IModelRegistry registry )
|
||||
{
|
||||
this.modelsByMeta.forEach( ( meta, model ) ->
|
||||
{
|
||||
registry.setCustomModelResourceLocation( this.item, meta, model );
|
||||
} );
|
||||
}
|
||||
@Override
|
||||
public void modelRegistration(Side side, IModelRegistry registry) {
|
||||
this.modelsByMeta.forEach((meta, model) ->
|
||||
{
|
||||
registry.setCustomModelResourceLocation(this.item, meta, model);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,32 +19,28 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class ItemVariantsComponent implements IModelRegistrationComponent
|
||||
{
|
||||
public class ItemVariantsComponent implements IModelRegistrationComponent {
|
||||
|
||||
private final Item item;
|
||||
private final Item item;
|
||||
|
||||
private final Collection<ResourceLocation> resources;
|
||||
private final Collection<ResourceLocation> resources;
|
||||
|
||||
public ItemVariantsComponent( Item item, Collection<ResourceLocation> resources )
|
||||
{
|
||||
this.item = item;
|
||||
this.resources = resources;
|
||||
}
|
||||
public ItemVariantsComponent(Item item, Collection<ResourceLocation> resources) {
|
||||
this.item = item;
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modelRegistration( Side side, IModelRegistry registry )
|
||||
{
|
||||
ResourceLocation[] resourceArr = this.resources.toArray( new ResourceLocation[0] );
|
||||
registry.registerItemVariants( this.item, resourceArr );
|
||||
}
|
||||
@Override
|
||||
public void modelRegistration(Side side, IModelRegistry registry) {
|
||||
ResourceLocation[] resourceArr = this.resources.toArray(new ResourceLocation[0]);
|
||||
registry.registerItemVariants(this.item, resourceArr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,8 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
@@ -36,61 +31,55 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
|
||||
public class ModelOverrideComponent implements IPreInitComponent
|
||||
{
|
||||
public class ModelOverrideComponent implements IPreInitComponent {
|
||||
|
||||
private static final ModelResourceLocation MODEL_MISSING = new ModelResourceLocation( "builtin/missing", "missing" );
|
||||
private static final ModelResourceLocation MODEL_MISSING = new ModelResourceLocation("builtin/missing", "missing");
|
||||
|
||||
// Maps from resource path to customizer
|
||||
private final Map<String, BiFunction<ModelResourceLocation, IBakedModel, IBakedModel>> customizer = new HashMap<>();
|
||||
// Maps from resource path to customizer
|
||||
private final Map<String, BiFunction<ModelResourceLocation, IBakedModel, IBakedModel>> customizer = new HashMap<>();
|
||||
|
||||
public void addOverride( String resourcePath, BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer )
|
||||
{
|
||||
this.customizer.put( resourcePath, customizer );
|
||||
}
|
||||
public void addOverride(String resourcePath, BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer) {
|
||||
this.customizer.put(resourcePath, customizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInitialize( Side side )
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register( this );
|
||||
}
|
||||
@Override
|
||||
public void preInitialize(Side side) {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBakeEvent( final ModelBakeEvent event )
|
||||
{
|
||||
IRegistry<ModelResourceLocation, IBakedModel> modelRegistry = event.getModelRegistry();
|
||||
Set<ModelResourceLocation> keys = Sets.newHashSet( modelRegistry.getKeys() );
|
||||
// IBakedModel missingModel = modelRegistry.getObject( MODEL_MISSING );
|
||||
IModel missingModel = ModelLoaderRegistry.getMissingModel();
|
||||
@SubscribeEvent
|
||||
public void onModelBakeEvent(final ModelBakeEvent event) {
|
||||
IRegistry<ModelResourceLocation, IBakedModel> modelRegistry = event.getModelRegistry();
|
||||
Set<ModelResourceLocation> keys = Sets.newHashSet(modelRegistry.getKeys());
|
||||
// IBakedModel missingModel = modelRegistry.getObject( MODEL_MISSING );
|
||||
IModel missingModel = ModelLoaderRegistry.getMissingModel();
|
||||
|
||||
for( ModelResourceLocation location : keys )
|
||||
{
|
||||
if( !location.getResourceDomain().equals( AppEng.MOD_ID ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (ModelResourceLocation location : keys) {
|
||||
if (!location.getResourceDomain().equals(AppEng.MOD_ID)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IBakedModel orgModel = modelRegistry.getObject( location );
|
||||
IBakedModel orgModel = modelRegistry.getObject(location);
|
||||
|
||||
// Don't customize the missing model. This causes Forge to swallow exceptions
|
||||
if( orgModel == missingModel )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// Don't customize the missing model. This causes Forge to swallow exceptions
|
||||
if (orgModel == missingModel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer = this.customizer.get( location.getResourcePath() );
|
||||
if( customizer != null )
|
||||
{
|
||||
IBakedModel newModel = customizer.apply( location, orgModel );
|
||||
BiFunction<ModelResourceLocation, IBakedModel, IBakedModel> customizer = this.customizer.get(location.getResourcePath());
|
||||
if (customizer != null) {
|
||||
IBakedModel newModel = customizer.apply(location, orgModel);
|
||||
|
||||
if( newModel != orgModel )
|
||||
{
|
||||
modelRegistry.putObject( location, newModel );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newModel != orgModel) {
|
||||
modelRegistry.putObject(location, newModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
@@ -26,33 +27,27 @@ import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* Registers a custom state mapper for a given block.
|
||||
*/
|
||||
public class StateMapperComponent implements IModelRegistrationComponent
|
||||
{
|
||||
public class StateMapperComponent implements IModelRegistrationComponent {
|
||||
|
||||
private final Block block;
|
||||
private final Block block;
|
||||
|
||||
private final IStateMapper stateMapper;
|
||||
private final IStateMapper stateMapper;
|
||||
|
||||
public StateMapperComponent( Block block, IStateMapper stateMapper )
|
||||
{
|
||||
this.block = block;
|
||||
this.stateMapper = stateMapper;
|
||||
}
|
||||
public StateMapperComponent(Block block, IStateMapper stateMapper) {
|
||||
this.block = block;
|
||||
this.stateMapper = stateMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modelRegistration( Side side, IModelRegistry registry )
|
||||
{
|
||||
registry.setCustomStateMapper( this.block, this.stateMapper );
|
||||
if( this.stateMapper instanceof IResourceManagerReloadListener )
|
||||
{
|
||||
( (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager() )
|
||||
.registerReloadListener( (IResourceManagerReloadListener) this.stateMapper );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void modelRegistration(Side side, IModelRegistry registry) {
|
||||
registry.setCustomStateMapper(this.block, this.stateMapper);
|
||||
if (this.stateMapper instanceof IResourceManagerReloadListener) {
|
||||
((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager())
|
||||
.registerReloadListener((IResourceManagerReloadListener) this.stateMapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,11 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
|
||||
|
||||
/**
|
||||
* Registers a TESR for a given tile entity class.
|
||||
@@ -32,23 +31,20 @@ import appeng.tile.AEBaseTile;
|
||||
* @param <T>
|
||||
*/
|
||||
// public class TesrComponent<T extends AEBaseTile> implements ModelRegComponent
|
||||
public class TesrComponent<T extends AEBaseTile> implements IPreInitComponent
|
||||
{
|
||||
public class TesrComponent<T extends AEBaseTile> implements IPreInitComponent {
|
||||
|
||||
private final Class<T> tileEntityClass;
|
||||
private final Class<T> tileEntityClass;
|
||||
|
||||
private final TileEntitySpecialRenderer<? super T> tesr;
|
||||
private final TileEntitySpecialRenderer<? super T> tesr;
|
||||
|
||||
public TesrComponent( Class<T> tileEntityClass, TileEntitySpecialRenderer<? super T> tesr )
|
||||
{
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.tesr = tesr;
|
||||
}
|
||||
public TesrComponent(Class<T> tileEntityClass, TileEntitySpecialRenderer<? super T> tesr) {
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.tesr = tesr;
|
||||
}
|
||||
|
||||
@Override
|
||||
// public void modelReg( Side side )
|
||||
public void preInitialize( Side side )
|
||||
{
|
||||
ClientRegistry.bindTileEntitySpecialRenderer( this.tileEntityClass, this.tesr );
|
||||
}
|
||||
@Override
|
||||
// public void modelReg( Side side )
|
||||
public void preInitialize(Side side) {
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(this.tileEntityClass, this.tesr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,37 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AppEng;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AppEng;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author GuntherDW
|
||||
*/
|
||||
public class TileEntityComponent implements IPreInitComponent
|
||||
{
|
||||
private List<TileEntityDefinition> tileEntityDefinitions = new ArrayList<>();
|
||||
public class TileEntityComponent implements IPreInitComponent {
|
||||
private final List<TileEntityDefinition> tileEntityDefinitions = new ArrayList<>();
|
||||
|
||||
public TileEntityComponent()
|
||||
{
|
||||
}
|
||||
public TileEntityComponent() {
|
||||
}
|
||||
|
||||
public void addTileEntity( TileEntityDefinition tileEntityDefinition )
|
||||
{
|
||||
if( !this.tileEntityDefinitions.contains( tileEntityDefinition ) )
|
||||
{
|
||||
this.tileEntityDefinitions.add( tileEntityDefinition );
|
||||
}
|
||||
}
|
||||
public void addTileEntity(TileEntityDefinition tileEntityDefinition) {
|
||||
if (!this.tileEntityDefinitions.contains(tileEntityDefinition)) {
|
||||
this.tileEntityDefinitions.add(tileEntityDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInitialize( Side side )
|
||||
{
|
||||
for( TileEntityDefinition tileEntityDefinition : this.tileEntityDefinitions )
|
||||
{
|
||||
if( !tileEntityDefinition.isRegistered() )
|
||||
{
|
||||
GameRegistry.registerTileEntity( tileEntityDefinition.getTileEntityClass(), AppEng.MOD_ID + ":" + tileEntityDefinition.getName() );
|
||||
tileEntityDefinition.setRegistered( true );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void preInitialize(Side side) {
|
||||
for (TileEntityDefinition tileEntityDefinition : this.tileEntityDefinitions) {
|
||||
if (!tileEntityDefinition.isRegistered()) {
|
||||
GameRegistry.registerTileEntity(tileEntityDefinition.getTileEntityClass(), AppEng.MOD_ID + ":" + tileEntityDefinition.getName());
|
||||
tileEntityDefinition.setRegistered(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,48 +25,40 @@ import appeng.tile.AEBaseTile;
|
||||
/**
|
||||
* @author GuntherDW
|
||||
*/
|
||||
public class TileEntityDefinition
|
||||
{
|
||||
public class TileEntityDefinition {
|
||||
|
||||
private final Class<? extends AEBaseTile> tileEntityClass;
|
||||
private String name;
|
||||
private boolean isRegistered = false;
|
||||
private final Class<? extends AEBaseTile> tileEntityClass;
|
||||
private String name;
|
||||
private boolean isRegistered = false;
|
||||
|
||||
// This signals the BlockDefinitionBuilder to set the name of the TE to the blockname.
|
||||
public TileEntityDefinition( Class<? extends AEBaseTile> tileEntityClass )
|
||||
{
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.name = null;
|
||||
}
|
||||
// This signals the BlockDefinitionBuilder to set the name of the TE to the blockname.
|
||||
public TileEntityDefinition(Class<? extends AEBaseTile> tileEntityClass) {
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.name = null;
|
||||
}
|
||||
|
||||
public TileEntityDefinition( Class<? extends AEBaseTile> tileEntityClass, String optionalName )
|
||||
{
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.name = optionalName;
|
||||
}
|
||||
public TileEntityDefinition(Class<? extends AEBaseTile> tileEntityClass, String optionalName) {
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.name = optionalName;
|
||||
}
|
||||
|
||||
public Class<? extends AEBaseTile> getTileEntityClass()
|
||||
{
|
||||
return this.tileEntityClass;
|
||||
}
|
||||
public Class<? extends AEBaseTile> getTileEntityClass() {
|
||||
return this.tileEntityClass;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isRegistered()
|
||||
{
|
||||
return this.isRegistered;
|
||||
}
|
||||
public boolean isRegistered() {
|
||||
return this.isRegistered;
|
||||
}
|
||||
|
||||
public void setRegistered( boolean registered )
|
||||
{
|
||||
this.isRegistered = registered;
|
||||
}
|
||||
public void setRegistered(boolean registered) {
|
||||
this.isRegistered = registered;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user