| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.properties.IProperty;
|
| 6 | import net.minecraft.block.properties.PropertyBool;
|
| 7 | import net.minecraft.block.state.BlockState;
|
| 8 | import net.minecraft.block.state.IBlockState;
|
| 9 | import net.minecraft.entity.Entity;
|
| 10 | import net.minecraft.entity.EntityLivingBase;
|
| 11 | import net.minecraft.util.AxisAlignedBB;
|
| 12 | import net.minecraft.util.BlockPos;
|
| 13 | import net.minecraft.world.World;
|
| 14 |
|
| 15 | public class BlockPressurePlate extends BlockBasePressurePlate
|
| 16 | {
|
| 17 | public static final PropertyBool POWERED = PropertyBool.create("powered");
|
| 18 | private final BlockPressurePlate.Sensitivity sensitivity;
|
| 19 |
|
| 20 | protected BlockPressurePlate(Material materialIn, BlockPressurePlate.Sensitivity sensitivityIn)
|
| 21 | {
|
| 22 | super(materialIn);
|
| 23 | this.setDefaultState(this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(false)));
|
| 24 | this.sensitivity = sensitivityIn;
|
| 25 | }
|
| 26 |
|
| 27 | protected int getRedstoneStrength(IBlockState state)
|
| 28 | {
|
| 29 | return ((Boolean)state.getValue(POWERED)).booleanValue() ? 15 : 0;
|
| 30 | }
|
| 31 |
|
| 32 | protected IBlockState setRedstoneStrength(IBlockState state, int strength)
|
| 33 | {
|
| 34 | return state.withProperty(POWERED, Boolean.valueOf(strength > 0));
|
| 35 | }
|
| 36 |
|
| 37 | protected int computeRedstoneStrength(World worldIn, BlockPos pos)
|
| 38 | {
|
| 39 | AxisAlignedBB axisalignedbb = this.getSensitiveAABB(pos);
|
| 40 | List <? extends Entity > list;
|
| 41 |
|
| 42 | switch (this.sensitivity)
|
| 43 | {
|
| 44 | case EVERYTHING:
|
| 45 | list = worldIn.getEntitiesWithinAABBExcludingEntity((Entity)null, axisalignedbb);
|
| 46 | break;
|
| 47 |
|
| 48 | case MOBS:
|
| 49 | list = worldIn.<Entity>getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
|
| 50 | break;
|
| 51 |
|
| 52 | default:
|
| 53 | return 0;
|
| 54 | }
|
| 55 |
|
| 56 | if (!list.isEmpty())
|
| 57 | {
|
| 58 | for (Entity entity : list)
|
| 59 | {
|
| 60 | if (!entity.doesEntityNotTriggerPressurePlate())
|
| 61 | {
|
| 62 | return 15;
|
| 63 | }
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | return 0;
|
| 68 | }
|
| 69 |
|
| 70 | /**
|
| 71 | * Convert the given metadata into a BlockState for this Block
|
| 72 | */
|
| 73 | public IBlockState getStateFromMeta(int meta)
|
| 74 | {
|
| 75 | return this.getDefaultState().withProperty(POWERED, Boolean.valueOf(meta == 1));
|
| 76 | }
|
| 77 |
|
| 78 | /**
|
| 79 | * Convert the BlockState into the correct metadata value
|
| 80 | */
|
| 81 | public int getMetaFromState(IBlockState state)
|
| 82 | {
|
| 83 | return ((Boolean)state.getValue(POWERED)).booleanValue() ? 1 : 0;
|
| 84 | }
|
| 85 |
|
| 86 | protected BlockState createBlockState()
|
| 87 | {
|
| 88 | return new BlockState(this, new IProperty[] {POWERED});
|
| 89 | }
|
| 90 |
|
| 91 | public static enum Sensitivity
|
| 92 | {
|
| 93 | EVERYTHING,
|
| 94 | MOBS;
|
| 95 | }
|
| 96 | }
|
| 97 |
|