| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.properties.IProperty;
|
| 5 | import net.minecraft.block.properties.PropertyBool;
|
| 6 | import net.minecraft.block.properties.PropertyInteger;
|
| 7 | import net.minecraft.block.state.BlockState;
|
| 8 | import net.minecraft.block.state.IBlockState;
|
| 9 | import net.minecraft.entity.player.EntityPlayer;
|
| 10 | import net.minecraft.init.Blocks;
|
| 11 | import net.minecraft.init.Items;
|
| 12 | import net.minecraft.item.Item;
|
| 13 | import net.minecraft.util.BlockPos;
|
| 14 | import net.minecraft.util.EnumFacing;
|
| 15 | import net.minecraft.util.EnumParticleTypes;
|
| 16 | import net.minecraft.util.StatCollector;
|
| 17 | import net.minecraft.world.IBlockAccess;
|
| 18 | import net.minecraft.world.World;
|
| 19 |
|
| 20 | public class BlockRedstoneRepeater extends BlockRedstoneDiode
|
| 21 | {
|
| 22 | public static final PropertyBool LOCKED = PropertyBool.create("locked");
|
| 23 | public static final PropertyInteger DELAY = PropertyInteger.create("delay", 1, 4);
|
| 24 |
|
| 25 | protected BlockRedstoneRepeater(boolean powered)
|
| 26 | {
|
| 27 | super(powered);
|
| 28 | this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(DELAY, Integer.valueOf(1)).withProperty(LOCKED, Boolean.valueOf(false)));
|
| 29 | }
|
| 30 |
|
| 31 | /**
|
| 32 | * Gets the localized name of this block. Used for the statistics page.
|
| 33 | */
|
| 34 | public String getLocalizedName()
|
| 35 | {
|
| 36 | return StatCollector.translateToLocal("item.diode.name");
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Get the actual Block state of this Block at the given position. This applies properties not visible in the
|
| 41 | * metadata, such as fence connections.
|
| 42 | */
|
| 43 | public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
|
| 44 | {
|
| 45 | return state.withProperty(LOCKED, Boolean.valueOf(this.isLocked(worldIn, pos, state)));
|
| 46 | }
|
| 47 |
|
| 48 | public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
|
| 49 | {
|
| 50 | if (!playerIn.capabilities.allowEdit)
|
| 51 | {
|
| 52 | return false;
|
| 53 | }
|
| 54 | else
|
| 55 | {
|
| 56 | worldIn.setBlockState(pos, state.cycleProperty(DELAY), 3);
|
| 57 | return true;
|
| 58 | }
|
| 59 | }
|
| 60 |
|
| 61 | protected int getDelay(IBlockState state)
|
| 62 | {
|
| 63 | return ((Integer)state.getValue(DELAY)).intValue() * 2;
|
| 64 | }
|
| 65 |
|
| 66 | protected IBlockState getPoweredState(IBlockState unpoweredState)
|
| 67 | {
|
| 68 | Integer integer = (Integer)unpoweredState.getValue(DELAY);
|
| 69 | Boolean obool = (Boolean)unpoweredState.getValue(LOCKED);
|
| 70 | EnumFacing enumfacing = (EnumFacing)unpoweredState.getValue(FACING);
|
| 71 | return Blocks.powered_repeater.getDefaultState().withProperty(FACING, enumfacing).withProperty(DELAY, integer).withProperty(LOCKED, obool);
|
| 72 | }
|
| 73 |
|
| 74 | protected IBlockState getUnpoweredState(IBlockState poweredState)
|
| 75 | {
|
| 76 | Integer integer = (Integer)poweredState.getValue(DELAY);
|
| 77 | Boolean obool = (Boolean)poweredState.getValue(LOCKED);
|
| 78 | EnumFacing enumfacing = (EnumFacing)poweredState.getValue(FACING);
|
| 79 | return Blocks.unpowered_repeater.getDefaultState().withProperty(FACING, enumfacing).withProperty(DELAY, integer).withProperty(LOCKED, obool);
|
| 80 | }
|
| 81 |
|
| 82 | /**
|
| 83 | * Get the Item that this Block should drop when harvested.
|
| 84 | */
|
| 85 | public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
| 86 | {
|
| 87 | return Items.repeater;
|
| 88 | }
|
| 89 |
|
| 90 | public Item getItem(World worldIn, BlockPos pos)
|
| 91 | {
|
| 92 | return Items.repeater;
|
| 93 | }
|
| 94 |
|
| 95 | public boolean isLocked(IBlockAccess worldIn, BlockPos pos, IBlockState state)
|
| 96 | {
|
| 97 | return this.getPowerOnSides(worldIn, pos, state) > 0;
|
| 98 | }
|
| 99 |
|
| 100 | protected boolean canPowerSide(Block blockIn)
|
| 101 | {
|
| 102 | return isRedstoneRepeaterBlockID(blockIn);
|
| 103 | }
|
| 104 |
|
| 105 | public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
| 106 | {
|
| 107 | if (this.isRepeaterPowered)
|
| 108 | {
|
| 109 | EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
|
| 110 | double d0 = (double)((float)pos.getX() + 0.5F) + (double)(rand.nextFloat() - 0.5F) * 0.2D;
|
| 111 | double d1 = (double)((float)pos.getY() + 0.4F) + (double)(rand.nextFloat() - 0.5F) * 0.2D;
|
| 112 | double d2 = (double)((float)pos.getZ() + 0.5F) + (double)(rand.nextFloat() - 0.5F) * 0.2D;
|
| 113 | float f = -5.0F;
|
| 114 |
|
| 115 | if (rand.nextBoolean())
|
| 116 | {
|
| 117 | f = (float)(((Integer)state.getValue(DELAY)).intValue() * 2 - 1);
|
| 118 | }
|
| 119 |
|
| 120 | f = f / 16.0F;
|
| 121 | double d3 = (double)(f * (float)enumfacing.getFrontOffsetX());
|
| 122 | double d4 = (double)(f * (float)enumfacing.getFrontOffsetZ());
|
| 123 | worldIn.spawnParticle(EnumParticleTypes.REDSTONE, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
|
| 124 | }
|
| 125 | }
|
| 126 |
|
| 127 | public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
| 128 | {
|
| 129 | super.breakBlock(worldIn, pos, state);
|
| 130 | this.notifyNeighbors(worldIn, pos, state);
|
| 131 | }
|
| 132 |
|
| 133 | /**
|
| 134 | * Convert the given metadata into a BlockState for this Block
|
| 135 | */
|
| 136 | public IBlockState getStateFromMeta(int meta)
|
| 137 | {
|
| 138 | return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)).withProperty(LOCKED, Boolean.valueOf(false)).withProperty(DELAY, Integer.valueOf(1 + (meta >> 2)));
|
| 139 | }
|
| 140 |
|
| 141 | /**
|
| 142 | * Convert the BlockState into the correct metadata value
|
| 143 | */
|
| 144 | public int getMetaFromState(IBlockState state)
|
| 145 | {
|
| 146 | int i = 0;
|
| 147 | i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
|
| 148 | i = i | ((Integer)state.getValue(DELAY)).intValue() - 1 << 2;
|
| 149 | return i;
|
| 150 | }
|
| 151 |
|
| 152 | protected BlockState createBlockState()
|
| 153 | {
|
| 154 | return new BlockState(this, new IProperty[] {FACING, DELAY, LOCKED});
|
| 155 | }
|
| 156 | }
|
| 157 |
|