From eecce3846bd99d89c7e584f54efb9152080794a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Tue, 14 Jun 2016 17:19:17 +0200 Subject: [PATCH] Some refactoring of the registry --- src/java/mmm/Mmm.java | 6 +-- src/java/mmm/deco/DBlockChair.java | 6 +-- src/java/mmm/deco/DBlockTable.java | 6 +-- src/java/mmm/deco/DecorativeBlocks.java | 26 +++++----- src/java/mmm/utils/I_URecipeRegistrar.java | 2 +- .../{URegistration.java => URegistry.java} | 47 ++++++++++--------- 6 files changed, 48 insertions(+), 45 deletions(-) rename src/java/mmm/utils/{URegistration.java => URegistry.java} (68%) diff --git a/src/java/mmm/Mmm.java b/src/java/mmm/Mmm.java index 3f1af5d..2e9e97d 100644 --- a/src/java/mmm/Mmm.java +++ b/src/java/mmm/Mmm.java @@ -2,7 +2,7 @@ package mmm; import mmm.deco.DecorativeBlocks; -import mmm.utils.URegistration; +import mmm.utils.URegistry; import mmm.utils.USeat; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; @@ -33,7 +33,7 @@ public class Mmm public void preInit( final FMLPreInitializationEvent event ) { DecorativeBlocks.preInit( ); - URegistration.registerRecipes( ); + URegistry.registerRecipes( ); } @@ -57,7 +57,7 @@ public class Mmm public void preInit( final FMLPreInitializationEvent event ) { super.preInit( event ); - URegistration.setupItemModels( ); + URegistry.setupItemModels( ); } } diff --git a/src/java/mmm/deco/DBlockChair.java b/src/java/mmm/deco/DBlockChair.java index e480e1f..3169084 100644 --- a/src/java/mmm/deco/DBlockChair.java +++ b/src/java/mmm/deco/DBlockChair.java @@ -6,7 +6,7 @@ import java.util.List; import mmm.utils.I_UBlockSeat; import mmm.utils.I_URecipeRegistrar; import mmm.utils.UMaths; -import mmm.utils.URegistration; +import mmm.utils.URegistry; import mmm.utils.USeat; import net.minecraft.block.Block; import net.minecraft.block.BlockHorizontal; @@ -62,7 +62,7 @@ public class DBlockChair this.setDefaultState( this.blockState.getBaseState( ).withProperty( DBlockChair.FACING , EnumFacing.NORTH ) ); this.setCreativeTab( CreativeTabs.DECORATIONS ); - URegistration.setIdentifiers( this , "deco" , "chair" , type.suffix ); + URegistry.setIdentifiers( this , "deco" , "chair" , type.suffix ); this.lightOpacity = 0; this.translucent = false; @@ -120,7 +120,7 @@ public class DBlockChair @Override - public void registerRecipe( ) + public void registerRecipes( ) { GameRegistry.addShapedRecipe( new ItemStack( this ) , // "B " , // diff --git a/src/java/mmm/deco/DBlockTable.java b/src/java/mmm/deco/DBlockTable.java index af887d7..9ee20c2 100644 --- a/src/java/mmm/deco/DBlockTable.java +++ b/src/java/mmm/deco/DBlockTable.java @@ -5,7 +5,7 @@ import java.util.List; import mmm.utils.I_URecipeRegistrar; import mmm.utils.UMaths; -import mmm.utils.URegistration; +import mmm.utils.URegistry; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; @@ -76,7 +76,7 @@ public class DBlockTable .withProperty( DBlockTable.SE , Boolean.valueOf( false ) ) ); this.setCreativeTab( CreativeTabs.DECORATIONS ); - URegistration.setIdentifiers( this , "deco" , "table" , type.suffix ); + URegistry.setIdentifiers( this , "deco" , "table" , type.suffix ); this.lightOpacity = 0; this.translucent = false; @@ -91,7 +91,7 @@ public class DBlockTable @Override - public void registerRecipe( ) + public void registerRecipes( ) { GameRegistry.addShapedRecipe( new ItemStack( this ) , // "BBB" , // diff --git a/src/java/mmm/deco/DecorativeBlocks.java b/src/java/mmm/deco/DecorativeBlocks.java index 2c97e28..9f18015 100644 --- a/src/java/mmm/deco/DecorativeBlocks.java +++ b/src/java/mmm/deco/DecorativeBlocks.java @@ -1,7 +1,7 @@ package mmm.deco; -import mmm.utils.URegistration; +import mmm.utils.URegistry; @@ -23,19 +23,19 @@ public class DecorativeBlocks public static final DBlockChair CHAIR_ACACIA; static { - URegistration.addBlock( TABLE_OAK = new DBlockTable( E_DWoodType.OAK ) ); - URegistration.addBlock( TABLE_BIRCH = new DBlockTable( E_DWoodType.BIRCH ) ); - URegistration.addBlock( TABLE_SPRUCE = new DBlockTable( E_DWoodType.SPRUCE ) ); - URegistration.addBlock( TABLE_JUNGLE = new DBlockTable( E_DWoodType.JUNGLE ) ); - URegistration.addBlock( TABLE_DARK_OAK = new DBlockTable( E_DWoodType.DARK_OAK ) ); - URegistration.addBlock( TABLE_ACACIA = new DBlockTable( E_DWoodType.ACACIA ) ); + URegistry.addBlock( TABLE_OAK = new DBlockTable( E_DWoodType.OAK ) ); + URegistry.addBlock( TABLE_BIRCH = new DBlockTable( E_DWoodType.BIRCH ) ); + URegistry.addBlock( TABLE_SPRUCE = new DBlockTable( E_DWoodType.SPRUCE ) ); + URegistry.addBlock( TABLE_JUNGLE = new DBlockTable( E_DWoodType.JUNGLE ) ); + URegistry.addBlock( TABLE_DARK_OAK = new DBlockTable( E_DWoodType.DARK_OAK ) ); + URegistry.addBlock( TABLE_ACACIA = new DBlockTable( E_DWoodType.ACACIA ) ); - URegistration.addBlock( CHAIR_OAK = new DBlockChair( E_DWoodType.OAK ) ); - URegistration.addBlock( CHAIR_BIRCH = new DBlockChair( E_DWoodType.BIRCH ) ); - URegistration.addBlock( CHAIR_SPRUCE = new DBlockChair( E_DWoodType.SPRUCE ) ); - URegistration.addBlock( CHAIR_JUNGLE = new DBlockChair( E_DWoodType.JUNGLE ) ); - URegistration.addBlock( CHAIR_DARK_OAK = new DBlockChair( E_DWoodType.DARK_OAK ) ); - URegistration.addBlock( CHAIR_ACACIA = new DBlockChair( E_DWoodType.ACACIA ) ); + URegistry.addBlock( CHAIR_OAK = new DBlockChair( E_DWoodType.OAK ) ); + URegistry.addBlock( CHAIR_BIRCH = new DBlockChair( E_DWoodType.BIRCH ) ); + URegistry.addBlock( CHAIR_SPRUCE = new DBlockChair( E_DWoodType.SPRUCE ) ); + URegistry.addBlock( CHAIR_JUNGLE = new DBlockChair( E_DWoodType.JUNGLE ) ); + URegistry.addBlock( CHAIR_DARK_OAK = new DBlockChair( E_DWoodType.DARK_OAK ) ); + URegistry.addBlock( CHAIR_ACACIA = new DBlockChair( E_DWoodType.ACACIA ) ); } diff --git a/src/java/mmm/utils/I_URecipeRegistrar.java b/src/java/mmm/utils/I_URecipeRegistrar.java index 8e15f0f..8af9b90 100644 --- a/src/java/mmm/utils/I_URecipeRegistrar.java +++ b/src/java/mmm/utils/I_URecipeRegistrar.java @@ -4,6 +4,6 @@ package mmm.utils; public interface I_URecipeRegistrar { - public void registerRecipe( ); + public void registerRecipes( ); } diff --git a/src/java/mmm/utils/URegistration.java b/src/java/mmm/utils/URegistry.java similarity index 68% rename from src/java/mmm/utils/URegistration.java rename to src/java/mmm/utils/URegistry.java index 151fda7..a6dd2f3 100644 --- a/src/java/mmm/utils/URegistration.java +++ b/src/java/mmm/utils/URegistry.java @@ -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 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 ) { throw new IllegalArgumentException( "no identifier specified" ); } - StringBuilder sb = new StringBuilder( ); + final StringBuilder sb = new StringBuilder( ); for ( int i = 0 ; i < nStrings ; i++ ) { if ( i > 0 ) { sb.append( '/' ); @@ -57,32 +58,33 @@ public class URegistration 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 ) { GameRegistry.register( item ); - URegistration.ITEMS.put( item , registerModel ); + URegistry.ITEMS.put( item , registerModel ); + URegistry.addRecipeRegistrar( item ); } 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 ) { - URegistration.addBlock( block , blockItem , true ); + URegistry.addBlock( block , blockItem , true ); } 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 ); } @@ -90,32 +92,33 @@ public class URegistration public static void addBlock( final Block block , final Item blockItem , final boolean registerItemModel ) { GameRegistry.register( block ); - URegistration.BLOCKS.add( block ); + URegistry.BLOCKS.add( block ); + URegistry.addRecipeRegistrar( block ); 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( ) { - for ( final Block block : URegistration.BLOCKS ) { - if ( block instanceof I_URecipeRegistrar ) { - ( (I_URecipeRegistrar) block ).registerRecipe( ); - } - } - - for ( final Item item : URegistration.ITEMS.keySet( ) ) { - if ( item instanceof I_URecipeRegistrar ) { - ( (I_URecipeRegistrar) item ).registerRecipe( ); - } + for ( final I_URecipeRegistrar registrar : URegistry.RECIPE_REGISTRARS ) { + registrar.registerRecipes( ); } } 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( ) ) { continue; }