BlockBasePressurePlate .java

net.minecraft.block.BlockBasePressurePlate (class, 246 lines): members: setBlockBoundsBasedOnState0, getSensitiveAABB, updateNeighbors, updateState.

net.minecraft.blockclass246 linescommonextends Block6.9 KB

API Surface (22)

void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
void setBlockBoundsBasedOnState0(IBlockState state)
int tickRate(World worldIn)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
boolean isOpaqueCube()
boolean isFullCube()
boolean isPassable(IBlockAccess worldIn, BlockPos pos)
boolean canSpawnInBlock()
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random)
void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
void updateState(World worldIn, BlockPos pos, IBlockState state, int oldRedstoneStrength)
AxisAlignedBB getSensitiveAABB(BlockPos pos)
void breakBlock(World worldIn, BlockPos pos, IBlockState state)
void updateNeighbors(World worldIn, BlockPos pos)
int getWeakPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side)
int getStrongPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side)
boolean canProvidePower()
void setBlockBoundsForItemRender()
int getMobilityFlag()

String literals (1)

"random.click"

Full Source

BlockBasePressurePlate.java246 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.state.IBlockState;
7
import net.minecraft.creativetab.CreativeTabs;
8
import net.minecraft.entity.Entity;
9
import net.minecraft.util.AxisAlignedBB;
10
import net.minecraft.util.BlockPos;
11
import net.minecraft.util.EnumFacing;
12
import net.minecraft.world.IBlockAccess;
13
import net.minecraft.world.World;
14
15
public abstract class BlockBasePressurePlate extends Block
16
{
17
    protected BlockBasePressurePlate(Material materialIn)
18
    {
19
        this(materialIn, materialIn.getMaterialMapColor());
20
    }
21
22
    protected BlockBasePressurePlate(Material p_i46401_1_, MapColor p_i46401_2_)
23
    {
24
        super(p_i46401_1_, p_i46401_2_);
25
        this.setCreativeTab(CreativeTabs.tabRedstone);
26
        this.setTickRandomly(true);
27
    }
28
29
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
30
    {
31
        this.setBlockBoundsBasedOnState0(worldIn.getBlockState(pos));
32
    }
33
34
    protected void setBlockBoundsBasedOnState0(IBlockState state)
35
    {
36
        boolean flag = this.getRedstoneStrength(state) > 0;
37
        float f = 0.0625F;
38
39
        if (flag)
40
        {
41
            this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.03125F, 0.9375F);
42
        }
43
        else
44
        {
45
            this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.0625F, 0.9375F);
46
        }
47
    }
48
49
    /**
50
     * How many world ticks before ticking
51
     */
52
    public int tickRate(World worldIn)
53
    {
54
        return 20;
55
    }
56
57
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
58
    {
59
        return null;
60
    }
61
62
    /**
63
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
64
     */
65
    public boolean isOpaqueCube()
66
    {
67
        return false;
68
    }
69
70
    public boolean isFullCube()
71
    {
72
        return false;
73
    }
74
75
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
76
    {
77
        return true;
78
    }
79
80
    /**
81
     * Return true if an entity can be spawned inside the block (used to get the player's bed spawn location)
82
     */
83
    public boolean canSpawnInBlock()
84
    {
85
        return true;
86
    }
87
88
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
89
    {
90
        return this.canBePlacedOn(worldIn, pos.down());
91
    }
92
93
    /**
94
     * Called when a neighboring block changes.
95
     */
96
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
97
    {
98
        if (!this.canBePlacedOn(worldIn, pos.down()))
99
        {
100
            this.dropBlockAsItem(worldIn, pos, state, 0);
101
            worldIn.setBlockToAir(pos);
102
        }
103
    }
104
105
    private boolean canBePlacedOn(World worldIn, BlockPos pos)
106
    {
107
        return World.doesBlockHaveSolidTopSurface(worldIn, pos) || worldIn.getBlockState(pos).getBlock() instanceof BlockFence;
108
    }
109
110
    /**
111
     * Called randomly when setTickRandomly is set to true (used by e.g. crops to grow, etc.)
112
     */
113
    public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random)
114
    {
115
    }
116
117
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
118
    {
119
        if (!worldIn.isRemote)
120
        {
121
            int i = this.getRedstoneStrength(state);
122
123
            if (i > 0)
124
            {
125
                this.updateState(worldIn, pos, state, i);
126
            }
127
        }
128
    }
129
130
    /**
131
     * Called When an Entity Collided with the Block
132
     */
133
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
134
    {
135
        if (!worldIn.isRemote)
136
        {
137
            int i = this.getRedstoneStrength(state);
138
139
            if (i == 0)
140
            {
141
                this.updateState(worldIn, pos, state, i);
142
            }
143
        }
144
    }
145
146
    /**
147
     * Updates the pressure plate when stepped on
148
     */
149
    protected void updateState(World worldIn, BlockPos pos, IBlockState state, int oldRedstoneStrength)
150
    {
151
        int i = this.computeRedstoneStrength(worldIn, pos);
152
        boolean flag = oldRedstoneStrength > 0;
153
        boolean flag1 = i > 0;
154
155
        if (oldRedstoneStrength != i)
156
        {
157
            state = this.setRedstoneStrength(state, i);
158
            worldIn.setBlockState(pos, state, 2);
159
            this.updateNeighbors(worldIn, pos);
160
            worldIn.markBlockRangeForRenderUpdate(pos, pos);
161
        }
162
163
        if (!flag1 && flag)
164
        {
165
            worldIn.playSoundEffect((double)pos.getX() + 0.5D, (double)pos.getY() + 0.1D, (double)pos.getZ() + 0.5D, "random.click", 0.3F, 0.5F);
166
        }
167
        else if (flag1 && !flag)
168
        {
169
            worldIn.playSoundEffect((double)pos.getX() + 0.5D, (double)pos.getY() + 0.1D, (double)pos.getZ() + 0.5D, "random.click", 0.3F, 0.6F);
170
        }
171
172
        if (flag1)
173
        {
174
            worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
175
        }
176
    }
177
178
    /**
179
     * Returns the cubic AABB inset by 1/8 on all sides
180
     */
181
    protected AxisAlignedBB getSensitiveAABB(BlockPos pos)
182
    {
183
        float f = 0.125F;
184
        return new AxisAlignedBB((double)((float)pos.getX() + 0.125F), (double)pos.getY(), (double)((float)pos.getZ() + 0.125F), (double)((float)(pos.getX() + 1) - 0.125F), (double)pos.getY() + 0.25D, (double)((float)(pos.getZ() + 1) - 0.125F));
185
    }
186
187
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
188
    {
189
        if (this.getRedstoneStrength(state) > 0)
190
        {
191
            this.updateNeighbors(worldIn, pos);
192
        }
193
194
        super.breakBlock(worldIn, pos, state);
195
    }
196
197
    /**
198
     * Notify block and block below of changes
199
     */
200
    protected void updateNeighbors(World worldIn, BlockPos pos)
201
    {
202
        worldIn.notifyNeighborsOfStateChange(pos, this);
203
        worldIn.notifyNeighborsOfStateChange(pos.down(), this);
204
    }
205
206
    public int getWeakPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side)
207
    {
208
        return this.getRedstoneStrength(state);
209
    }
210
211
    public int getStrongPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side)
212
    {
213
        return side == EnumFacing.UP ? this.getRedstoneStrength(state) : 0;
214
    }
215
216
    /**
217
     * Can this block provide power. Only wire currently seems to have this change based on its state.
218
     */
219
    public boolean canProvidePower()
220
    {
221
        return true;
222
    }
223
224
    /**
225
     * Sets the block's bounds for rendering it as an item
226
     */
227
    public void setBlockBoundsForItemRender()
228
    {
229
        float f = 0.5F;
230
        float f1 = 0.125F;
231
        float f2 = 0.5F;
232
        this.setBlockBounds(0.0F, 0.375F, 0.0F, 1.0F, 0.625F, 1.0F);
233
    }
234
235
    public int getMobilityFlag()
236
    {
237
        return 1;
238
    }
239
240
    protected abstract int computeRedstoneStrength(World worldIn, BlockPos pos);
241
242
    protected abstract int getRedstoneStrength(IBlockState state);
243
244
    protected abstract IBlockState setRedstoneStrength(IBlockState state, int strength);
245
}
246

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