2013-12-27 23:59:59 +01:00
|
|
|
package appeng.block.misc;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockDispenser;
|
|
|
|
import net.minecraft.block.material.Material;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.projectile.EntityArrow;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
2014-02-16 05:40:17 +01:00
|
|
|
import net.minecraft.item.Item;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.util.IIcon;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.world.Explosion;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import appeng.block.AEBaseBlock;
|
|
|
|
import appeng.client.render.BaseBlockRender;
|
|
|
|
import appeng.client.render.blocks.RenderTinyTNT;
|
|
|
|
import appeng.client.texture.FullIcon;
|
|
|
|
import appeng.core.AppEng;
|
|
|
|
import appeng.core.features.AEFeature;
|
2014-02-23 02:28:52 +01:00
|
|
|
import appeng.entity.EntityIds;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.entity.EntityTinyTNTPrimed;
|
|
|
|
import appeng.helpers.ICustomCollision;
|
2014-03-02 09:35:11 +01:00
|
|
|
import appeng.hooks.DispenserBehaviorTinyTNT;
|
2013-12-27 23:59:59 +01:00
|
|
|
import cpw.mods.fml.common.registry.EntityRegistry;
|
|
|
|
|
|
|
|
public class BlockTinyTNT extends AEBaseBlock implements ICustomCollision
|
|
|
|
{
|
|
|
|
|
|
|
|
public BlockTinyTNT() {
|
|
|
|
super( BlockTinyTNT.class, Material.tnt );
|
|
|
|
setfeature( EnumSet.of( AEFeature.TinyTNT ) );
|
|
|
|
setLightOpacity( 3 );
|
|
|
|
setBlockBounds( 0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f );
|
|
|
|
isFullSize = isOpaque = false;
|
|
|
|
|
|
|
|
EntityRegistry.registerModEntity( EntityTinyTNTPrimed.class, "EntityTinyTNTPrimed", EntityIds.TINY_TNT, AppEng.instance, 16, 4, true );
|
2014-02-16 05:40:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postInit()
|
|
|
|
{
|
|
|
|
super.postInit();
|
|
|
|
BlockDispenser.dispenseBehaviorRegistry.putObject( Item.getItemFromBlock( this ), new DispenserBehaviorTinyTNT() );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Class<? extends BaseBlockRender> getRenderer()
|
|
|
|
{
|
|
|
|
return RenderTinyTNT.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void registerBlockIcons(IIconRegister iconRegistry)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
// no images required.
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public IIcon getIcon(int direction, int metadata)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
return new FullIcon( Blocks.tnt.getIcon( direction, metadata ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEntityCollidedWithBlock(World w, int x, int y, int z, Entity entity)
|
|
|
|
{
|
|
|
|
if ( entity instanceof EntityArrow && !w.isRemote )
|
|
|
|
{
|
|
|
|
EntityArrow entityarrow = (EntityArrow) entity;
|
|
|
|
|
|
|
|
if ( entityarrow.isBurning() )
|
|
|
|
{
|
|
|
|
this.startFuse( w, x, y, z, entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase) entityarrow.shootingEntity : null );
|
|
|
|
w.setBlockToAir( x, y, z );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockAdded(World w, int x, int y, int z)
|
|
|
|
{
|
|
|
|
super.onBlockAdded( w, x, y, z );
|
|
|
|
|
|
|
|
if ( w.isBlockIndirectlyGettingPowered( x, y, z ) )
|
|
|
|
{
|
|
|
|
this.startFuse( w, x, y, z, null );
|
|
|
|
w.setBlockToAir( x, y, z );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void onNeighborBlockChange(World w, int x, int y, int z, Block id)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( w.isBlockIndirectlyGettingPowered( x, y, z ) )
|
|
|
|
{
|
|
|
|
this.startFuse( w, x, y, z, null );
|
|
|
|
w.setBlockToAir( x, y, z );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.flint_and_steel )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
this.startFuse( w, x, y, z, player );
|
|
|
|
w.setBlockToAir( x, y, z );
|
|
|
|
player.getCurrentEquippedItem().damageItem( 1, player );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return super.onActivated( w, x, y, z, player, side, hitX, hitY, hitZ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockDestroyedByExplosion(World w, int x, int y, int z, Explosion exp)
|
|
|
|
{
|
|
|
|
if ( !w.isRemote )
|
|
|
|
{
|
|
|
|
EntityTinyTNTPrimed entitytntprimed = new EntityTinyTNTPrimed( w, x + 0.5F, y + 0.5F, z + 0.5F, exp.getExplosivePlacedBy() );
|
|
|
|
entitytntprimed.fuse = w.rand.nextInt( entitytntprimed.fuse / 4 ) + entitytntprimed.fuse / 8;
|
|
|
|
w.spawnEntityInWorld( entitytntprimed );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startFuse(World w, int x, int y, int z, EntityLivingBase ignitor)
|
|
|
|
{
|
|
|
|
if ( !w.isRemote )
|
|
|
|
{
|
|
|
|
EntityTinyTNTPrimed entitytntprimed = new EntityTinyTNTPrimed( w, x + 0.5F, y + 0.5F, z + 0.5F, ignitor );
|
|
|
|
w.spawnEntityInWorld( entitytntprimed );
|
2014-02-09 19:34:27 +01:00
|
|
|
w.playSoundAtEntity( entitytntprimed, "game.tnt.primed", 1.0F, 1.0F );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDropFromExplosion(Explosion exp)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-31 18:11:50 +01:00
|
|
|
public Iterable<AxisAlignedBB> getSelectedBoundingBoxsFromPool(World w, int x, int y, int z, Entity e, boolean isVisual)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return Arrays.asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( 0.25, 0, 0.25, 0.75, 0.5, 0.75 ) } );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e)
|
|
|
|
{
|
|
|
|
out.add( AxisAlignedBB.getAABBPool().getAABB( 0.25, 0, 0.25, 0.75, 0.5, 0.75 ) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|