From f44e8bd7b7f5612be3ecb4d7bf848a8976a5cb26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Tue, 12 Jul 2016 20:56:55 +0200 Subject: [PATCH] More refactoring --- src/java/mmm/MmmMaterials.java | 6 ++-- src/java/mmm/core/CRegistry.java | 5 --- src/java/mmm/deco/DStairs.java | 2 +- src/java/mmm/deco/slabs/DSlabParts.java | 2 +- src/java/mmm/materials/MTraps.java | 30 ---------------- src/java/mmm/materials/MWood.java | 1 + src/java/mmm/materials/{ => traps}/MMud.java | 2 +- .../mmm/materials/{ => traps}/MQuicksand.java | 2 +- .../mmm/materials/{ => traps}/MSwampPit.java | 2 +- .../{MTrapBlocks.java => traps/MTraps.java} | 35 +++++++++++++++---- .../mmm/materials/{ => trees}/MLeaves.java | 2 +- src/java/mmm/materials/{ => trees}/MLog.java | 2 +- .../mmm/materials/{ => trees}/MPlanks.java | 2 +- .../mmm/materials/{ => trees}/MSapling.java | 2 +- src/java/mmm/materials/{ => trees}/MTree.java | 2 +- .../mmm/materials/{ => trees}/MTrees.java | 2 +- .../{ => trees}/MWoodAchievementHandler.java | 2 +- src/java/mmm/world/gen/WGTrapBlocks.java | 6 ++-- .../mmm/world/trees/A_WTTreeGenerator.java | 4 +-- src/java/mmm/world/trees/WTBamboo.java | 2 +- src/java/mmm/world/trees/WTHeveaBig.java | 2 +- src/java/mmm/world/trees/WTHeveaMega.java | 2 +- 22 files changed, 53 insertions(+), 64 deletions(-) delete mode 100644 src/java/mmm/materials/MTraps.java rename src/java/mmm/materials/{ => traps}/MMud.java (98%) rename src/java/mmm/materials/{ => traps}/MQuicksand.java (98%) rename src/java/mmm/materials/{ => traps}/MSwampPit.java (98%) rename src/java/mmm/materials/{MTrapBlocks.java => traps/MTraps.java} (59%) rename src/java/mmm/materials/{ => trees}/MLeaves.java (99%) rename src/java/mmm/materials/{ => trees}/MLog.java (99%) rename src/java/mmm/materials/{ => trees}/MPlanks.java (95%) rename src/java/mmm/materials/{ => trees}/MSapling.java (99%) rename src/java/mmm/materials/{ => trees}/MTree.java (99%) rename src/java/mmm/materials/{ => trees}/MTrees.java (97%) rename src/java/mmm/materials/{ => trees}/MWoodAchievementHandler.java (95%) diff --git a/src/java/mmm/MmmMaterials.java b/src/java/mmm/MmmMaterials.java index 155f6ff..c12e703 100644 --- a/src/java/mmm/MmmMaterials.java +++ b/src/java/mmm/MmmMaterials.java @@ -8,10 +8,10 @@ import mmm.materials.MItems; import mmm.materials.MMetals; import mmm.materials.MOres; import mmm.materials.MRocks; -import mmm.materials.MTraps; -import mmm.materials.MTrees; -import mmm.materials.MWoodAchievementHandler; import mmm.materials.MWoods; +import mmm.materials.traps.MTraps; +import mmm.materials.trees.MTrees; +import mmm.materials.trees.MWoodAchievementHandler; import net.minecraft.block.Block; import net.minecraft.block.BlockStone; import net.minecraft.block.state.IBlockState; diff --git a/src/java/mmm/core/CRegistry.java b/src/java/mmm/core/CRegistry.java index 00013c5..1237085 100644 --- a/src/java/mmm/core/CRegistry.java +++ b/src/java/mmm/core/CRegistry.java @@ -15,12 +15,10 @@ import mmm.core.api.I_RequiresClientPreInit; import mmm.core.api.blocks.I_ColoredBlock; import mmm.core.api.blocks.I_StateMapperProvider; import mmm.core.api.blocks.I_TintedBlock; -import mmm.core.api.blocks.I_TrapBlock; import mmm.core.api.items.I_ItemModelProvider; import mmm.core.api.items.I_ItemModelProviderBasic; import mmm.core.api.items.I_ItemWithVariants; import mmm.core.api.items.I_TintedItem; -import mmm.materials.MTrapBlocks; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ModelResourceLocation; @@ -143,9 +141,6 @@ public class CRegistry GameRegistry.register( block ); CRegistry.addRecipeRegistrar( block ); CRegistry.addOreGenerationRegistrar( block ); - if ( block instanceof I_TrapBlock ) { - MTrapBlocks.INSTANCE.register( (I_TrapBlock) block ); - } if ( block instanceof I_RequiresClientPreInit ) { CRegistry.BLOCKS_CLIENT_PREINIT.add( block ); } diff --git a/src/java/mmm/deco/DStairs.java b/src/java/mmm/deco/DStairs.java index 464e1fe..b37485c 100644 --- a/src/java/mmm/deco/DStairs.java +++ b/src/java/mmm/deco/DStairs.java @@ -5,7 +5,7 @@ import mmm.MmmDeco; import mmm.MmmMaterials; import mmm.core.CRegistry; import mmm.core.api.I_RecipeRegistrar; -import mmm.materials.MTree; +import mmm.materials.trees.MTree; import net.minecraft.block.Block; import net.minecraft.block.BlockStairs; import net.minecraft.block.BlockStone; diff --git a/src/java/mmm/deco/slabs/DSlabParts.java b/src/java/mmm/deco/slabs/DSlabParts.java index 79f99c2..1cfe119 100644 --- a/src/java/mmm/deco/slabs/DSlabParts.java +++ b/src/java/mmm/deco/slabs/DSlabParts.java @@ -4,7 +4,7 @@ package mmm.deco.slabs; import mmm.core.CRegistry; import mmm.core.api.I_RecipeRegistrar; import mmm.deco.DSmoothStone; -import mmm.materials.MTree; +import mmm.materials.trees.MTree; import net.minecraft.block.Block; import net.minecraft.block.BlockStone; import net.minecraft.block.state.IBlockState; diff --git a/src/java/mmm/materials/MTraps.java b/src/java/mmm/materials/MTraps.java deleted file mode 100644 index 52b666e..0000000 --- a/src/java/mmm/materials/MTraps.java +++ /dev/null @@ -1,30 +0,0 @@ -package mmm.materials; - - -import mmm.core.CRegistry; -import net.minecraft.block.BlockSand; -import net.minecraft.init.Blocks; - - - -public class MTraps -{ - public final MQuicksand QUICKSAND; - public final MQuicksand RED_QUICKSAND; - public final MSwampPit SWAMP_PIT; - public final MMud MUD; - - - public MTraps( ) - { - // FIXME recipes to convert quicksand into sand or mud into dirt - CRegistry.addBlock( this.QUICKSAND = new MQuicksand( "sand" , // - Blocks.SAND.getDefaultState( ) // - .withProperty( BlockSand.VARIANT , BlockSand.EnumType.SAND ) ) ); - CRegistry.addBlock( this.RED_QUICKSAND = new MQuicksand( "red_sand" , // - Blocks.SAND.getDefaultState( ) // - .withProperty( BlockSand.VARIANT , BlockSand.EnumType.RED_SAND ) ) ); - CRegistry.addBlock( this.SWAMP_PIT = new MSwampPit( ) ); - CRegistry.addBlock( this.MUD = new MMud( ) ); - } -} diff --git a/src/java/mmm/materials/MWood.java b/src/java/mmm/materials/MWood.java index 0edf9ed..cba6ba4 100644 --- a/src/java/mmm/materials/MWood.java +++ b/src/java/mmm/materials/MWood.java @@ -2,6 +2,7 @@ package mmm.materials; import mmm.Mmm; +import mmm.materials.trees.MTree; import net.minecraft.block.Block; import net.minecraft.block.BlockPlanks; import net.minecraft.block.material.MapColor; diff --git a/src/java/mmm/materials/MMud.java b/src/java/mmm/materials/traps/MMud.java similarity index 98% rename from src/java/mmm/materials/MMud.java rename to src/java/mmm/materials/traps/MMud.java index a69a03b..22ff4af 100644 --- a/src/java/mmm/materials/MMud.java +++ b/src/java/mmm/materials/traps/MMud.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.traps; import mmm.core.CRegistry; diff --git a/src/java/mmm/materials/MQuicksand.java b/src/java/mmm/materials/traps/MQuicksand.java similarity index 98% rename from src/java/mmm/materials/MQuicksand.java rename to src/java/mmm/materials/traps/MQuicksand.java index af991bd..4479377 100644 --- a/src/java/mmm/materials/MQuicksand.java +++ b/src/java/mmm/materials/traps/MQuicksand.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.traps; import mmm.core.CRegistry; diff --git a/src/java/mmm/materials/MSwampPit.java b/src/java/mmm/materials/traps/MSwampPit.java similarity index 98% rename from src/java/mmm/materials/MSwampPit.java rename to src/java/mmm/materials/traps/MSwampPit.java index 588c934..5ac394b 100644 --- a/src/java/mmm/materials/MSwampPit.java +++ b/src/java/mmm/materials/traps/MSwampPit.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.traps; import mmm.core.api.blocks.I_TintedBlock; diff --git a/src/java/mmm/materials/MTrapBlocks.java b/src/java/mmm/materials/traps/MTraps.java similarity index 59% rename from src/java/mmm/materials/MTrapBlocks.java rename to src/java/mmm/materials/traps/MTraps.java index c28dc3c..b22957d 100644 --- a/src/java/mmm/materials/MTrapBlocks.java +++ b/src/java/mmm/materials/traps/MTraps.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.traps; import java.util.ArrayList; @@ -8,27 +8,51 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Lists; +import mmm.core.CRegistry; import mmm.core.api.blocks.I_TrapBlock; import net.minecraft.block.Block; +import net.minecraft.block.BlockSand; import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; -public enum MTrapBlocks { - INSTANCE; +public class MTraps +{ + public final MQuicksand QUICKSAND; + public final MQuicksand RED_QUICKSAND; + public final MSwampPit SWAMP_PIT; + public final MMud MUD; private final ArrayListMultimap< IBlockState , I_TrapBlock > traps = ArrayListMultimap.create( ); private final ArrayListMultimap< IBlockState , IBlockState > replacements = ArrayListMultimap.create( ); private final LinkedHashMultimap< IBlockState , String > trapTypes = LinkedHashMultimap.create( ); - public void register( final I_TrapBlock block ) + public MTraps( ) { + // FIXME recipes to convert quicksand into sand or mud into dirt + this.QUICKSAND = this.register( new MQuicksand( "sand" , // + Blocks.SAND.getDefaultState( ) // + .withProperty( BlockSand.VARIANT , BlockSand.EnumType.SAND ) ) ); + this.RED_QUICKSAND = this.register( new MQuicksand( "red_sand" , // + Blocks.SAND.getDefaultState( ) // + .withProperty( BlockSand.VARIANT , BlockSand.EnumType.RED_SAND ) ) ); + this.SWAMP_PIT = this.register( new MSwampPit( ) ); + this.MUD = this.register( new MMud( ) ); + } + + + public < T extends Block & I_TrapBlock > T register( final T block ) + { + Block asMcBlock = (Block) block; for ( final IBlockState state : block.getReplacedBlocks( ) ) { this.traps.put( state , block ); this.trapTypes.put( state , block.getTrapType( ) ); - this.replacements.put( state , ( (Block) block ).getDefaultState( ) ); + this.replacements.put( state , asMcBlock.getDefaultState( ) ); } + CRegistry.addBlock( asMcBlock ); + return block; } @@ -57,5 +81,4 @@ public enum MTrapBlocks { { return Lists.newArrayList( this.trapTypes.get( blockState ) ); } - } diff --git a/src/java/mmm/materials/MLeaves.java b/src/java/mmm/materials/trees/MLeaves.java similarity index 99% rename from src/java/mmm/materials/MLeaves.java rename to src/java/mmm/materials/trees/MLeaves.java index 840ff14..c14d9e5 100644 --- a/src/java/mmm/materials/MLeaves.java +++ b/src/java/mmm/materials/trees/MLeaves.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.trees; import java.util.Arrays; diff --git a/src/java/mmm/materials/MLog.java b/src/java/mmm/materials/trees/MLog.java similarity index 99% rename from src/java/mmm/materials/MLog.java rename to src/java/mmm/materials/trees/MLog.java index 33fc9d9..bf53faa 100644 --- a/src/java/mmm/materials/MLog.java +++ b/src/java/mmm/materials/trees/MLog.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.trees; import mmm.core.CRegistry; diff --git a/src/java/mmm/materials/MPlanks.java b/src/java/mmm/materials/trees/MPlanks.java similarity index 95% rename from src/java/mmm/materials/MPlanks.java rename to src/java/mmm/materials/trees/MPlanks.java index a98b17d..e7fd4a0 100644 --- a/src/java/mmm/materials/MPlanks.java +++ b/src/java/mmm/materials/trees/MPlanks.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.trees; import mmm.core.CRegistry; diff --git a/src/java/mmm/materials/MSapling.java b/src/java/mmm/materials/trees/MSapling.java similarity index 99% rename from src/java/mmm/materials/MSapling.java rename to src/java/mmm/materials/trees/MSapling.java index abca5d3..186e805 100644 --- a/src/java/mmm/materials/MSapling.java +++ b/src/java/mmm/materials/trees/MSapling.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.trees; import java.util.Random; diff --git a/src/java/mmm/materials/MTree.java b/src/java/mmm/materials/trees/MTree.java similarity index 99% rename from src/java/mmm/materials/MTree.java rename to src/java/mmm/materials/trees/MTree.java index f6f6d0b..9abf686 100644 --- a/src/java/mmm/materials/MTree.java +++ b/src/java/mmm/materials/trees/MTree.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.trees; import java.util.Random; diff --git a/src/java/mmm/materials/MTrees.java b/src/java/mmm/materials/trees/MTrees.java similarity index 97% rename from src/java/mmm/materials/MTrees.java rename to src/java/mmm/materials/trees/MTrees.java index 8e124e4..9d739f1 100644 --- a/src/java/mmm/materials/MTrees.java +++ b/src/java/mmm/materials/trees/MTrees.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.trees; import mmm.utils.UMaths; diff --git a/src/java/mmm/materials/MWoodAchievementHandler.java b/src/java/mmm/materials/trees/MWoodAchievementHandler.java similarity index 95% rename from src/java/mmm/materials/MWoodAchievementHandler.java rename to src/java/mmm/materials/trees/MWoodAchievementHandler.java index 50f382f..af16658 100644 --- a/src/java/mmm/materials/MWoodAchievementHandler.java +++ b/src/java/mmm/materials/trees/MWoodAchievementHandler.java @@ -1,4 +1,4 @@ -package mmm.materials; +package mmm.materials.trees; import net.minecraft.item.Item; diff --git a/src/java/mmm/world/gen/WGTrapBlocks.java b/src/java/mmm/world/gen/WGTrapBlocks.java index 5643a72..958396d 100644 --- a/src/java/mmm/world/gen/WGTrapBlocks.java +++ b/src/java/mmm/world/gen/WGTrapBlocks.java @@ -7,7 +7,7 @@ import java.util.Random; import com.google.common.collect.Lists; -import mmm.materials.MTrapBlocks; +import mmm.MmmMaterials; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; @@ -82,7 +82,7 @@ public class WGTrapBlocks final BlockPos pos = bp.add( x , y , z ); final IBlockState atPos = worldIn.getBlockState( pos ); - final List< String > trapTypes = MTrapBlocks.INSTANCE.getTrapTypes( atPos ); + final List< String > trapTypes = MmmMaterials.TRAP.getTrapTypes( atPos ); for ( final String rep : trapTypes ) { if ( !types.contains( rep ) ) { types.add( rep ); @@ -105,7 +105,7 @@ public class WGTrapBlocks final BlockPos pos = bp.add( x , y , z ); final IBlockState atPos = worldIn.getBlockState( pos ); - final List< IBlockState > replacements = MTrapBlocks.INSTANCE.getReplacements( atPos , trapType ); + final List< IBlockState > replacements = MmmMaterials.TRAP.getReplacements( atPos , trapType ); final int nReplacements = replacements.size( ); if ( nReplacements == 0 ) { continue; diff --git a/src/java/mmm/world/trees/A_WTTreeGenerator.java b/src/java/mmm/world/trees/A_WTTreeGenerator.java index 9d4965c..fa18041 100644 --- a/src/java/mmm/world/trees/A_WTTreeGenerator.java +++ b/src/java/mmm/world/trees/A_WTTreeGenerator.java @@ -3,8 +3,8 @@ package mmm.world.trees; import java.util.Random; -import mmm.materials.MSapling; -import mmm.materials.MTree; +import mmm.materials.trees.MSapling; +import mmm.materials.trees.MTree; import net.minecraft.block.Block; import net.minecraft.block.BlockBush; import net.minecraft.block.BlockFlower; diff --git a/src/java/mmm/world/trees/WTBamboo.java b/src/java/mmm/world/trees/WTBamboo.java index f177ca9..38a3505 100644 --- a/src/java/mmm/world/trees/WTBamboo.java +++ b/src/java/mmm/world/trees/WTBamboo.java @@ -4,7 +4,7 @@ package mmm.world.trees; import java.util.Random; import mmm.MmmMaterials; -import mmm.materials.MTree; +import mmm.materials.trees.MTree; import net.minecraft.block.BlockLeaves; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; diff --git a/src/java/mmm/world/trees/WTHeveaBig.java b/src/java/mmm/world/trees/WTHeveaBig.java index 6ca61cf..9156edf 100644 --- a/src/java/mmm/world/trees/WTHeveaBig.java +++ b/src/java/mmm/world/trees/WTHeveaBig.java @@ -3,7 +3,7 @@ package mmm.world.trees; import java.util.Random; -import mmm.materials.MLog; +import mmm.materials.trees.MLog; import net.minecraft.block.BlockLog; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; diff --git a/src/java/mmm/world/trees/WTHeveaMega.java b/src/java/mmm/world/trees/WTHeveaMega.java index 9cb7e13..3dad496 100644 --- a/src/java/mmm/world/trees/WTHeveaMega.java +++ b/src/java/mmm/world/trees/WTHeveaMega.java @@ -4,7 +4,7 @@ package mmm.world.trees; import java.util.Random; import mmm.MmmMaterials; -import mmm.materials.MTree; +import mmm.materials.trees.MTree; import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockLog; import net.minecraft.block.state.IBlockState;