001package net.minecraft.block;
002
003import java.util.Iterator;
004import net.minecraft.block.material.Material;
005import net.minecraft.entity.item.EntityItem;
006import net.minecraft.util.MathHelper;
007import net.minecraft.world.World;
008
009public class BlockPressurePlateWeighted extends BlockBasePressurePlate
010{
011    /** The maximum number of items the plate weights. */
012    private final int maxItemsWeighted;
013
014    protected BlockPressurePlateWeighted(int par1, String par2Str, Material par3Material, int par4)
015    {
016        super(par1, par2Str, par3Material);
017        this.maxItemsWeighted = par4;
018    }
019
020    /**
021     * Returns the current state of the pressure plate. Returns a value between 0 and 15 based on the number of items on
022     * it.
023     */
024    protected int getPlateState(World par1World, int par2, int par3, int par4)
025    {
026        int l = 0;
027        Iterator iterator = par1World.getEntitiesWithinAABB(EntityItem.class, this.getSensitiveAABB(par2, par3, par4)).iterator();
028
029        while (iterator.hasNext())
030        {
031            EntityItem entityitem = (EntityItem)iterator.next();
032            l += entityitem.getEntityItem().stackSize;
033
034            if (l >= this.maxItemsWeighted)
035            {
036                break;
037            }
038        }
039
040        if (l <= 0)
041        {
042            return 0;
043        }
044        else
045        {
046            float f = (float)Math.min(this.maxItemsWeighted, l) / (float)this.maxItemsWeighted;
047            return MathHelper.ceiling_float_int(f * 15.0F);
048        }
049    }
050
051    /**
052     * Argument is metadata. Returns power level (0-15)
053     */
054    protected int getPowerSupply(int par1)
055    {
056        return par1;
057    }
058
059    /**
060     * Argument is weight (0-15). Return the metadata to be set because of it.
061     */
062    protected int getMetaFromWeight(int par1)
063    {
064        return par1;
065    }
066
067    /**
068     * How many world ticks before ticking
069     */
070    public int tickRate(World par1World)
071    {
072        return 10;
073    }
074}