2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.entity;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
2015-12-24 02:07:03 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.block.Block;
|
2014-02-15 04:17:22 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.entity.item.EntityTNTPrimed;
|
2015-01-03 02:53:14 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.util.BlockPos;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.util.DamageSource;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.util.EnumParticleTypes;
|
2014-02-15 04:17:22 +01:00
|
|
|
import net.minecraft.world.Explosion;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.world.World;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
|
2015-12-24 02:07:03 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-02-09 06:08:27 +01:00
|
|
|
import appeng.core.AEConfig;
|
2014-02-15 04:17:22 +01:00
|
|
|
import appeng.core.CommonHelper;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.core.sync.packets.PacketMockExplosion;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.helpers.Reflected;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-04-06 00:35:42 +02:00
|
|
|
public final class EntityTinyTNTPrimed extends EntityTNTPrimed implements IEntityAdditionalSpawnData
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
@Reflected
|
2015-09-30 14:24:40 +02:00
|
|
|
public EntityTinyTNTPrimed( final World w )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
super( w );
|
|
|
|
this.setSize( 0.35F, 0.35F );
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public EntityTinyTNTPrimed( final World w, final double x, final double y, final double z, final EntityLivingBase igniter )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
super( w, x, y, z, igniter );
|
2013-12-27 23:59:59 +01:00
|
|
|
this.setSize( 0.55F, 0.55F );
|
2015-12-24 02:03:16 +01:00
|
|
|
// this.yOffset = this.height / 2.0F;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called to update the entity's position/logic.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
this.handleWaterMovement();
|
|
|
|
|
|
|
|
this.prevPosX = this.posX;
|
|
|
|
this.prevPosY = this.posY;
|
|
|
|
this.prevPosZ = this.posZ;
|
|
|
|
this.motionY -= 0.03999999910593033D;
|
|
|
|
this.moveEntity( this.motionX, this.motionY, this.motionZ );
|
|
|
|
this.motionX *= 0.9800000190734863D;
|
|
|
|
this.motionY *= 0.9800000190734863D;
|
|
|
|
this.motionZ *= 0.9800000190734863D;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.onGround )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
this.motionX *= 0.699999988079071D;
|
|
|
|
this.motionZ *= 0.699999988079071D;
|
|
|
|
this.motionY *= -0.5D;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isInWater() && Platform.isServer() ) // put out the fuse.
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final ItemStack tntStack : AEApi.instance().definitions().blocks().tinyTNT().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
final EntityItem item = new EntityItem( this.worldObj, this.posX, this.posY, this.posZ, tntStack );
|
|
|
|
|
|
|
|
item.motionX = this.motionX;
|
|
|
|
item.motionY = this.motionY;
|
|
|
|
item.motionZ = this.motionZ;
|
|
|
|
item.prevPosX = this.prevPosX;
|
|
|
|
item.prevPosY = this.prevPosY;
|
|
|
|
item.prevPosZ = this.prevPosZ;
|
|
|
|
|
|
|
|
this.worldObj.spawnEntityInWorld( item );
|
|
|
|
this.setDead();
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.fuse <= 0 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
this.setDead();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.worldObj.isRemote )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
this.explode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
this.worldObj.spawnParticle( EnumParticleTypes.SMOKE_NORMAL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-03-26 11:07:26 +01:00
|
|
|
this.fuse--;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// override :P
|
|
|
|
void explode()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.worldObj.playSoundEffect( this.posX, this.posY, this.posZ, "random.explode", 4.0F, ( 1.0F + ( this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat() ) * 0.2F ) * 32.9F );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isInWater() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final Object e : this.worldObj.getEntitiesWithinAABBExcludingEntity( this, AxisAlignedBB.fromBounds( this.posX - 1.5, this.posY - 1.5f, this.posZ - 1.5, this.posX + 1.5, this.posY + 1.5, this.posZ + 1.5 ) ) )
|
2014-02-15 04:17:22 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( e instanceof Entity )
|
2014-02-15 04:17:22 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
( (Entity) e ).attackEntityFrom( DamageSource.setExplosionSource( null ), 6 );
|
2014-02-15 04:17:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AEConfig.instance.isFeatureEnabled( AEFeature.TinyTNTBlockDamage ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.posY -= 0.25;
|
2015-09-30 14:24:40 +02:00
|
|
|
final Explosion ex = new Explosion( this.worldObj, this, this.posX, this.posY, this.posZ, 0.2f, false, false );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = (int) ( this.posX - 2 ); x <= this.posX + 2; x++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int y = (int) ( this.posY - 2 ); y <= this.posY + 2; y++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int z = (int) ( this.posZ - 2 ); z <= this.posZ + 2; z++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-12-24 02:03:16 +01:00
|
|
|
final BlockPos point = new BlockPos( x, y, z );
|
2015-09-30 14:24:40 +02:00
|
|
|
final IBlockState state = this.worldObj.getBlockState( point );
|
|
|
|
final Block block = state.getBlock();
|
2015-06-16 02:44:59 +02:00
|
|
|
if( block != null && !block.isAir( this.worldObj, point ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
float strength = (float) ( 2.3f - ( ( ( x + 0.5f ) - this.posX ) * ( ( x + 0.5f ) - this.posX ) + ( ( y + 0.5f ) - this.posY ) * ( ( y + 0.5f ) - this.posY ) + ( ( z + 0.5f ) - this.posZ ) * ( ( z + 0.5f ) - this.posZ ) ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final float resistance = block.getExplosionResistance( this.worldObj, point, this, ex );
|
2015-04-03 08:54:31 +02:00
|
|
|
strength -= ( resistance + 0.3F ) * 0.11f;
|
2014-02-15 04:17:22 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( strength > 0.01 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( block.getMaterial() != Material.air )
|
2014-02-15 04:17:22 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( block.canDropFromExplosion( ex ) )
|
2014-02-15 04:17:22 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
block.dropBlockAsItemWithChance( this.worldObj, point, state, 1.0F / 1.0f, 0 );
|
2014-02-15 04:17:22 +01:00
|
|
|
}
|
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
block.onBlockExploded( this.worldObj, point, ex );
|
2014-02-15 04:17:22 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
CommonHelper.proxy.sendToAllNearExcept( null, this.posX, this.posY, this.posZ, 64, this.worldObj, new PacketMockExplosion( this.posX, this.posY, this.posZ ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-30 14:24:40 +02:00
|
|
|
public void writeSpawnData( final ByteBuf data )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
data.writeByte( this.fuse );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-30 14:24:40 +02:00
|
|
|
public void readSpawnData( final ByteBuf data )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.fuse = data.readByte();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|