diff --git a/graphics/nether-coral.xcf b/graphics/nether-coral.xcf new file mode 100644 index 0000000..4d359ae Binary files /dev/null and b/graphics/nether-coral.xcf differ diff --git a/src/java/mmm/MmmPlants.java b/src/java/mmm/MmmPlants.java index 12bde10..e94f6eb 100644 --- a/src/java/mmm/MmmPlants.java +++ b/src/java/mmm/MmmPlants.java @@ -1,6 +1,7 @@ package mmm; +import mmm.plants.PNetherCoral; import mmm.plants.PTomato; @@ -9,9 +10,11 @@ public class MmmPlants { public static final PTomato TOMATO; + public static final PNetherCoral NETHER_CORAL; static { TOMATO = new PTomato( ); + NETHER_CORAL = new PNetherCoral( ); } diff --git a/src/java/mmm/core/api/world/I_FloraParameters.java b/src/java/mmm/core/api/world/I_FloraParameters.java index 7baff15..226f07e 100644 --- a/src/java/mmm/core/api/world/I_FloraParameters.java +++ b/src/java/mmm/core/api/world/I_FloraParameters.java @@ -24,5 +24,8 @@ public interface I_FloraParameters public int getPlacementAttempts( World world , BlockPos pos , Random random ); + public int getSuccessfulPlacements( World world , BlockPos pos , Random random ); + + public boolean canPlace( World world , BlockPos pos , Random random ); } diff --git a/src/java/mmm/plants/PNetherCoral.java b/src/java/mmm/plants/PNetherCoral.java new file mode 100644 index 0000000..3a502c6 --- /dev/null +++ b/src/java/mmm/plants/PNetherCoral.java @@ -0,0 +1,135 @@ +package mmm.plants; + + +import java.util.List; + +import mmm.core.CRegistry; +import mmm.core.api.I_FloraRegistrar; +import mmm.core.api.world.I_FloraParameters; +import mmm.world.WLocation; +import mmm.world.gen.WGFloraParameters; +import net.minecraft.block.BlockBush; +import net.minecraft.block.SoundType; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Blocks; +import net.minecraft.util.IStringSerializable; + + + +public class PNetherCoral + implements I_FloraRegistrar +{ + + public static enum E_Color + implements IStringSerializable { + + YELLOW , + ORANGE , + BLUE , + RED; + + private static final E_Color[] VALUES = E_Color.values( ); + + + public static E_Color fromMetadata( final int meta ) + { + return E_Color.VALUES[ meta ]; + } + + + @Override + public String getName( ) + { + return this.toString( ).toLowerCase( ); + } + + + public int toMetadata( ) + { + return this.ordinal( ); + } + } + + private static final PropertyEnum< E_Color > COLOR = PropertyEnum.create( "color" , E_Color.class ); + + public class Plant + extends BlockBush + { + + public Plant( ) + { + CRegistry.setIdentifiers( this , "plant" , "block" , "nether_coral" ); + + this.setTickRandomly( true ); + this.setCreativeTab( (CreativeTabs) null ); + this.setHardness( 0f ); + this.setSoundType( SoundType.PLANT ); + this.lightValue = 13; + this.disableStats( ); + + this.setDefaultState( this.blockState.getBaseState( ) // + .withProperty( PNetherCoral.COLOR , E_Color.YELLOW ) ); + } + + + @Override + protected BlockStateContainer createBlockState( ) + { + return new BlockStateContainer( this , PNetherCoral.COLOR ); + } + + + @Override + public IBlockState getStateFromMeta( final int meta ) + { + return this.getDefaultState( ).withProperty( PNetherCoral.COLOR , E_Color.fromMetadata( meta ) ); + } + + + @Override + public int getMetaFromState( final IBlockState state ) + { + return state.getValue( PNetherCoral.COLOR ).toMetadata( ); + } + + + @Override + protected boolean canSustainBush( final IBlockState state ) + { + return state.getBlock( ) == Blocks.NETHERRACK || state.getBlock( ) == Blocks.SOUL_SAND; + } + + } + + public final Plant PLANT; + + + public PNetherCoral( ) + { + CRegistry.addRegistrar( this ); + CRegistry.addBlock( this.PLANT = new Plant( ) , null ); + } + + + @Override + public void getFloraGeneration( final List< I_FloraParameters > output ) + { + output.add( new WGFloraParameters( this.getPlant( E_Color.YELLOW ) , // + 0.2f , WLocation.inTheNether( ) ).setSuccessfulPlacements( 16 ) ); + output.add( new WGFloraParameters( this.getPlant( E_Color.RED ) , // + 0.2f , WLocation.inTheNether( ) ).setSuccessfulPlacements( 16 ) ); + output.add( new WGFloraParameters( this.getPlant( E_Color.ORANGE ) , // + 0.1f , WLocation.inTheNether( ) ).setSuccessfulPlacements( 8 ) ); + output.add( new WGFloraParameters( this.getPlant( E_Color.BLUE ) , // + 0.05f , WLocation.inTheNether( ) ).setSuccessfulPlacements( 4 ) ); + } + + + private IBlockState getPlant( final E_Color color ) + { + return this.PLANT.getDefaultState( ).withProperty( PNetherCoral.COLOR , color ); + } +} diff --git a/src/java/mmm/world/WDefaultGenWatcher.java b/src/java/mmm/world/WDefaultGenWatcher.java index 1deffdf..abc1d40 100644 --- a/src/java/mmm/world/WDefaultGenWatcher.java +++ b/src/java/mmm/world/WDefaultGenWatcher.java @@ -67,10 +67,8 @@ public class WDefaultGenWatcher @SubscribeEvent - public void onBiomeDecorate( DecorateBiomeEvent.Decorate event ) + public void onBiomeDecorate( DecorateBiomeEvent.Post event ) { - if ( event.getType( ) == DecorateBiomeEvent.Decorate.EventType.GRASS ) { - this.floraGenerator.generate( event.getWorld( ) , event.getRand( ) , event.getPos( ) ); - } + this.floraGenerator.generate( event.getWorld( ) , event.getRand( ) , event.getPos( ) ); } } diff --git a/src/java/mmm/world/gen/WGFlora.java b/src/java/mmm/world/gen/WGFlora.java index 713d263..44f0815 100644 --- a/src/java/mmm/world/gen/WGFlora.java +++ b/src/java/mmm/world/gen/WGFlora.java @@ -9,7 +9,9 @@ import mmm.core.api.I_FloraRegistrar; import mmm.core.api.world.I_BiomeWithFlora; import mmm.core.api.world.I_FloraParameters; import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.DimensionType; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.feature.WorldGenerator; @@ -88,24 +90,61 @@ public class WGFlora private void tryGeneratePlant( final World worldIn , final Random rand , BlockPos position , final I_FloraParameters parameters ) { - IBlockState bs = worldIn.getBlockState( position ); - while ( ( bs.getBlock( ).isAir( bs , worldIn , position ) - || bs.getBlock( ).isLeaves( bs , worldIn , position ) ) && position.getY( ) > 0 ) { - position = position.down( ); - bs = worldIn.getBlockState( position ); + if ( worldIn.provider.getDimensionType( ) == DimensionType.NETHER ) { + position = this.findNetherPosition( worldIn , rand , position ); + } else { + position = this.findOverwordOrEndPosition( worldIn , position ); } final int attempts = parameters.getPlacementAttempts( worldIn , position , rand ); + int successes = parameters.getSuccessfulPlacements( worldIn , position , rand ); for ( int i = 0 ; i < attempts ; ++i ) { final BlockPos blockpos = position.add( // rand.nextInt( 8 ) - rand.nextInt( 8 ) , // rand.nextInt( 4 ) - rand.nextInt( 4 ) , // rand.nextInt( 8 ) - rand.nextInt( 8 ) ); - if ( parameters.canPlace( worldIn , blockpos , rand ) ) { - worldIn.setBlockState( blockpos , parameters.getBlockState( worldIn , blockpos , rand ) , 2 ); + if ( !parameters.canPlace( worldIn , blockpos , rand ) ) { + continue; + } + + worldIn.setBlockState( blockpos , parameters.getBlockState( worldIn , blockpos , rand ) , 2 ); + successes--; + if ( successes == 0 ) { break; } } } + + private BlockPos findNetherPosition( final World worldIn , final Random rand , BlockPos position ) + { + float keepGoing = 1.6f; + do { + keepGoing *= .5f; + IBlockState bs = worldIn.getBlockState( position ); + while ( ( bs.getBlock( ) == Blocks.NETHERRACK || bs.getBlock( ) == Blocks.BEDROCK + || bs.getMaterial( ).isLiquid( ) ) && position.getY( ) > 0 ) { + position = position.down( ); + bs = worldIn.getBlockState( position ); + } + while ( bs.getBlock( ).isAir( bs , worldIn , position ) && position.getY( ) > 0 ) { + position = position.down( ); + bs = worldIn.getBlockState( position ); + } + } while ( position.getY( ) > 0 && rand.nextFloat( ) < keepGoing ); + return position; + } + + + private BlockPos findOverwordOrEndPosition( final World worldIn , BlockPos position ) + { + IBlockState bs = worldIn.getBlockState( position ); + while ( ( bs.getBlock( ).isAir( bs , worldIn , position ) // + || bs.getBlock( ).isLeaves( bs , worldIn , position ) ) && position.getY( ) > 0 ) { + position = position.down( ); + bs = worldIn.getBlockState( position ); + } + return position; + } + } diff --git a/src/java/mmm/world/gen/WGFloraParameters.java b/src/java/mmm/world/gen/WGFloraParameters.java index f3cb77b..5a2e578 100644 --- a/src/java/mmm/world/gen/WGFloraParameters.java +++ b/src/java/mmm/world/gen/WGFloraParameters.java @@ -33,6 +33,8 @@ public class WGFloraParameters public final float perChunk; public final I_LocationCheck location; public final BiPredicate< World , BlockPos > placementCheck; + private int attempts = 128; + private int successes = 1; public WGFloraParameters( final IBlockState floraType , final float perChunk ) @@ -64,6 +66,26 @@ public class WGFloraParameters } + public WGFloraParameters setPlacementAttempts( int attempts ) + { + if ( attempts < 1 ) { + throw new IllegalArgumentException( "invalid placement attempts count" ); + } + this.attempts = attempts; + return this; + } + + + public WGFloraParameters setSuccessfulPlacements( int successes ) + { + if ( successes < 1 ) { + throw new IllegalArgumentException( "invalid successful placement count" ); + } + this.successes = successes; + return this; + } + + @Override public IBlockState getBlockState( final World world , final BlockPos pos , final Random random ) { @@ -72,7 +94,7 @@ public class WGFloraParameters @Override - public boolean canPlaceInChunk( World world , BlockPos pos ) + public boolean canPlaceInChunk( final World world , final BlockPos pos ) { return this.location.checkLocation( world , pos.getX( ) >> 4 , pos.getZ( ) >> 4 , world.getChunkProvider( ) ); } @@ -93,7 +115,14 @@ public class WGFloraParameters @Override public int getPlacementAttempts( final World world , final BlockPos pos , final Random random ) { - return 128; + return this.attempts; + } + + + @Override + public int getSuccessfulPlacements( final World world , final BlockPos pos , final Random random ) + { + return this.successes; } diff --git a/src/resources/assets/mmm/blockstates/plant/block/nether_coral.json b/src/resources/assets/mmm/blockstates/plant/block/nether_coral.json new file mode 100644 index 0000000..fdde6b3 --- /dev/null +++ b/src/resources/assets/mmm/blockstates/plant/block/nether_coral.json @@ -0,0 +1,15 @@ +{ + "forge_marker": 1 , + "defaults" : { + "model": "minecraft:cross" + } , + "variants" : { + "color" : { + "yellow" : { "textures" : { "cross" : "mmm:blocks/plant/nether_coral/yellow" } } , + "red" : { "textures" : { "cross" : "mmm:blocks/plant/nether_coral/red" } } , + "orange" : { "textures" : { "cross" : "mmm:blocks/plant/nether_coral/orange" } } , + "blue" : { "textures" : { "cross" : "mmm:blocks/plant/nether_coral/blue" } } + } + } + +} \ No newline at end of file diff --git a/src/resources/assets/mmm/textures/blocks/plant/nether_coral/blue.png b/src/resources/assets/mmm/textures/blocks/plant/nether_coral/blue.png new file mode 100644 index 0000000..5d9c422 Binary files /dev/null and b/src/resources/assets/mmm/textures/blocks/plant/nether_coral/blue.png differ diff --git a/src/resources/assets/mmm/textures/blocks/plant/nether_coral/orange.png b/src/resources/assets/mmm/textures/blocks/plant/nether_coral/orange.png new file mode 100644 index 0000000..ef5e280 Binary files /dev/null and b/src/resources/assets/mmm/textures/blocks/plant/nether_coral/orange.png differ diff --git a/src/resources/assets/mmm/textures/blocks/plant/nether_coral/red.png b/src/resources/assets/mmm/textures/blocks/plant/nether_coral/red.png new file mode 100644 index 0000000..b4e754a Binary files /dev/null and b/src/resources/assets/mmm/textures/blocks/plant/nether_coral/red.png differ diff --git a/src/resources/assets/mmm/textures/blocks/plant/nether_coral/yellow.png b/src/resources/assets/mmm/textures/blocks/plant/nether_coral/yellow.png new file mode 100644 index 0000000..2460ecf Binary files /dev/null and b/src/resources/assets/mmm/textures/blocks/plant/nether_coral/yellow.png differ