001package net.minecraft.block; 002 003import java.util.Iterator; 004import java.util.List; 005import net.minecraft.block.material.Material; 006import net.minecraft.entity.Entity; 007import net.minecraft.entity.EntityLiving; 008import net.minecraft.entity.player.EntityPlayer; 009import net.minecraft.world.World; 010 011public class BlockPressurePlate extends BlockBasePressurePlate 012{ 013 /** The mob type that can trigger this pressure plate. */ 014 private EnumMobType triggerMobType; 015 016 protected BlockPressurePlate(int par1, String par2Str, Material par3Material, EnumMobType par4EnumMobType) 017 { 018 super(par1, par2Str, par3Material); 019 this.triggerMobType = par4EnumMobType; 020 } 021 022 /** 023 * Argument is weight (0-15). Return the metadata to be set because of it. 024 */ 025 protected int getMetaFromWeight(int par1) 026 { 027 return par1 > 0 ? 1 : 0; 028 } 029 030 /** 031 * Argument is metadata. Returns power level (0-15) 032 */ 033 protected int getPowerSupply(int par1) 034 { 035 return par1 == 1 ? 15 : 0; 036 } 037 038 /** 039 * Returns the current state of the pressure plate. Returns a value between 0 and 15 based on the number of items on 040 * it. 041 */ 042 protected int getPlateState(World par1World, int par2, int par3, int par4) 043 { 044 List list = null; 045 046 if (this.triggerMobType == EnumMobType.everything) 047 { 048 list = par1World.getEntitiesWithinAABBExcludingEntity((Entity)null, this.getSensitiveAABB(par2, par3, par4)); 049 } 050 051 if (this.triggerMobType == EnumMobType.mobs) 052 { 053 list = par1World.getEntitiesWithinAABB(EntityLiving.class, this.getSensitiveAABB(par2, par3, par4)); 054 } 055 056 if (this.triggerMobType == EnumMobType.players) 057 { 058 list = par1World.getEntitiesWithinAABB(EntityPlayer.class, this.getSensitiveAABB(par2, par3, par4)); 059 } 060 061 if (!list.isEmpty()) 062 { 063 Iterator iterator = list.iterator(); 064 065 while (iterator.hasNext()) 066 { 067 Entity entity = (Entity)iterator.next(); 068 069 if (!entity.doesEntityNotTriggerPressurePlate()) 070 { 071 return 15; 072 } 073 } 074 } 075 076 return 0; 077 } 078}