Nether coral
This commit is contained in:
parent
e6cbf48ed8
commit
7b3e9f63d0
12 changed files with 235 additions and 13 deletions
BIN
graphics/nether-coral.xcf
Normal file
BIN
graphics/nether-coral.xcf
Normal file
Binary file not shown.
|
@ -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( );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
135
src/java/mmm/plants/PNetherCoral.java
Normal file
135
src/java/mmm/plants/PNetherCoral.java
Normal file
|
@ -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 );
|
||||
}
|
||||
}
|
|
@ -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( ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 ) ) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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" } }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 230 B |
Binary file not shown.
After Width: | Height: | Size: 226 B |
Binary file not shown.
After Width: | Height: | Size: 227 B |
Binary file not shown.
After Width: | Height: | Size: 227 B |
Reference in a new issue