BlockCommandBlock .java

net.minecraft.block.BlockCommandBlock (class): members: TRIGGERED, getComparatorInputOverride, hasComparatorInputOverride, onBlockPlacedBy, tickRate.

net.minecraft.blockclass172 linescommonextends BlockContainer5.5 KB

API Surface (14)

TileEntity createNewTileEntity(World worldIn, int meta)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
int tickRate(World worldIn)
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
boolean hasComparatorInputOverride()
int getComparatorInputOverride(World worldIn, BlockPos pos)
void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
int quantityDropped(Random random)
int getRenderType()
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)

Fields & Constants (1)

TRIGGERED

String literals (2)

"triggered"
"sendCommandFeedback"

Full Source

BlockCommandBlock.java172 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.Random;
4
import net.minecraft.block.material.MapColor;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.block.properties.IProperty;
7
import net.minecraft.block.properties.PropertyBool;
8
import net.minecraft.block.state.BlockState;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.command.server.CommandBlockLogic;
11
import net.minecraft.entity.EntityLivingBase;
12
import net.minecraft.entity.player.EntityPlayer;
13
import net.minecraft.item.ItemStack;
14
import net.minecraft.tileentity.TileEntity;
15
import net.minecraft.tileentity.TileEntityCommandBlock;
16
import net.minecraft.util.BlockPos;
17
import net.minecraft.util.EnumFacing;
18
import net.minecraft.world.World;
19
20
public class BlockCommandBlock extends BlockContainer
21
{
22
    public static final PropertyBool TRIGGERED = PropertyBool.create("triggered");
23
24
    public BlockCommandBlock()
25
    {
26
        super(Material.iron, MapColor.adobeColor);
27
        this.setDefaultState(this.blockState.getBaseState().withProperty(TRIGGERED, Boolean.valueOf(false)));
28
    }
29
30
    /**
31
     * Returns a new instance of a block's tile entity class. Called on placing the block.
32
     */
33
    public TileEntity createNewTileEntity(World worldIn, int meta)
34
    {
35
        return new TileEntityCommandBlock();
36
    }
37
38
    /**
39
     * Called when a neighboring block changes.
40
     */
41
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
42
    {
43
        if (!worldIn.isRemote)
44
        {
45
            boolean flag = worldIn.isBlockPowered(pos);
46
            boolean flag1 = ((Boolean)state.getValue(TRIGGERED)).booleanValue();
47
48
            if (flag && !flag1)
49
            {
50
                worldIn.setBlockState(pos, state.withProperty(TRIGGERED, Boolean.valueOf(true)), 4);
51
                worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
52
            }
53
            else if (!flag && flag1)
54
            {
55
                worldIn.setBlockState(pos, state.withProperty(TRIGGERED, Boolean.valueOf(false)), 4);
56
            }
57
        }
58
    }
59
60
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
61
    {
62
        TileEntity tileentity = worldIn.getTileEntity(pos);
63
64
        if (tileentity instanceof TileEntityCommandBlock)
65
        {
66
            ((TileEntityCommandBlock)tileentity).getCommandBlockLogic().trigger(worldIn);
67
            worldIn.updateComparatorOutputLevel(pos, this);
68
        }
69
    }
70
71
    /**
72
     * How many world ticks before ticking
73
     */
74
    public int tickRate(World worldIn)
75
    {
76
        return 1;
77
    }
78
79
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
80
    {
81
        TileEntity tileentity = worldIn.getTileEntity(pos);
82
        return tileentity instanceof TileEntityCommandBlock ? ((TileEntityCommandBlock)tileentity).getCommandBlockLogic().tryOpenEditCommandBlock(playerIn) : false;
83
    }
84
85
    public boolean hasComparatorInputOverride()
86
    {
87
        return true;
88
    }
89
90
    public int getComparatorInputOverride(World worldIn, BlockPos pos)
91
    {
92
        TileEntity tileentity = worldIn.getTileEntity(pos);
93
        return tileentity instanceof TileEntityCommandBlock ? ((TileEntityCommandBlock)tileentity).getCommandBlockLogic().getSuccessCount() : 0;
94
    }
95
96
    /**
97
     * Called by ItemBlocks after a block is set in the world, to allow post-place logic
98
     */
99
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
100
    {
101
        TileEntity tileentity = worldIn.getTileEntity(pos);
102
103
        if (tileentity instanceof TileEntityCommandBlock)
104
        {
105
            CommandBlockLogic commandblocklogic = ((TileEntityCommandBlock)tileentity).getCommandBlockLogic();
106
107
            if (stack.hasDisplayName())
108
            {
109
                commandblocklogic.setName(stack.getDisplayName());
110
            }
111
112
            if (!worldIn.isRemote)
113
            {
114
                commandblocklogic.setTrackOutput(worldIn.getGameRules().getBoolean("sendCommandFeedback"));
115
            }
116
        }
117
    }
118
119
    /**
120
     * Returns the quantity of items to drop on block destruction.
121
     */
122
    public int quantityDropped(Random random)
123
    {
124
        return 0;
125
    }
126
127
    /**
128
     * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
129
     */
130
    public int getRenderType()
131
    {
132
        return 3;
133
    }
134
135
    /**
136
     * Convert the given metadata into a BlockState for this Block
137
     */
138
    public IBlockState getStateFromMeta(int meta)
139
    {
140
        return this.getDefaultState().withProperty(TRIGGERED, Boolean.valueOf((meta & 1) > 0));
141
    }
142
143
    /**
144
     * Convert the BlockState into the correct metadata value
145
     */
146
    public int getMetaFromState(IBlockState state)
147
    {
148
        int i = 0;
149
150
        if (((Boolean)state.getValue(TRIGGERED)).booleanValue())
151
        {
152
            i |= 1;
153
        }
154
155
        return i;
156
    }
157
158
    protected BlockState createBlockState()
159
    {
160
        return new BlockState(this, new IProperty[] {TRIGGERED});
161
    }
162
163
    /**
164
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
165
     * IBlockstate
166
     */
167
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
168
    {
169
        return this.getDefaultState().withProperty(TRIGGERED, Boolean.valueOf(false));
170
    }
171
}
172

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