BlockTNT .java

net.minecraft.block.BlockTNT (class): members: EXPLODE, explode, canDropFromExplosion, onBlockDestroyedByExplosion, onBlockDestroyedByPlayer, onBlockAdded.

net.minecraft.blockclass162 linescommonextends Block5.6 KB

API Surface (11)

void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn)
void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state)
void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter)
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
boolean canDropFromExplosion(Explosion explosionIn)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (1)

EXPLODE

String literals (2)

"explode"
"game.tnt.primed"

Full Source

BlockTNT.java162 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import net.minecraft.block.material.Material;
4
import net.minecraft.block.properties.IProperty;
5
import net.minecraft.block.properties.PropertyBool;
6
import net.minecraft.block.state.BlockState;
7
import net.minecraft.block.state.IBlockState;
8
import net.minecraft.creativetab.CreativeTabs;
9
import net.minecraft.entity.Entity;
10
import net.minecraft.entity.EntityLivingBase;
11
import net.minecraft.entity.item.EntityTNTPrimed;
12
import net.minecraft.entity.player.EntityPlayer;
13
import net.minecraft.entity.projectile.EntityArrow;
14
import net.minecraft.init.Items;
15
import net.minecraft.item.Item;
16
import net.minecraft.util.BlockPos;
17
import net.minecraft.util.EnumFacing;
18
import net.minecraft.world.Explosion;
19
import net.minecraft.world.World;
20
21
public class BlockTNT extends Block
22
{
23
    public static final PropertyBool EXPLODE = PropertyBool.create("explode");
24
25
    public BlockTNT()
26
    {
27
        super(Material.tnt);
28
        this.setDefaultState(this.blockState.getBaseState().withProperty(EXPLODE, Boolean.valueOf(false)));
29
        this.setCreativeTab(CreativeTabs.tabRedstone);
30
    }
31
32
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
33
    {
34
        super.onBlockAdded(worldIn, pos, state);
35
36
        if (worldIn.isBlockPowered(pos))
37
        {
38
            this.onBlockDestroyedByPlayer(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
39
            worldIn.setBlockToAir(pos);
40
        }
41
    }
42
43
    /**
44
     * Called when a neighboring block changes.
45
     */
46
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
47
    {
48
        if (worldIn.isBlockPowered(pos))
49
        {
50
            this.onBlockDestroyedByPlayer(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
51
            worldIn.setBlockToAir(pos);
52
        }
53
    }
54
55
    /**
56
     * Called when this Block is destroyed by an Explosion
57
     */
58
    public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn)
59
    {
60
        if (!worldIn.isRemote)
61
        {
62
            EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy());
63
            entitytntprimed.fuse = worldIn.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8;
64
            worldIn.spawnEntityInWorld(entitytntprimed);
65
        }
66
    }
67
68
    /**
69
     * Called when a player destroys this Block
70
     */
71
    public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state)
72
    {
73
        this.explode(worldIn, pos, state, (EntityLivingBase)null);
74
    }
75
76
    public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter)
77
    {
78
        if (!worldIn.isRemote)
79
        {
80
            if (((Boolean)state.getValue(EXPLODE)).booleanValue())
81
            {
82
                EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), igniter);
83
                worldIn.spawnEntityInWorld(entitytntprimed);
84
                worldIn.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F);
85
            }
86
        }
87
    }
88
89
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
90
    {
91
        if (playerIn.getCurrentEquippedItem() != null)
92
        {
93
            Item item = playerIn.getCurrentEquippedItem().getItem();
94
95
            if (item == Items.flint_and_steel || item == Items.fire_charge)
96
            {
97
                this.explode(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)), playerIn);
98
                worldIn.setBlockToAir(pos);
99
100
                if (item == Items.flint_and_steel)
101
                {
102
                    playerIn.getCurrentEquippedItem().damageItem(1, playerIn);
103
                }
104
                else if (!playerIn.capabilities.isCreativeMode)
105
                {
106
                    --playerIn.getCurrentEquippedItem().stackSize;
107
                }
108
109
                return true;
110
            }
111
        }
112
113
        return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);
114
    }
115
116
    /**
117
     * Called When an Entity Collided with the Block
118
     */
119
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
120
    {
121
        if (!worldIn.isRemote && entityIn instanceof EntityArrow)
122
        {
123
            EntityArrow entityarrow = (EntityArrow)entityIn;
124
125
            if (entityarrow.isBurning())
126
            {
127
                this.explode(worldIn, pos, worldIn.getBlockState(pos).withProperty(EXPLODE, Boolean.valueOf(true)), entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase)entityarrow.shootingEntity : null);
128
                worldIn.setBlockToAir(pos);
129
            }
130
        }
131
    }
132
133
    /**
134
     * Return whether this block can drop from an explosion.
135
     */
136
    public boolean canDropFromExplosion(Explosion explosionIn)
137
    {
138
        return false;
139
    }
140
141
    /**
142
     * Convert the given metadata into a BlockState for this Block
143
     */
144
    public IBlockState getStateFromMeta(int meta)
145
    {
146
        return this.getDefaultState().withProperty(EXPLODE, Boolean.valueOf((meta & 1) > 0));
147
    }
148
149
    /**
150
     * Convert the BlockState into the correct metadata value
151
     */
152
    public int getMetaFromState(IBlockState state)
153
    {
154
        return ((Boolean)state.getValue(EXPLODE)).booleanValue() ? 1 : 0;
155
    }
156
157
    protected BlockState createBlockState()
158
    {
159
        return new BlockState(this, new IProperty[] {EXPLODE});
160
    }
161
}
162

Deobfuscated MCP 1.8.9 source of BlockTNT from Marcelektro/MavenMCP-1.8.9 (net/minecraft/block/BlockTNT.java), stored verbatim.