Some refactoring of the registry

This commit is contained in:
Emmanuel BENOîT 2016-06-14 17:19:17 +02:00
parent 2519f88bbe
commit eecce3846b
6 changed files with 48 additions and 45 deletions

View file

@ -2,7 +2,7 @@ package mmm;
import mmm.deco.DecorativeBlocks; import mmm.deco.DecorativeBlocks;
import mmm.utils.URegistration; import mmm.utils.URegistry;
import mmm.utils.USeat; import mmm.utils.USeat;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;
@ -33,7 +33,7 @@ public class Mmm
public void preInit( final FMLPreInitializationEvent event ) public void preInit( final FMLPreInitializationEvent event )
{ {
DecorativeBlocks.preInit( ); DecorativeBlocks.preInit( );
URegistration.registerRecipes( ); URegistry.registerRecipes( );
} }
@ -57,7 +57,7 @@ public class Mmm
public void preInit( final FMLPreInitializationEvent event ) public void preInit( final FMLPreInitializationEvent event )
{ {
super.preInit( event ); super.preInit( event );
URegistration.setupItemModels( ); URegistry.setupItemModels( );
} }
} }

View file

@ -6,7 +6,7 @@ import java.util.List;
import mmm.utils.I_UBlockSeat; import mmm.utils.I_UBlockSeat;
import mmm.utils.I_URecipeRegistrar; import mmm.utils.I_URecipeRegistrar;
import mmm.utils.UMaths; import mmm.utils.UMaths;
import mmm.utils.URegistration; import mmm.utils.URegistry;
import mmm.utils.USeat; import mmm.utils.USeat;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal; import net.minecraft.block.BlockHorizontal;
@ -62,7 +62,7 @@ public class DBlockChair
this.setDefaultState( this.blockState.getBaseState( ).withProperty( DBlockChair.FACING , EnumFacing.NORTH ) ); this.setDefaultState( this.blockState.getBaseState( ).withProperty( DBlockChair.FACING , EnumFacing.NORTH ) );
this.setCreativeTab( CreativeTabs.DECORATIONS ); this.setCreativeTab( CreativeTabs.DECORATIONS );
URegistration.setIdentifiers( this , "deco" , "chair" , type.suffix ); URegistry.setIdentifiers( this , "deco" , "chair" , type.suffix );
this.lightOpacity = 0; this.lightOpacity = 0;
this.translucent = false; this.translucent = false;
@ -120,7 +120,7 @@ public class DBlockChair
@Override @Override
public void registerRecipe( ) public void registerRecipes( )
{ {
GameRegistry.addShapedRecipe( new ItemStack( this ) , // GameRegistry.addShapedRecipe( new ItemStack( this ) , //
"B " , // "B " , //

View file

@ -5,7 +5,7 @@ import java.util.List;
import mmm.utils.I_URecipeRegistrar; import mmm.utils.I_URecipeRegistrar;
import mmm.utils.UMaths; import mmm.utils.UMaths;
import mmm.utils.URegistration; import mmm.utils.URegistry;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -76,7 +76,7 @@ public class DBlockTable
.withProperty( DBlockTable.SE , Boolean.valueOf( false ) ) ); .withProperty( DBlockTable.SE , Boolean.valueOf( false ) ) );
this.setCreativeTab( CreativeTabs.DECORATIONS ); this.setCreativeTab( CreativeTabs.DECORATIONS );
URegistration.setIdentifiers( this , "deco" , "table" , type.suffix ); URegistry.setIdentifiers( this , "deco" , "table" , type.suffix );
this.lightOpacity = 0; this.lightOpacity = 0;
this.translucent = false; this.translucent = false;
@ -91,7 +91,7 @@ public class DBlockTable
@Override @Override
public void registerRecipe( ) public void registerRecipes( )
{ {
GameRegistry.addShapedRecipe( new ItemStack( this ) , // GameRegistry.addShapedRecipe( new ItemStack( this ) , //
"BBB" , // "BBB" , //

View file

@ -1,7 +1,7 @@
package mmm.deco; package mmm.deco;
import mmm.utils.URegistration; import mmm.utils.URegistry;
@ -23,19 +23,19 @@ public class DecorativeBlocks
public static final DBlockChair CHAIR_ACACIA; public static final DBlockChair CHAIR_ACACIA;
static { static {
URegistration.addBlock( TABLE_OAK = new DBlockTable( E_DWoodType.OAK ) ); URegistry.addBlock( TABLE_OAK = new DBlockTable( E_DWoodType.OAK ) );
URegistration.addBlock( TABLE_BIRCH = new DBlockTable( E_DWoodType.BIRCH ) ); URegistry.addBlock( TABLE_BIRCH = new DBlockTable( E_DWoodType.BIRCH ) );
URegistration.addBlock( TABLE_SPRUCE = new DBlockTable( E_DWoodType.SPRUCE ) ); URegistry.addBlock( TABLE_SPRUCE = new DBlockTable( E_DWoodType.SPRUCE ) );
URegistration.addBlock( TABLE_JUNGLE = new DBlockTable( E_DWoodType.JUNGLE ) ); URegistry.addBlock( TABLE_JUNGLE = new DBlockTable( E_DWoodType.JUNGLE ) );
URegistration.addBlock( TABLE_DARK_OAK = new DBlockTable( E_DWoodType.DARK_OAK ) ); URegistry.addBlock( TABLE_DARK_OAK = new DBlockTable( E_DWoodType.DARK_OAK ) );
URegistration.addBlock( TABLE_ACACIA = new DBlockTable( E_DWoodType.ACACIA ) ); URegistry.addBlock( TABLE_ACACIA = new DBlockTable( E_DWoodType.ACACIA ) );
URegistration.addBlock( CHAIR_OAK = new DBlockChair( E_DWoodType.OAK ) ); URegistry.addBlock( CHAIR_OAK = new DBlockChair( E_DWoodType.OAK ) );
URegistration.addBlock( CHAIR_BIRCH = new DBlockChair( E_DWoodType.BIRCH ) ); URegistry.addBlock( CHAIR_BIRCH = new DBlockChair( E_DWoodType.BIRCH ) );
URegistration.addBlock( CHAIR_SPRUCE = new DBlockChair( E_DWoodType.SPRUCE ) ); URegistry.addBlock( CHAIR_SPRUCE = new DBlockChair( E_DWoodType.SPRUCE ) );
URegistration.addBlock( CHAIR_JUNGLE = new DBlockChair( E_DWoodType.JUNGLE ) ); URegistry.addBlock( CHAIR_JUNGLE = new DBlockChair( E_DWoodType.JUNGLE ) );
URegistration.addBlock( CHAIR_DARK_OAK = new DBlockChair( E_DWoodType.DARK_OAK ) ); URegistry.addBlock( CHAIR_DARK_OAK = new DBlockChair( E_DWoodType.DARK_OAK ) );
URegistration.addBlock( CHAIR_ACACIA = new DBlockChair( E_DWoodType.ACACIA ) ); URegistry.addBlock( CHAIR_ACACIA = new DBlockChair( E_DWoodType.ACACIA ) );
} }

View file

@ -4,6 +4,6 @@ package mmm.utils;
public interface I_URecipeRegistrar public interface I_URecipeRegistrar
{ {
public void registerRecipe( ); public void registerRecipes( );
} }

View file

@ -17,21 +17,22 @@ import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;
public class URegistration public class URegistry
{ {
private static final HashSet< I_URecipeRegistrar > RECIPE_REGISTRARS = new HashSet< I_URecipeRegistrar >( );
private static final HashMap< Item , Boolean > ITEMS = new HashMap< Item , Boolean >( ); private static final HashMap< Item , Boolean > ITEMS = new HashMap< Item , Boolean >( );
private static final HashSet< Block > BLOCKS = new HashSet< Block >( ); private static final HashSet< Block > BLOCKS = new HashSet< Block >( );
public static void setIdentifiers( final IForgeRegistryEntry< ? > thing , String... strings ) public static void setIdentifiers( final IForgeRegistryEntry< ? > thing , final String... strings )
{ {
int nStrings = strings.length; final int nStrings = strings.length;
if ( nStrings == 0 ) { if ( nStrings == 0 ) {
throw new IllegalArgumentException( "no identifier specified" ); throw new IllegalArgumentException( "no identifier specified" );
} }
StringBuilder sb = new StringBuilder( ); final StringBuilder sb = new StringBuilder( );
for ( int i = 0 ; i < nStrings ; i++ ) { for ( int i = 0 ; i < nStrings ; i++ ) {
if ( i > 0 ) { if ( i > 0 ) {
sb.append( '/' ); sb.append( '/' );
@ -57,32 +58,33 @@ public class URegistration
public static void addItem( final Item item ) public static void addItem( final Item item )
{ {
URegistration.addItem( item , true ); URegistry.addItem( item , true );
} }
public static void addItem( final Item item , final boolean registerModel ) public static void addItem( final Item item , final boolean registerModel )
{ {
GameRegistry.register( item ); GameRegistry.register( item );
URegistration.ITEMS.put( item , registerModel ); URegistry.ITEMS.put( item , registerModel );
URegistry.addRecipeRegistrar( item );
} }
public static void addBlock( final Block block ) public static void addBlock( final Block block )
{ {
URegistration.addBlock( block , true ); URegistry.addBlock( block , true );
} }
public static void addBlock( final Block block , final Item blockItem ) public static void addBlock( final Block block , final Item blockItem )
{ {
URegistration.addBlock( block , blockItem , true ); URegistry.addBlock( block , blockItem , true );
} }
public static void addBlock( final Block block , final boolean registerItemModel ) public static void addBlock( final Block block , final boolean registerItemModel )
{ {
URegistration.addBlock( block , new ItemBlock( block ).setRegistryName( block.getRegistryName( ) ) , URegistry.addBlock( block , new ItemBlock( block ).setRegistryName( block.getRegistryName( ) ) ,
registerItemModel ); registerItemModel );
} }
@ -90,32 +92,33 @@ public class URegistration
public static void addBlock( final Block block , final Item blockItem , final boolean registerItemModel ) public static void addBlock( final Block block , final Item blockItem , final boolean registerItemModel )
{ {
GameRegistry.register( block ); GameRegistry.register( block );
URegistration.BLOCKS.add( block ); URegistry.BLOCKS.add( block );
URegistry.addRecipeRegistrar( block );
if ( blockItem != null ) { if ( blockItem != null ) {
URegistration.addItem( blockItem , registerItemModel ); URegistry.addItem( blockItem , registerItemModel );
}
}
public static void addRecipeRegistrar( final Object object )
{
if ( object instanceof I_URecipeRegistrar ) {
URegistry.RECIPE_REGISTRARS.add( (I_URecipeRegistrar) object );
} }
} }
public static void registerRecipes( ) public static void registerRecipes( )
{ {
for ( final Block block : URegistration.BLOCKS ) { for ( final I_URecipeRegistrar registrar : URegistry.RECIPE_REGISTRARS ) {
if ( block instanceof I_URecipeRegistrar ) { registrar.registerRecipes( );
( (I_URecipeRegistrar) block ).registerRecipe( );
}
}
for ( final Item item : URegistration.ITEMS.keySet( ) ) {
if ( item instanceof I_URecipeRegistrar ) {
( (I_URecipeRegistrar) item ).registerRecipe( );
}
} }
} }
public static void setupItemModels( ) public static void setupItemModels( )
{ {
for ( final Map.Entry< Item , Boolean > entry : URegistration.ITEMS.entrySet( ) ) { for ( final Map.Entry< Item , Boolean > entry : URegistry.ITEMS.entrySet( ) ) {
if ( !entry.getValue( ) ) { if ( !entry.getValue( ) ) {
continue; continue;
} }