From 7b3e9f63d075a7478092939bc4555021e038853e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 21 Jul 2016 12:50:43 +0200 Subject: [PATCH] Nether coral --- graphics/nether-coral.xcf | Bin 0 -> 5694 bytes src/java/mmm/MmmPlants.java | 3 + .../mmm/core/api/world/I_FloraParameters.java | 3 + src/java/mmm/plants/PNetherCoral.java | 135 ++++++++++++++++++ src/java/mmm/world/WDefaultGenWatcher.java | 6 +- src/java/mmm/world/gen/WGFlora.java | 53 ++++++- src/java/mmm/world/gen/WGFloraParameters.java | 33 ++++- .../blockstates/plant/block/nether_coral.json | 15 ++ .../blocks/plant/nether_coral/blue.png | Bin 0 -> 230 bytes .../blocks/plant/nether_coral/orange.png | Bin 0 -> 226 bytes .../blocks/plant/nether_coral/red.png | Bin 0 -> 227 bytes .../blocks/plant/nether_coral/yellow.png | Bin 0 -> 227 bytes 12 files changed, 235 insertions(+), 13 deletions(-) create mode 100644 graphics/nether-coral.xcf create mode 100644 src/java/mmm/plants/PNetherCoral.java create mode 100644 src/resources/assets/mmm/blockstates/plant/block/nether_coral.json create mode 100644 src/resources/assets/mmm/textures/blocks/plant/nether_coral/blue.png create mode 100644 src/resources/assets/mmm/textures/blocks/plant/nether_coral/orange.png create mode 100644 src/resources/assets/mmm/textures/blocks/plant/nether_coral/red.png create mode 100644 src/resources/assets/mmm/textures/blocks/plant/nether_coral/yellow.png diff --git a/graphics/nether-coral.xcf b/graphics/nether-coral.xcf new file mode 100644 index 0000000000000000000000000000000000000000..4d359aed58e46fe2e3d75e70984e9f3b77042a90 GIT binary patch literal 5694 zcmeHL&1)2A7=LDVvvDW0A6ZRR+QJ+{NhmAvP`v2HTPQ`aP!LaRvOAe}lMTBGet>vV zsGv7b-ue#|q?aBR!Ba0~JbKtdz4g+AY0)OOnf`w7Jg;4K6>XcyKpysa=lOcSf6ueC z8%E2k!G(oZ(2Ckk0acYLPl6o>&3^E{lXo|#$&e3#^Wb^#dnz+-3h^J{Sq(94Jz8#r z&3f347GV$wqK ztv`6Rz^)g1tBr+dB@B+*xnR6F%BZ&b`bxAGL@NtR%^v%ATCHAl?b!m^`(;yVdA=*p zLCLu-GImC!cv@uQYmw3&k;+4nnr|cUw3orN-T(PgW3?H~EH%1|K|2bU)@B)50P`xo z1@BXt;YF445MBvmNFLbA6GJkmwf54GT!GASEsaB9Tn%htKv~KCLIt~Y#JXQTZ*wnE zKOoyNMndDTaplQiLu4RA!(W46(LRa$0%N>E3uH&`qfI}L`Gn8v1B&e3@3X-uaX;oz z8!=rlqz^|PaYzJlItDtiBU=L#;D{5ueOI;~$1&VFGpj4xgTB)*z_+!5LHjt5t$4uE zJrm%Yc5H7)8MvcqaS}(KCL#&2;UqcvBay^>JlQnn1X$coaLH(lRHFo>CNhQ|d2o>m zV4EP#oa9dqU`$1ElM>Az5#crkn2rULy|mhdy$1PRC2WohNvXhuCfU^@VGHl4CTlBv zOnon5k@|ZjX!nb%CZEYS7x^}vztlH1ftkcvb;u zf19st4*g%gvJY{>lswGqoq#-40lW{@sWz`p{R+^pd>l`%-}dp-Z3fGY-d7AAwa3@J zmXy(luN92pm|CIi8^&Rnl)UdC*l7{&{h$uJ)Cbg2tTGLo{ORT*_c7`mY2Qt(@C{$d z{{*m$px6t*o%!?XRGW{tT7#8efRTCd^b1%iVsASIl!Lk!Jp7-~*mVLZ{v-9NtwgM4 z9w_6dx{a04{B--jvBL9t+n)klgHpL6QoaSn-T|;uURS5u%2%lqAK>d?BM0$obJVk5SH@1Z*Ix-1UiiN)EbRLxU`Y=#E%q$Bi1X5d#wLg0|kU7X?Zow~B3}SqzDhB^LQ<@rnXF|o8 Qx~vYx>(mYEnLEwD0dl<9YXATM literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..5d9c42282450a2807f3a454542a14b9b85c3fc8d GIT binary patch literal 230 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ydu{YLo7}wCoEv)xcA||{l%gi zBJ1~m{r~^vbB;m*`D62nIel$CKD`hQah$O5tGhzdiMB=)Woe%9HydOwGt7|Klz8IJ zXZ?j$6GRXDxSKObOTW`y)8z5!#5!kl9#;XE#q1g#{Kg`89a1dUY+J~#P!+N8xJcXQ z3$ZMh8m^Y5Fi(hWdM6dIqIr?vGD&5tkFMIAxHm}lT@{E}#CUOogW3wgXr2dMii>y^ ePlgroFfhF9cF)wCQ}-O`a0X9TKbLh*2~7YSRaiLy literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..ef5e2806bd6a3d26accf1e73bf8ea9071e5812d8 GIT binary patch literal 226 zcmV<803H8{P)M0%zq0YAp1&K_K^Yi>;XBhsmD2d%?k(hae z`xU!?#Wmx_w+jm8d_-Z?+<{l|>A+U5gV}hQ@ZwfU0a4tZ6(&vIx>Hy$ED3EWCDEV? zv}a*8*Ffo&PRhSk95Ih^^$uX1I5*1#HPbG;alRX?br8X0$n(=s^V;N37o!PmO=v&l co2tJ69%ax+X-6xnAOHXW07*qoM6N<$f?%3mn*aa+ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..b4e754a44dae95edd2ef9b39cfff9a4e1ea45545 GIT binary patch literal 227 zcmV<90382`P)Z# z1=_Q)nroo+N+;#tDvp@OxOxXLPMn)%hFWNs-8kQk)jEjaG35DasAX;Pr;E`9wkEV6 d@=euW01ug1Ic7@_+j9T_002ovPDHLkV1f`@WIX@? literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..2460ecf97ec8a5ac2ccc117e764f4bab3e645748 GIT binary patch literal 227 zcmV<90382`P);Fi^R+$ z+|StkE3O$YzMW7g*CPs}<_^4yF9)`A9n8kdgcr9;3W(zNtT1Wv)}6w7VM%C1DTxME zpgjw#xduwFbW;AU;)r>St9Jn7#JO1}sF`-zjq}}Dt%C?2L!O_8n%5?Ox)@DhYeM@W d-&Fkt@BnrbQ;nD|UTFXT002ovPDHLkV1lZ}T`vFt literal 0 HcmV?d00001