diff --git a/src/java/mmm/plants/PNetherCoral.java b/src/java/mmm/plants/PNetherCoral.java index 130037e..598fb97 100644 --- a/src/java/mmm/plants/PNetherCoral.java +++ b/src/java/mmm/plants/PNetherCoral.java @@ -4,6 +4,7 @@ package mmm.plants; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Random; import mmm.core.CRegistry; import mmm.core.api.I_FloraRegistrar; @@ -11,18 +12,26 @@ import mmm.core.api.world.I_FloraParameters; import mmm.utils.UBlockItemWithVariants; import mmm.world.WLocation; import mmm.world.gen.WGFloraParameters; +import net.minecraft.block.Block; 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.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; +import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.IStringSerializable; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.IBlockAccess; @@ -99,6 +108,13 @@ public class PNetherCoral } + @Override + public AxisAlignedBB getBoundingBox( final IBlockState state , final IBlockAccess source , final BlockPos pos ) + { + return Block.FULL_BLOCK_AABB; + } + + @Override protected BlockStateContainer createBlockState( ) { @@ -190,8 +206,87 @@ public class PNetherCoral return new ItemStack( PNetherCoral.this.ITEM , 1 , state.getValue( PNetherCoral.COLOR ).toMetadata( ) ); } + + @Override + public void onEntityCollidedWithBlock( final World worldIn , final BlockPos pos , final IBlockState state , + final Entity entityIn ) + { + final Random rand = worldIn.rand == null ? Block.RANDOM : worldIn.rand; + + if ( entityIn instanceof EntityItem ) { + final ItemStack stack = ( (EntityItem) entityIn ).getEntityItem( ); + final Item item = stack.getItem( ); + if ( item instanceof ItemFood && ( (ItemFood) item ).isWolfsFavoriteMeat( ) ) { + entityIn.setDead( ); + this.doSmokeParticles( worldIn , pos , rand ); + this.doFlameParticles( worldIn , pos , rand ); + if ( !worldIn.isRemote ) { + this.tryGrow( worldIn , pos , state ); + } + } + } else if ( entityIn instanceof EntityLivingBase && worldIn.rand.nextFloat( ) < .01f ) { + this.doFlameParticles( worldIn , pos , rand ); + if ( !entityIn.isImmuneToFire( ) ) { + entityIn.attackEntityFrom( PNetherCoral.this.DAMAGE , 1f ); + } + } + } + + + private void tryGrow( final World worldIn , final BlockPos pos , final IBlockState state ) + { + final ArrayList< BlockPos > positions = new ArrayList<>( 26 ); + int nAround = -1; + for ( int i = -1 ; i <= 1 ; i++ ) { + for ( int j = -1 ; j <= 1 ; j++ ) { + for ( int k = -1 ; k <= 1 ; k++ ) { + final BlockPos nPos = pos.add( i , j , k ); + if ( worldIn.isAirBlock( nPos ) && this.canBlockStay( worldIn , nPos , state ) ) { + positions.add( nPos ); + } else if ( worldIn.getBlockState( nPos ).getBlock( ) == this ) { + nAround++; + } + } + } + } + + final float limit = .5f + nAround / 8f; + if ( positions.isEmpty( ) || worldIn.rand.nextFloat( ) < limit ) { + return; + } + final BlockPos growPos = positions.get( worldIn.rand.nextInt( positions.size( ) ) ); + worldIn.setBlockState( growPos , state , 3 ); + } + + + private void doSmokeParticles( final World world , final BlockPos pos , final Random rand ) + { + world.spawnParticle( EnumParticleTypes.SMOKE_LARGE , pos.getX( ) + .5 , pos.getY( ) + .5 , + pos.getZ( ) + .5 , 0 , .1 + rand.nextFloat( ) * .2 , 0 ); + for ( int i = 0 ; i < 8 ; i++ ) { + world.spawnParticle( EnumParticleTypes.SMOKE_NORMAL , // + pos.getX( ) + .1 + rand.nextFloat( ) * .8 , // + pos.getY( ) + .4 + rand.nextFloat( ) * .2 , // + pos.getZ( ) + .1 + rand.nextFloat( ) * .8 , // + 0 , .1 + rand.nextFloat( ) * .2 , 0 ); + } + } + + + private void doFlameParticles( final World world , final BlockPos pos , final Random rand ) + { + for ( int i = 0 ; i < 50 ; i++ ) { + world.spawnParticle( EnumParticleTypes.FLAME , // + pos.getX( ) + rand.nextFloat( ) , // + pos.getY( ) + .4 + rand.nextFloat( ) * .2 , // + pos.getZ( ) + rand.nextFloat( ) , // + 0 , 0 , 0 ); + } + } + } + public final DamageSource DAMAGE = new DamageSource( "nether_coral" ).setFireDamage( ).setDamageBypassesArmor( ); public final Plant PLANT; public final UBlockItemWithVariants ITEM; diff --git a/src/resources/assets/mmm/lang/en_US.lang b/src/resources/assets/mmm/lang/en_US.lang index a1324a1..7c3d2e2 100644 --- a/src/resources/assets/mmm/lang/en_US.lang +++ b/src/resources/assets/mmm/lang/en_US.lang @@ -11,6 +11,9 @@ gui.mmm.tech.base.am.disabled=Deactivated item.mmm.plant.fruit.tomato.name=Tomato item.mmm.plant.seeds.tomato.name=Tomato Seeds tile.mmm.plant.block.wild_tomato.name=Wild Tomato Plant + +death.attack.nether_coral=%1$s became Nether Coral food +death.attack.nether_coral.player=%1$s fled away from %2$s and straight into hungry Nether Coral tile.mmm.plant.block.nether_coral.red.name=Red Nether Coral tile.mmm.plant.block.nether_coral.yellow.name=Yellow Nether Coral tile.mmm.plant.block.nether_coral.orange.name=Orange Nether Coral