From bb88579c9f2a36845af98257d82756c4fde7425e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Fri, 8 Jul 2016 09:09:38 +0200 Subject: [PATCH] Basalt + better custom rocks Avoid having classes for each type of rock, add generation conditions from the Materials directly. --- src/java/mmm/materials/I_MRock.java | 7 ++ src/java/mmm/materials/MRock.java | 66 +++++++++++++++++ src/java/mmm/materials/Materials.java | 68 ++++++++++++++---- src/java/mmm/materials/ore/MOCinnabar.java | 3 +- src/java/mmm/materials/rock/MRChalk.java | 28 -------- src/java/mmm/materials/rock/MRLimestone.java | 43 ----------- src/java/mmm/materials/rock/MRSlate.java | 49 ------------- src/java/mmm/world/gen/WGBasalt.java | 25 +++++++ src/java/mmm/world/gen/WGOreParameters.java | 38 ++++++++-- .../blockstates/materials/rock/basalt.json | 5 ++ src/resources/assets/mmm/lang/en_US.lang | 1 + .../models/block/materials/rock/basalt.json | 6 ++ .../models/item/materials/rock/basalt.json | 3 + .../textures/blocks/materials/rock/basalt.png | Bin 0 -> 260 bytes 14 files changed, 205 insertions(+), 137 deletions(-) create mode 100644 src/java/mmm/materials/I_MRock.java create mode 100644 src/java/mmm/materials/MRock.java delete mode 100644 src/java/mmm/materials/rock/MRChalk.java delete mode 100644 src/java/mmm/materials/rock/MRLimestone.java delete mode 100644 src/java/mmm/materials/rock/MRSlate.java create mode 100644 src/java/mmm/world/gen/WGBasalt.java create mode 100644 src/resources/assets/mmm/blockstates/materials/rock/basalt.json create mode 100644 src/resources/assets/mmm/models/block/materials/rock/basalt.json create mode 100644 src/resources/assets/mmm/models/item/materials/rock/basalt.json create mode 100644 src/resources/assets/mmm/textures/blocks/materials/rock/basalt.png diff --git a/src/java/mmm/materials/I_MRock.java b/src/java/mmm/materials/I_MRock.java new file mode 100644 index 0000000..496dab5 --- /dev/null +++ b/src/java/mmm/materials/I_MRock.java @@ -0,0 +1,7 @@ +package mmm.materials; + + +public interface I_MRock +{ + // EMPTY +} diff --git a/src/java/mmm/materials/MRock.java b/src/java/mmm/materials/MRock.java new file mode 100644 index 0000000..8d8b09e --- /dev/null +++ b/src/java/mmm/materials/MRock.java @@ -0,0 +1,66 @@ +package mmm.materials; + + +import java.util.List; + +import mmm.utils.I_UOreGenerationRegistrar; +import mmm.utils.URegistry; +import mmm.world.gen.WGOreCondition; +import net.minecraft.block.Block; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import net.minecraft.creativetab.CreativeTabs; + + + +public class MRock + extends Block + implements I_MRock , I_UOreGenerationRegistrar +{ + + private WGOreCondition[] genConditions; + + + public MRock( final String name , final MapColor mapColor ) + { + this( name , mapColor , 0 , 1.5f , 10f ); + } + + + public MRock( final String name , final MapColor mapColor , final int harvestLevel ) + { + this( name , mapColor , harvestLevel , 1.5f , 10f ); + } + + + public MRock( final String name , final MapColor mapColor , final int harvestLevel , final float hardness , + final float resistance ) + { + super( Material.ROCK , mapColor ); + this.setCreativeTab( CreativeTabs.BUILDING_BLOCKS ); + this.setHardness( hardness ); + this.setResistance( resistance ); + this.setSoundType( SoundType.STONE ); + this.setHarvestLevel( "pickaxe" , harvestLevel ); + URegistry.setIdentifiers( this , "materials" , "rock" , name ); + URegistry.addBlock( this ); + } + + + public MRock setConditions( final WGOreCondition... genConditions ) + { + this.genConditions = genConditions.clone( ); + return this; + } + + + @Override + public void addConditions( final List< WGOreCondition > conditions ) + { + for ( int i = 0 ; i < this.genConditions.length ; i++ ) { + conditions.add( this.genConditions[ i ] ); + } + } + +} diff --git a/src/java/mmm/materials/Materials.java b/src/java/mmm/materials/Materials.java index 50d1418..dda175d 100644 --- a/src/java/mmm/materials/Materials.java +++ b/src/java/mmm/materials/Materials.java @@ -1,6 +1,8 @@ package mmm.materials; +import java.util.List; + import mmm.materials.ore.MOBauxite; import mmm.materials.ore.MOCassiterite; import mmm.materials.ore.MOCinnabar; @@ -10,25 +12,33 @@ import mmm.materials.ore.MOGalena; import mmm.materials.ore.MOMalachite; import mmm.materials.ore.MORockSalt; import mmm.materials.ore.MOSphalerite; -import mmm.materials.rock.MRChalk; -import mmm.materials.rock.MRLimestone; -import mmm.materials.rock.MRSlate; +import mmm.utils.I_UOreGenerationRegistrar; import mmm.utils.I_URecipeRegistrar; import mmm.utils.URegistry; +import mmm.world.WLocation; +import mmm.world.WLocationInBiome; +import mmm.world.gen.WGOreCondition; +import mmm.world.gen.WGOreParameters; +import net.minecraft.block.Block; +import net.minecraft.block.BlockStone; import net.minecraft.block.material.MapColor; +import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; +import net.minecraft.world.biome.BiomePlains; +import net.minecraft.world.biome.BiomeSwamp; public class Materials - implements I_URecipeRegistrar + implements I_URecipeRegistrar , I_UOreGenerationRegistrar { - public static final MRLimestone ROCK_LIMESTONE; - public static final MRChalk ROCK_CHALK; - public static final MRSlate ROCK_SLATE; + public static final MRock ROCK_LIMESTONE; + public static final MRock ROCK_CHALK; + public static final MRock ROCK_SLATE; + public static final MRock ROCK_BASALT; public static final MMetal GOLD; public static final MMetal IRON; @@ -61,9 +71,10 @@ public class Materials static { // Rocks - URegistry.addBlock( ROCK_LIMESTONE = new MRLimestone( ) ); - URegistry.addBlock( ROCK_CHALK = new MRChalk( ) ); - URegistry.addBlock( ROCK_SLATE = new MRSlate( ) ); + ROCK_LIMESTONE = new MRock( "limestone" , MapColor.SNOW , 0 , 1f , 7.5f ); + ROCK_CHALK = new MRock( "chalk" , MapColor.SNOW , 0 , 1f , 5f ); + ROCK_SLATE = new MRock( "slate" , MapColor.BLACK ); + ROCK_BASALT = new MRock( "basalt" , MapColor.BLACK ); // Vanilla metals GOLD = new MMetal( Blocks.GOLD_BLOCK , Items.GOLD_INGOT , Items.GOLD_NUGGET ); @@ -105,8 +116,9 @@ public class Materials ORE_GALENA = new MOGalena( ); ORE_CINNABAR = new MOCinnabar( ); - // Other recipes - URegistry.addRecipeRegistrar( new Materials( ) ); + // Other recipes, ore generation parameters, etc. + final Materials materials = new Materials( ); + URegistry.addRecipeRegistrar( materials ); } @@ -134,6 +146,21 @@ public class Materials } + public static boolean isRock( final IBlockState bs ) + { + final Block block = bs.getBlock( ); + if ( block instanceof BlockStone ) { + final BlockStone.EnumType variant = bs.getValue( BlockStone.VARIANT ); + return variant == BlockStone.EnumType.ANDESITE || variant == BlockStone.EnumType.DIORITE + || variant == BlockStone.EnumType.GRANITE || variant == BlockStone.EnumType.STONE; + } + if ( block == Blocks.COBBLESTONE ) { + return true; + } + return block instanceof I_MRock; + } + + private Materials( ) { // EMPTY @@ -187,4 +214,21 @@ public class Materials .setOutput( Materials.ITEM_COKE ).setSlag( 1 ).register( ); } + + @Override + public void addConditions( final List< WGOreCondition > conditions ) + { + conditions.add( new WGOreCondition( // + WLocation.inOverworld( ) , // + new WGOreParameters( Materials.ROCK_LIMESTONE , 15 , 40 ) ) ); + + conditions.add( new WGOreCondition( // + new WLocationInBiome<>( BiomePlains.class ) , // + new WGOreParameters( Materials.ROCK_SLATE , 15 , 40 ) ) ); + conditions.add( new WGOreCondition( // + new WLocationInBiome<>( BiomeSwamp.class ) , // + new WGOreParameters( Materials.ROCK_SLATE , 20 , 60 ) ) ); + + } + } diff --git a/src/java/mmm/materials/ore/MOCinnabar.java b/src/java/mmm/materials/ore/MOCinnabar.java index bd4f625..7ecef40 100644 --- a/src/java/mmm/materials/ore/MOCinnabar.java +++ b/src/java/mmm/materials/ore/MOCinnabar.java @@ -3,6 +3,7 @@ package mmm.materials.ore; import java.util.List; +import mmm.materials.I_MRock; import mmm.materials.MOre; import mmm.utils.I_UOreGenerationRegistrar; import mmm.world.WLocation; @@ -13,7 +14,7 @@ import mmm.world.gen.WGOreParameters; public class MOCinnabar extends MOre - implements I_UOreGenerationRegistrar + implements I_UOreGenerationRegistrar , I_MRock { public MOCinnabar( ) diff --git a/src/java/mmm/materials/rock/MRChalk.java b/src/java/mmm/materials/rock/MRChalk.java deleted file mode 100644 index e311a27..0000000 --- a/src/java/mmm/materials/rock/MRChalk.java +++ /dev/null @@ -1,28 +0,0 @@ -package mmm.materials.rock; - - -import mmm.utils.URegistry; -import net.minecraft.block.Block; -import net.minecraft.block.SoundType; -import net.minecraft.block.material.MapColor; -import net.minecraft.block.material.Material; -import net.minecraft.creativetab.CreativeTabs; - - - -public class MRChalk - extends Block -{ - - public MRChalk( ) - { - super( Material.ROCK , MapColor.SNOW ); - this.setCreativeTab( CreativeTabs.BUILDING_BLOCKS ); - this.setHardness( 1f ); - this.setResistance( 5f ); - this.setSoundType( SoundType.STONE ); - this.setHarvestLevel( "pickaxe" , 0 ); - URegistry.setIdentifiers( this , "materials" , "rock" , "chalk" ); - } - -} diff --git a/src/java/mmm/materials/rock/MRLimestone.java b/src/java/mmm/materials/rock/MRLimestone.java deleted file mode 100644 index d48237c..0000000 --- a/src/java/mmm/materials/rock/MRLimestone.java +++ /dev/null @@ -1,43 +0,0 @@ -package mmm.materials.rock; - - -import java.util.List; - -import mmm.utils.I_UOreGenerationRegistrar; -import mmm.utils.URegistry; -import mmm.world.WLocation; -import mmm.world.gen.WGOreCondition; -import mmm.world.gen.WGOreParameters; -import net.minecraft.block.Block; -import net.minecraft.block.SoundType; -import net.minecraft.block.material.MapColor; -import net.minecraft.block.material.Material; -import net.minecraft.creativetab.CreativeTabs; - - - -public class MRLimestone - extends Block - implements I_UOreGenerationRegistrar -{ - - public MRLimestone( ) - { - super( Material.ROCK , MapColor.SNOW ); - this.setCreativeTab( CreativeTabs.BUILDING_BLOCKS ); - this.setHardness( 1f ); - this.setResistance( 7.5f ); - this.setSoundType( SoundType.STONE ); - this.setHarvestLevel( "pickaxe" , 0 ); - URegistry.setIdentifiers( this , "materials" , "rock" , "limestone" ); - } - - - @Override - public void addConditions( final List< WGOreCondition > conditions ) - { - conditions.add( new WGOreCondition( WLocation.inOverworld( ) , - new WGOreParameters( this.getDefaultState( ) , 15 , 40 ) ) ); - } - -} diff --git a/src/java/mmm/materials/rock/MRSlate.java b/src/java/mmm/materials/rock/MRSlate.java deleted file mode 100644 index 023e6f6..0000000 --- a/src/java/mmm/materials/rock/MRSlate.java +++ /dev/null @@ -1,49 +0,0 @@ -package mmm.materials.rock; - - -import java.util.List; - -import mmm.utils.I_UOreGenerationRegistrar; -import mmm.utils.URegistry; -import mmm.world.WLocationInBiome; -import mmm.world.gen.WGOreCondition; -import mmm.world.gen.WGOreParameters; -import net.minecraft.block.Block; -import net.minecraft.block.SoundType; -import net.minecraft.block.material.MapColor; -import net.minecraft.block.material.Material; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.world.biome.BiomePlains; -import net.minecraft.world.biome.BiomeSwamp; - - - -public class MRSlate - extends Block - implements I_UOreGenerationRegistrar -{ - - public MRSlate( ) - { - super( Material.ROCK , MapColor.BLACK ); - this.setCreativeTab( CreativeTabs.BUILDING_BLOCKS ); - this.setHardness( 1.5f ); - this.setResistance( 10f ); - this.setSoundType( SoundType.STONE ); - this.setHarvestLevel( "pickaxe" , 0 ); - URegistry.setIdentifiers( this , "materials" , "rock" , "slate" ); - } - - - @Override - public void addConditions( final List< WGOreCondition > conditions ) - { - conditions.add( new WGOreCondition( // - new WLocationInBiome<>( BiomePlains.class ) , - new WGOreParameters( this.getDefaultState( ) , 15 , 40 ) ) ); - conditions.add( new WGOreCondition( // - new WLocationInBiome<>( BiomeSwamp.class ) , - new WGOreParameters( this.getDefaultState( ) , 20 , 60 ) ) ); - } - -} diff --git a/src/java/mmm/world/gen/WGBasalt.java b/src/java/mmm/world/gen/WGBasalt.java new file mode 100644 index 0000000..692245a --- /dev/null +++ b/src/java/mmm/world/gen/WGBasalt.java @@ -0,0 +1,25 @@ +package mmm.world.gen; + + +import java.util.Random; + +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkGenerator; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.fml.common.IWorldGenerator; + + + +public class WGBasalt + implements IWorldGenerator +{ + + @Override + public void generate( final Random random , final int chunkX , final int chunkZ , final World world , + final IChunkGenerator chunkGenerator , final IChunkProvider chunkProvider ) + { + // TODO: prevent basalt from generating in some biomes + + } + +} diff --git a/src/java/mmm/world/gen/WGOreParameters.java b/src/java/mmm/world/gen/WGOreParameters.java index db80155..a405c6a 100644 --- a/src/java/mmm/world/gen/WGOreParameters.java +++ b/src/java/mmm/world/gen/WGOreParameters.java @@ -5,6 +5,7 @@ import java.util.Random; import com.google.common.base.Predicate; +import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraft.init.Blocks; @@ -28,6 +29,35 @@ public class WGOreParameters private WorldGenMinable generator; + public WGOreParameters( final Block ore , final int clusters , final int clusterSize ) + { + this( ore.getDefaultState( ) , clusters , clusterSize , Integer.MIN_VALUE , Integer.MIN_VALUE , + BlockMatcher.forBlock( Blocks.STONE ) ); + } + + + public WGOreParameters( final Block ore , final int clusters , final int clusterSize , final int minHeight , + final int maxHeight ) + { + this( ore.getDefaultState( ) , clusters , clusterSize , minHeight , maxHeight , + BlockMatcher.forBlock( Blocks.STONE ) ); + } + + + public WGOreParameters( final Block ore , final int clusters , final int clusterSize , + final Predicate< IBlockState > matcher ) + { + this( ore.getDefaultState( ) , clusters , clusterSize , Integer.MIN_VALUE , Integer.MIN_VALUE , matcher ); + } + + + public WGOreParameters( final Block ore , final int clusters , final int clusterSize , final int minHeight , + final int maxHeight , final Predicate< IBlockState > matcher ) + { + this( ore.getDefaultState( ) , clusters , clusterSize , minHeight , maxHeight , matcher ); + } + + public WGOreParameters( final IBlockState ore , final int clusters , final int clusterSize ) { this( ore , clusters , clusterSize , Integer.MIN_VALUE , Integer.MIN_VALUE , @@ -35,8 +65,8 @@ public class WGOreParameters } - public WGOreParameters( final IBlockState ore , final int clusters , final int clusterSize , - final int minHeight , final int maxHeight ) + public WGOreParameters( final IBlockState ore , final int clusters , final int clusterSize , final int minHeight , + final int maxHeight ) { this( ore , clusters , clusterSize , minHeight , maxHeight , BlockMatcher.forBlock( Blocks.STONE ) ); } @@ -49,8 +79,8 @@ public class WGOreParameters } - public WGOreParameters( final IBlockState ore , final int clusters , final int clusterSize , - int minHeight , int maxHeight , final Predicate< IBlockState > matcher ) + public WGOreParameters( final IBlockState ore , final int clusters , final int clusterSize , int minHeight , + int maxHeight , final Predicate< IBlockState > matcher ) { if ( clusters < 1 ) { throw new IllegalArgumentException( "cluster count should be at least 1" ); diff --git a/src/resources/assets/mmm/blockstates/materials/rock/basalt.json b/src/resources/assets/mmm/blockstates/materials/rock/basalt.json new file mode 100644 index 0000000..83e101a --- /dev/null +++ b/src/resources/assets/mmm/blockstates/materials/rock/basalt.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "mmm:materials/rock/basalt" } + } +} diff --git a/src/resources/assets/mmm/lang/en_US.lang b/src/resources/assets/mmm/lang/en_US.lang index b1b5901..75f4bd7 100644 --- a/src/resources/assets/mmm/lang/en_US.lang +++ b/src/resources/assets/mmm/lang/en_US.lang @@ -11,6 +11,7 @@ gui.mmm.tech.base.am.disabled=Deactivated tile.mmm.materials.rock.limestone.name=Limestone tile.mmm.materials.rock.chalk.name=Chalk tile.mmm.materials.rock.slate.name=Slate +tile.mmm.materials.rock.basalt.name=Basalt tile.mmm.materials.ore.rock_salt.name=Rock Salt item.mmm.materials.stone.rock_salt.name=Salt Crystals diff --git a/src/resources/assets/mmm/models/block/materials/rock/basalt.json b/src/resources/assets/mmm/models/block/materials/rock/basalt.json new file mode 100644 index 0000000..388e05b --- /dev/null +++ b/src/resources/assets/mmm/models/block/materials/rock/basalt.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/cube_all", + "textures": { + "all": "mmm:blocks/materials/rock/basalt" + } +} \ No newline at end of file diff --git a/src/resources/assets/mmm/models/item/materials/rock/basalt.json b/src/resources/assets/mmm/models/item/materials/rock/basalt.json new file mode 100644 index 0000000..4a72b55 --- /dev/null +++ b/src/resources/assets/mmm/models/item/materials/rock/basalt.json @@ -0,0 +1,3 @@ +{ + "parent": "mmm:block/materials/rock/basalt" +} \ No newline at end of file diff --git a/src/resources/assets/mmm/textures/blocks/materials/rock/basalt.png b/src/resources/assets/mmm/textures/blocks/materials/rock/basalt.png new file mode 100644 index 0000000000000000000000000000000000000000..4ff8fe26a3c2f994da31285169cc8b7d8f6ceaab GIT binary patch literal 260 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#0XsWCyPS9FP9dPsVow*x5R22jL6&?C20W+hBX*U%KKB1UizZbnxkc%BC^v~;chyObq8 z+S%L1@?ef%uk1(J4Ggn|EMjKc%7&bhxfM|+llN@h>(C?9i$d+aYIG-+&3U_7Yd3dT zL)Yf_8