Java 类net.minecraftforge.event.entity.player.SleepingLocationCheckEvent 实例源码

项目:CustomWorldGen    文件:ForgeEventFactory.java   
public static boolean fireSleepingLocationCheck(EntityPlayer player, BlockPos sleepingLocation)
{
    SleepingLocationCheckEvent evt = new SleepingLocationCheckEvent(player, sleepingLocation);
    MinecraftForge.EVENT_BUS.post(evt);

    Result canContinueSleep = evt.getResult();
    if (canContinueSleep == Result.DEFAULT)
    {
        IBlockState state = player.worldObj.getBlockState(player.bedLocation);
        return state.getBlock().isBed(state, player.worldObj, player.bedLocation, player);
    }
    else
        return canContinueSleep == Result.ALLOW;
}
项目:Cyclic    文件:ItemSleepingMat.java   
@SubscribeEvent
public void onBedCheck(SleepingLocationCheckEvent event) {
  EntityPlayer p = event.getEntityPlayer();
  final IPlayerExtendedProperties sleep = p.getCapability(ModCyclic.CAPABILITYSTORAGE, null);
  if (sleep != null && sleep.isSleeping()) {
    if (p.isSneaking()) {
      //you want to cancel, ok
      sleep.setSleeping(false);
    }
    else {
      p.bedLocation = p.getPosition();
      event.setResult(Result.ALLOW);
    }
  }
}
项目:OpenBlocks    文件:ItemSleepingBag.java   
@SubscribeEvent
public void onBedCheck(SleepingLocationCheckEvent evt) {
    if (isWearingSleepingBag(evt.getEntityPlayer()))
        evt.setResult(Result.ALLOW);
}