package common.block.tech;

import common.block.Material;
import common.entity.Entity;
import common.properties.Property;
import common.properties.PropertyInteger;
import common.util.BlockPos;
import common.util.ExtMath;
import common.world.State;
import common.world.World;

public class BlockPressurePlateWeighted extends BlockBasePressurePlate
{
    public static final PropertyInteger POWER = PropertyInteger.create("power", 0, 15);
    private final int field_150068_a;

    public BlockPressurePlateWeighted(Material p_i46380_1_, int p_i46380_2_)
    {
        super(p_i46380_1_);
        this.setDefaultState(this.getBaseState().withProperty(POWER, Integer.valueOf(0)));
        this.field_150068_a = p_i46380_2_;
    }

    protected int computeRedstoneStrength(World worldIn, BlockPos pos)
    {
        int i = Math.min(worldIn.getEntitiesWithinAABB(Entity.class, this.getSensitiveAABB(pos)).size(), this.field_150068_a);

        if (i > 0)
        {
            float f = (float)Math.min(this.field_150068_a, i) / (float)this.field_150068_a;
            return ExtMath.ceilf(f * 15.0F);
        }
        else
        {
            return 0;
        }
    }

    protected int getRedstoneStrength(State state)
    {
        return ((Integer)state.getValue(POWER)).intValue();
    }

    protected State setRedstoneStrength(State state, int strength)
    {
        return state.withProperty(POWER, Integer.valueOf(strength));
    }

    /**
     * How many world ticks before ticking
     */
    public int tickRate(World worldIn, BlockPos pos)
    {
        return 10;
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public State getStateFromMeta(int meta)
    {
        return this.getState().withProperty(POWER, Integer.valueOf(meta));
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(State state)
    {
        return ((Integer)state.getValue(POWER)).intValue();
    }

    protected Property[] getProperties()
    {
        return new Property[] {POWER};
    }
    
    public boolean isMagnetic() {
    	return this.field_150068_a == 150;
    }
    
    public String getTexture() {
    	return this.field_150068_a == 150 ? "iron_block" : "gold_block";
    }
}
